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

Refactor Rust-based chain specs #592

Merged
merged 28 commits into from
Jan 18, 2024
Merged

Refactor Rust-based chain specs #592

merged 28 commits into from
Jan 18, 2024

Conversation

HCastano
Copy link
Collaborator

@HCastano HCastano commented Jan 16, 2024

This PR refactors the Rust-based chain spec code.

It removes some unused chain specs, and moves the remaining ones (dev,
integration-tests, and testnet) into their own modules. This makes it easier to make
changes to a specific chain spec without being tangled in a sea of other configuration
options and chain specs.

I've also pulled out a lot of accounts/public keys into consts (or equivalent) to make
the configurations easier to read.

One behavioral change here is that now if you run without specifying a --chain, then
it'll run a --dev chain. Before it used to run a local chain.

Follow-ups

There's a few follow-ups that I'd like to do after this is merged:

  • For the testnet genesis accounts, I'd like to use the accounts and maybe IPs that we actually
    intend to launch testnet with. This will make it so that @vitropy doesn't need to
    manually fill these fields out as part of the Ansible playbooks
    • If we can't get the IPs that's fine, we'll just keep substituting them in the
      playbook
  • I'd like to review the configurations across each network and see if we need all the
    validators/TSS servers listed, or really any other pallet configurations
  • I'd like to review the accounts used across all the networks and clearly document their
    mnemonics and purpose
    • For example, in the dev config it's unclear if we need three different accounts in the
      relayer GenesisConfig
    • There's also some random byte-based accounts floating around that I've got no clue
      what the original mnemonic is
  • Look into merging dev and integration-tests networks #596
  • Use JSON + builder pattern in chain specs #595

We don't need this anymore. Functionality has been moved into the `chain_spec` module.
Let's keep this as simple as we can. If we need to add more chain configs later let's do that, but
only if they're acutally being used.
This make `--dev` the default option if no chain is passed in. In the future we'll may want to
change this to be our mainnet.
Copy link

vercel bot commented Jan 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
entropy-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 10:37pm

Ideally I'd want this to be the same as the `dev` config, but let's leave it this way for now.
@HCastano HCastano marked this pull request as ready for review January 17, 2024 03:30
Comment on lines 197 to 200
Some([
28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198,
96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82,
]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are some of the mystery accounts I mention in the PR description. If nobody knows the mnemonic I'll just re-create these with a documented one in a follow-up PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats not a mystery account if ive understood you. This is a tuple, (account_id, keyvisibilty, Option<x25519_public_key>) where keyvisibility is a u8 representing public, private or permissioned. So //Eve's account is private and has a given x25519 public key. @JesseAbram did it like this because there was some difficulty using the KeyVisibilty type here, i don't remember exactly what it was.

This x25519 keypair was created by calling the derive_static_secret fn //Eve's private signing key. So we could maybe make that clearer by calling that fn here rather than giving it hard-coded.

Copy link
Member

Choose a reason for hiding this comment

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

ya it is sometimes wildly hard to get enums and structs to compile inside the runtime wasm and then also outside of it in the build spec

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thats not a mystery account if ive understood you. This is a tuple, (account_id, keyvisibilty, Option<x25519_public_key>) where keyvisibility is a u8 representing public, private or permissioned. So //Eve's account is private and has a given x25519 public key

Thanks for clarifying this. In the genesis config the last part of the tuple is just a [u8; 32], so it's unclear what it actually was supposed to be.

This x25519 keypair was created by calling the derive_static_secret fn //Eve's private signing key. So we could maybe make that clearer by calling that fn here rather than giving it hard-coded.

Thing is, we use two different sets of Alice, Bob, etc. accounts. Some come from Substrate's sp_keyring's Keyring, while others are accounts which we've designated as Alice, Bob, etc. and are used by the TSS. Without the mnemonic it's hard to tell which account is which. But yes, would definitely be nicer to derive it in place.

Copy link
Collaborator Author

@HCastano HCastano Jan 17, 2024

Choose a reason for hiding this comment

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

ya it is sometimes wildly hard to get enums and structs to compile inside the runtime wasm and then also outside of it in the build spec

We can improve this using typedefs, and things like this:

enum Enum {
    Foo = 1,
    Bar = 2,
    Baz = 3,
}

We don't need to use complex types which are hard to serialize, and we don't need to work with raw byte arrays.

Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

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

Nice work! this makes stuff a lot clearer.

Its a little bit hard to see what exactly has changed as names of things have changed as well as what files they are in. Is the idea that docker compose would now use development_config, and testnet-local would be for if external people wanted to make their own testnet deployment similar to ours? I'm asking because the name 'testnet-local' kind of implies it runs locally, but it can't be used in the 'local' docker compose setup as it currently is because it has 4 validators rather than 2.

Comment on lines 197 to 200
Some([
28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198,
96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82,
]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thats not a mystery account if ive understood you. This is a tuple, (account_id, keyvisibilty, Option<x25519_public_key>) where keyvisibility is a u8 representing public, private or permissioned. So //Eve's account is private and has a given x25519 public key. @JesseAbram did it like this because there was some difficulty using the KeyVisibilty type here, i don't remember exactly what it was.

This x25519 keypair was created by calling the derive_static_secret fn //Eve's private signing key. So we could maybe make that clearer by calling that fn here rather than giving it hard-coded.

node/cli/src/endowed_accounts.rs Show resolved Hide resolved
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"test" => Box::new(chain_spec::testing_config()),
"local-devnet" => Box::new(chain_spec::local_devnet_config()),
Copy link
Contributor

Choose a reason for hiding this comment

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

The docker compose setup uses local-devnet so if removing it here i guess we need to change docker-compose.yaml.

Copy link
Member

Choose a reason for hiding this comment

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

nah I think you need to add it in specifically since it uses different urls to match the docker containers, this def needs to be kept in as an option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would be nice to have this be configurable on the Docker side instead of having specific chainspecs for it. Future problem though

Copy link
Member

@JesseAbram JesseAbram left a comment

Choose a reason for hiding this comment

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

We need one more chain type for docker other than that this looks good

Comment on lines 197 to 200
Some([
28, 63, 144, 84, 78, 147, 195, 214, 190, 234, 111, 101, 117, 133, 9, 198,
96, 96, 76, 140, 152, 251, 255, 28, 167, 38, 157, 185, 192, 42, 201, 82,
]),
Copy link
Member

Choose a reason for hiding this comment

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

ya it is sometimes wildly hard to get enums and structs to compile inside the runtime wasm and then also outside of it in the build spec

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"test" => Box::new(chain_spec::testing_config()),
"local-devnet" => Box::new(chain_spec::local_devnet_config()),
Copy link
Member

Choose a reason for hiding this comment

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

nah I think you need to add it in specifically since it uses different urls to match the docker containers, this def needs to be kept in as an option

node/cli/src/chain_spec.rs Show resolved Hide resolved
This is meant to be compatible with the hostname scheme expected by the local `docker-compose`
setup.
@HCastano
Copy link
Collaborator Author

Its a little bit hard to see what exactly has changed as names of things have changed as well as what files they are in.

Yeah sorry. The best way to review is to open this up locally and look around the new chain_spec folder. The structure will be more clear that way.

Is the idea that docker compose would now use development_config, and testnet-local would be for if external people wanted to make their own testnet deployment similar to ours? I'm asking because the name 'testnet-local' kind of implies it runs locally, but it can't be used in the 'local' docker compose setup as it currently is because it has 4 validators rather than 2.

So tbh I forgot about the Docker config. Good catch on that!

Your comment got me thinking and I'm gonna say that the convention is that a *-local chain should be compatible with our Docker Compose setup. I've updated both the devnet and testnet configs to support this.

The testnet-local config only has two validators, Alice and Bob, not four. The testnet config does have four validators however.

node/cli/src/command.rs Show resolved Hide resolved
@HCastano HCastano merged commit 9181513 into master Jan 18, 2024
10 checks passed
@HCastano HCastano deleted the hc/clean-up-chainspec branch January 18, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants