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

Example: How to connect to parachain #1043

Merged
merged 36 commits into from
Jul 21, 2023

Conversation

tadeohepperle
Copy link
Contributor

The example shows how someone might construct the subxt::Config and the metadata module for a certain parachain if they develop an application with subxt.

The example is using the Statemint (Polkadot Asset Hub) parachain as an example.

@tadeohepperle tadeohepperle requested a review from a team as a code owner June 30, 2023 08:03
@tadeohepperle tadeohepperle self-assigned this Jun 30, 2023
@tadeohepperle tadeohepperle force-pushed the tadeo-hepperle-connect-to-parachain-example branch from 14f990e to 4a632f1 Compare July 6, 2023 10:49
//! as the polkadot.js link to the parachain (e.g. "collator01") in the zombienet output. Here `41955` refers to the port,
//! which we will need shortly.
//!
//! In this example we use the _uniques_ pallet of the polakdot asset hub parachain.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//! In this example we use the _uniques_ pallet of the polakdot asset hub parachain.
//! In this example we use the _uniques_ pallet of the polkadot asset hub parachain.

//!
//! We use [zombienet](https://github.com/paritytech/zombienet) to start up a local asset hub.
//!
//! ## 1. Install necessary tools
Copy link
Member

Choose a reason for hiding this comment

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

It would useful if you add bash script/docker image that installs everything and runs it.

It's super complicated to run this :P

//! Polkadot / Kusama / Rococo have different epoch times of `24h` / `2h` / `2min` respectively.
//! The parachain is only registered after the first epoch. So we need to wait 2 minutes, until the parachain becomes interactive and produces blocks.
//!
//!
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//!

//!
//! # Running the example
//!
//! After you have the network running, you should see something like [https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:41955#/explorer]
Copy link
Member

Choose a reason for hiding this comment

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

can't we instruct zoombienet to use a specific port to avoid more configurations to run this example?

[relaychain]
default_image = "docker.io/parity/polkadot:latest"
default_command = "polkadot"
default_args = [ "-lparachain=debug" ]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
default_args = [ "-lparachain=debug" ]
default_args = ["-lparachain=debug"]

// Third Config (using the Substrate and Polkadot Config)
////////////////////////////////////////////////////////////

pub enum StatemintConfig3 {}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see why you need to duplicate this config, it would be better to just to call this PolkadotConfig via type alias or something.

This example contains already plenty of 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.

Just because the ExtrinsicParams are from Substrate instead of from Polkadot here. So it would be inaccurate to take just the PolkadotConfig.

// Second Config (just using subxt types)
////////////////////////////////////////////////////////////

pub enum StatemintConfig2 {}
Copy link
Member

Choose a reason for hiding this comment

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

maybe you could rename this to StatemintConfigAssetTip

// First Config (verbose and detailed)
////////////////////////////////////////////////////////////

pub enum StatemintConfig {}
Copy link
Member

Choose a reason for hiding this comment

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

maybe you could rename this to StatemintConfigChargeAssetTxPayment

//! - Address: [sp_runtime::MultiAddress<Self::AccountId, ()>](sp_runtime::MultiAddress)
//! - Signature: [sp_runtime::MultiSignature]
//!
//! #### ExtrinsicParams
Copy link
Member

Choose a reason for hiding this comment

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

This is really great information but I think it's a bit too much for my taste in such example.

Like, we could say "subxt exposes a Config trait that mimics the frame_system::Config and how to construct extrinsic for a given runtime (ExtrinsicParams).

Such as if your parachain runtime has different SignedExtra then the default runtime in Substrate/Polkadot then you need provide a custom type for ExtrinsicParams in order to construct valid extrinsics.

The same applies to all associated types in the trait subxt::Config

Ideally, subxt could parse these types from the metadata/wasm blob that could be extracted when subxt connects to the node but that doesn't work currently and you have provide this yourself.

For more information regarding the SignedExtra see documentation at some link ^^

@jsdw jsdw force-pushed the tadeo-hepperle-connect-to-parachain-example branch from 2038884 to a9901a5 Compare July 18, 2023 17:14
Copy link
Contributor Author

@tadeohepperle tadeohepperle left a comment

Choose a reason for hiding this comment

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

The restructuring looks good to me, I like how you broken down the type replacements into different sections and the example is now more slim.

@jsdw
Copy link
Collaborator

jsdw commented Jul 19, 2023

Ah one mo; hit a compilation error with the example; need to add CI or something and fix it

@jsdw jsdw requested a review from a team as a code owner July 19, 2023 16:49
@@ -109,7 +109,7 @@ jobs:
# Check WASM examples, which aren't a part of the workspace and so are otherwise missed:
- name: Cargo check WASM examples
run: |
cargo check --manifest-path examples/wasm-example/Cargo.toml
cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I think this should already be the case since target: wasm32-unknown-unknown means that it's the only target that will be installed, but nothing wrong with having some extra reassurance (I've done similar!)

@tadeohepperle tadeohepperle merged commit 8b23b2b into master Jul 21, 2023
8 checks passed
@tadeohepperle tadeohepperle deleted the tadeo-hepperle-connect-to-parachain-example branch July 21, 2023 11:55
@jsdw jsdw mentioned this pull request Jul 24, 2023
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.

4 participants