Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: improve smoldot integration #374

Merged
merged 9 commits into from
Nov 11, 2022
Merged

feat: improve smoldot integration #374

merged 9 commits into from
Nov 11, 2022

Conversation

kratico
Copy link
Contributor

@kratico kratico commented Nov 9, 2022

Resolves #376

Description

Improve Smoldot integration for relay chains by

  • capturing Smoldot errors
  • mapping specific .send requests to specific .send calls

Smoldot parachain integration will be tacked in an upcoming PR

Comment on lines +12 to +9
sanitizeOps: false,
sanitizeResources: false,
Copy link
Contributor Author

@kratico kratico Nov 9, 2022

Choose a reason for hiding this comment

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

Smoldot seems to not clear a few timers started in

at start_timer (https://deno.land/x/[email protected]/instance/bindings-smoldot-light.js:107:17)

@kratico kratico force-pushed the feat/smoldot-integration branch 2 times, most recently from f43a9b4 to 2b14816 Compare November 10, 2022 13:49
rpc/client.ts Outdated
Comment on lines 42 to 48
const pendingCall = this.pendingCalls[egressMessageId];
if (!pendingCall) {
console.log({ e });
// TODO: pipe error to listeners and message the likely cause,
// a duplicate client.
throw new Error();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this check can be removed.
It happens when the provider is being discarded and an inflight/pending response is emitted.
In that scenario, I assume that we don't care about the response so we can ignore it.

Thoughts @harrysolovay?

Copy link
Contributor

Choose a reason for hiding this comment

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

Which lines specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (!pendingCall) {
        console.log({ e });
        // TODO: pipe error to listeners and message the likely cause,
        //       a duplicate client.
        throw new Error();
      }

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Removing sounds good.

@kratico kratico marked this pull request as ready for review November 10, 2022 16:22
rpc/provider/errors.ts Outdated Show resolved Hide resolved
try {
conn = await connection(chainSpec, listener);
} catch (error) {
listener(new ProviderHandlerError(error as SmoldotHandlerErrorData));
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome solution!

rpc/client.ts Outdated
Comment on lines 42 to 48
const pendingCall = this.pendingCalls[egressMessageId];
if (!pendingCall) {
console.log({ e });
// TODO: pipe error to listeners and message the likely cause,
// a duplicate client.
throw new Error();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Which lines specifically?

rpc/client.ts Outdated Show resolved Hide resolved
| CrashError
| JsonRpcDisabledError
| AddChainError;
type SmoldotCloseErrorData = AlreadyDestroyedError | CrashError;
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome

rpc/provider/smoldot.ts Outdated Show resolved Hide resolved
@@ -67,27 +92,24 @@ async function connection(
}
let conn = connections.get(chainSpec);
if (!conn) {
// TODO: try catch this and send through handler within a `ProviderHandlerError`
const inner = await client.addChain({ chainSpec });
Copy link
Contributor

@wirednkod wirednkod Nov 10, 2022

Choose a reason for hiding this comment

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

for parachain support, all you need to do is to pass in the potentialRelayChains all the chains inner that you collect during the addChain.
Meaning something like:

Suggested change
const inner = await client.addChain({ chainSpec });
const innerMap: Chain[] = [];
connections.forEach((value: SmoldotProviderConnection) => {
innerMap.push(value.inner);
});
const inner = await client.addChain({ chainSpec, potentialRelayChains: innerMap });

As described yesterday, smoldot will understand which parachain should go to which chain etc etc.

EDIT: Tested the solution and It works - This is the testing code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx @wirednkod
The parachain support will be done in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@harrysolovay we need to decide 2 things

  • 1st when connecting to a parachain, I believe that we need to pass the parachain spec and the potential relay chain spec
  • 2nd smoldot connection clean up, given that it takes time to sync the light client, connecting/disconnecting to the same chain will make it slow, so perhaps we can keep the synced state without closing the connections

Thouths?

Copy link
Contributor

Choose a reason for hiding this comment

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

thx @wirednkod The parachain support will be done in a separate PR

#378

Comment on lines 94 to 111
let inner: Chain;
if (typeof chainSpec === "string") {
inner = await client.addChain({ chainSpec });
} else {
const [parachainSpec, relayChainSpec] = chainSpec;
const relayChainConnection = await client.addChain({ chainSpec: relayChainSpec });
inner = await client.addChain({
chainSpec: parachainSpec,
potentialRelayChains: [relayChainConnection],
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks fantastic!

Copy link
Contributor

Choose a reason for hiding this comment

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

Giving my 2 cents here, I think this will strict the user always to start relay chain and parachain at the same spot of the application... IMO these steps should be separated (add relay chain, add parachain) with the same function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the input @wirednkod
For now, the relay/parachain start will be on demand on the first .send invocation.

rpc/provider/smoldot.ts Outdated Show resolved Hide resolved
@kratico kratico force-pushed the feat/smoldot-integration branch from b527680 to e262b4f Compare November 11, 2022 16:30
@kratico kratico merged commit cc121e3 into main Nov 11, 2022
@kratico kratico deleted the feat/smoldot-integration branch November 11, 2022 17:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smoldot Integration
3 participants