Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiHandler / ChainData refactoring #2951

Merged
merged 4 commits into from
May 30, 2024
Merged

Conversation

mutantcornholio
Copy link
Contributor

@mutantcornholio mutantcornholio commented May 28, 2024

Removed a lot of retry/reconnect logic from ApiHandler and ChainData, as it was spawning a lot of PJS instances, which also handling reconnects on its own.
This change also properly adpots the idea of talking both to relay chain and to parachains, depending on queried data.

With new logic, each ApiHandler instance governs an interface to a single chain, where it can switch endpoints and do reconnects on its own.
ApiHandler.getApi() returns a PJS instance that should work, and will block in case we're reconnecting.

PeopleApi endpoints now live in configs, instead of being hardcoded.

Instead of passing around ApiHandlers, passing a ChainData instance now, as it contains both ApiHandlers instance now, and as it is an intended abstraction for it

Fixes https://github.com/w3f/1k-validators-be-PRIVATE/issues/14

@mutantcornholio mutantcornholio marked this pull request as draft May 28, 2024 08:37
@mutantcornholio mutantcornholio force-pushed the yuri/websocket-disconnect branch 2 times, most recently from 761966e to bc312a9 Compare May 28, 2024 08:51
@mutantcornholio mutantcornholio marked this pull request as ready for review May 28, 2024 08:59
packages/common/src/chaindata/chaindata.ts Outdated Show resolved Hide resolved

const chainType = await chaindata?.api?.rpc.system.chain();
const chainType = await api.rpc.system.chain();
if (!chainType) {
return null;
}
const denom =
chainType.toString() == "Polkadot" ? 10000000000 : 1000000000000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be fetched dynamically from the api ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api.registry.getChainProperties() should return tokenDecimals, where denom = 10 ** tokenDecimals

@@ -200,8 +197,9 @@ export default class Nominator extends EventEmitter {

public async stash(): Promise<string> {
try {
const api = this.handler.getApi();
const ledger = await api?.query.staking.ledger(this.bondedAddress);
// TODO: chain interaction should be performed exclusively in ChainData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this series of TODOs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to tackle it separately: https://github.com/w3f/1k-validators-be-PRIVATE/issues/85

This changeset has already gotten too big

Removed a lot of retry/reconnect logic from ApiHandler and ChainData, as
it was spawning a lot of PJS instances, which also handling reconnects
on its own.
This change also properly adpots the idea of talking both to relay chain
and to parachains, depending on queried data.

With new logic, each ApiHandler instance governs an interface to a
single chain, where it can switch endpoints and do reconnects on its
own.
`ApiHandler.getApi()` returns a PJS instance that should work, and will
block in case we're reconnecting.

PeopleApi endpoints now live in configs, instead of being hardcoded.

Instead of passing around ApiHandlers, passing a ChainData instance now, as
it contains both ApiHandlers instance now, and as it is an intended
abstraction for it
@mutantcornholio mutantcornholio merged commit db066cf into staging May 30, 2024
16 checks passed
@mutantcornholio mutantcornholio deleted the yuri/websocket-disconnect branch May 30, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants