Skip to content

Conversation

@mnaamani
Copy link
Member

@mnaamani mnaamani commented Aug 26, 2020

Update chain-spec-builder to import initial members, forum and versioned store at genesis.
Uses exported state produced by scripts in Joystream/joystream-api-examples#12

The path to the exported state as .json files can be passed as arguments to the chainspec builder:

To test (after cargo build --release)

./target/release/chain-spec-builder new \
   --authority-seeds Alice \
   --sudo-account 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
   --endowed-accounts 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
   --initial-members-path members.json \
   --initial-forum-path forum.json \
   --initial-content-path content.json

This will produce a chain-spec.json file. To run a chain with this configuration:

./target/release/joystream-node --chain chain-spec.json --alice --validator

@mnaamani mnaamani marked this pull request as ready for review August 31, 2020 06:31
wasm-bindgen = { version = "0.2.57", optional = true }
wasm-bindgen-futures = { version = "0.4.7", optional = true }
browser-utils = { package = 'substrate-browser-utils', git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4', optional = true}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind moving these dependencies to the 'third-party' category?

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 6e3ebf6

hex::decode(&self.class[2..].as_bytes()).expect("failed to parse class hex string");
let encoded_permissions = hex::decode(&self.permissions[2..].as_bytes())
.expect("failed to parse class permissions hex string");
ClassAndPermissions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to panic during the initialization? Should we fail on the first error?

Copy link
Member Author

@mnaamani mnaamani Sep 3, 2020

Choose a reason for hiding this comment

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

Yes I prefer to panic rather than introduce inconsistent state at genesis. Remember this code will only be running at the genesis construction time before any network is launched. So it would NOT affect the runtime if that is your concern?

Should we fail on the first error?

As there are references from some classes to other classes, yes there is no point continuing to import other classes since they will depend on earlier classes in some cases. So its an all or nothing scenario we want at import time.

self
}
pub fn members(mut self, members: Vec<T::AccountId>) -> Self {
pub fn members(mut self, members: Vec<(T::MemberId, T::AccountId)>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

The public method needs a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 14abbc4

Some(member.handle.clone().into_bytes()),
Some(member.avatar_uri.clone().into_bytes()),
Some(member.about.clone().into_bytes())
).expect("Importing Member Failed");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid panicking in the runtime code. Last time we changed panicking to the printing error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

This code in the build(|config: &GenesisConfig<T>| { }) block isn't runtime code. It is only native code that runs when building the genesis chain-spec. So it is safe to panic.

edition = '2018'

[dependencies]
serde = { version = "1.0.101", features = ["derive"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this line 'serde', to the std feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in a498fef

let user_info = Self::check_user_registration_info(handle, avatar_uri, about)?;

// ensure handle is not already registered
Self::ensure_unique_handle(&user_info.handle)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this check after copying inside the insert_member?

Copy link
Member Author

Choose a reason for hiding this comment

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

quite right, I forgot to remove it after adding the check in insert_member

Copy link
Member Author

Choose a reason for hiding this comment

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

will also move the slashing to come after insert_member

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 2957b71

let user_info = Self::check_user_registration_info(handle, avatar_uri, about)?;

// ensure handle is not already registered
Self::ensure_unique_handle(&user_info.handle)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this check after copying inside the insert_member?

Copy link
Member Author

Choose a reason for hiding this comment

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

quite right, I forgot to remove it after adding the check in insert_member

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 2957b71

@@ -0,0 +1,11 @@
use node_runtime::{membership, AccountId, Moment};
use std::{fs, path::Path};

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the comments for the public methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 3a01b78

@@ -0,0 +1,145 @@
use codec::Decode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the comments for the public methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 3a01b78

@@ -0,0 +1,375 @@
use codec::Decode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the comments for the public methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 3a01b78

Copy link
Contributor

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

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

LGTM

@shamil-gadelshin shamil-gadelshin merged commit 65cf1e1 into Joystream:iznik Sep 3, 2020
@mnaamani mnaamani deleted the chainspec-import-members-forum-versioned-store branch September 4, 2020 12:42
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