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

feat: upgrade to substrate-connect v0.8.4 #5776

Merged
merged 5 commits into from
Jan 26, 2024

Conversation

kratico
Copy link
Contributor

@kratico kratico commented Jan 2, 2024

Upgrade @substrate/connect to v0.8.4 and use the new addChain API.

The addChain API uses the relay chain to instantiate new parachains, for example

const client = createScClient()
const relayChain = await client.addWellKnownChain(input, onMessageForRelay)
const parachain = await relayChain.addChain(input, onMessageForParachain)

Given that the ScProvider is injected a relay chain provider, no changes are needed in the ScProvider public API and it works as before, for example

import { ApiPromise } from "@polkadot/api";
import { ScProvider } from "@polkadot/rpc-provider";
import * as Sc from "@substrate/connect";

import jsonParachainSpec from './myParaChainSpec.json';

const parachainSpec = JSON.stringify(jsonParachainSpec);
const relayProvider = new ScProvider(Sc, Sc.WellKnownChain.westend2);
const provider = new ScProvider(Sc, parachainSpec, relayProvider);

await provider.connect();

// ...

Note: given that ScProvider receives createScClient from @substrate/connect as input to the constructor and that the @substrate/connect API has a breaking change, this is also a breaking change for @polkadot/rpc-provider.

Comment on lines 157 to 161
const addChain = this.#sharedSandbox
? (async (...args) => (await this.#sharedSandbox!.#chain)!.addChain(...args)) as ScType.AddChain
: this.#wellKnownChains.has(this.#spec as ScType.WellKnownChain)
? client.addWellKnownChain
: client.addChain;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The this.#sharedSandbox!.#chain is not transpiled properly see
image

I think this is related to this polkadot-js/dev script
https://github.com/polkadot-js/dev/blob/1d7db82109f666dd013d5db04ef2bd6a45f4d74a/packages/dev/scripts/polkadot-dev-build-ts.mjs#L74-L84

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 Author

Choose a reason for hiding this comment

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

as an alternative that is coupled to a polkadot-dev-build-ts.mjs implementation detail, this can be re-written to

    const addChain = this.#sharedSandbox
      ? (async (...args) => {
          const source = this.#sharedSandbox!;
          return (await source.#chain)!.addChain(...args);
        }) as ScType.AddChain
      : this.#wellKnownChains.has(this.#spec as ScType.WellKnownChain)
        ? client.addWellKnownChain
        : client.addChain;

and it will transpile to

        const addChain = this.__internal__sharedSandbox
            ? (async (...args) => {
                const source = this.__internal__sharedSandbox;
                return (await source.__internal__chain).addChain(...args);
            })
            : this.__internal__wellKnownChains.has(this.__internal__spec)
                ? client.addWellKnownChain
                : client.addChain;

Copy link
Member

Choose a reason for hiding this comment

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

So the dev script implementation can actually be dropped (after we dropped Node 16 last year). The issue is that TSC compiled everything #<id> to WeakMaps for Node 16 compat and it had severe implications for performance. So at best it is/was a horrible workaround.

So the adjustment will be dropped sometime, but no idea when that sometime will be - needs some checks all over when done.

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 for the info @jacogr

I'll re-write it as suggested previously so it's more friendly with this script

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re-written in 7df6a77

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

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

Some small CI linting issues - should not be a massive issue to resolve.

const addChain = this.#sharedSandbox
? (async (...args) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const source = this.#sharedSandbox!;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

eslint-disable because it's checked on line 157

@kratico kratico requested a review from jacogr January 16, 2024 11:28
jacogr
jacogr previously requested changes Jan 26, 2024
Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

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

Seems spot-on. Please just merge master to resolve the yarn.lock conflicts.

@josepot josepot requested a review from jacogr January 26, 2024 11:45
@josepot josepot dismissed jacogr’s stale review January 26, 2024 14:10

The conflicts with the yarn.lock file have been addressed.

@josepot josepot self-requested a review January 26, 2024 14:10
Copy link
Member

@josepot josepot left a comment

Choose a reason for hiding this comment

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

Thanks @kratico ! I will try to find out how to create a release.

@josepot josepot merged commit bc3f066 into polkadot-js:master Jan 26, 2024
4 checks passed
@kratico kratico deleted the feat/substrate-connect-v0.8.4 branch January 26, 2024 14:20
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jan 28, 2024
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.

4 participants