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

Update authorize-specific-nodes.md #2151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ To add the `node-authorization` pallet to the Substrate runtime:

```toml
[dependencies]
pallet-node-authorization = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
pallet-node-authorization = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
```

This line imports the `pallet-node-authorization` crate as a dependency and specifies the following configuration details for the crate:
Expand All @@ -143,7 +143,7 @@ To add the `node-authorization` pallet to the Substrate runtime:

Note that you should use the same branch and version information for all pallets to ensure that they are compatible with each other.
Using pallets from different branches can result in compiler errors.
This example illustrates adding pallets to the `Cargo.toml` file if the other pallets use `branch = "polkadot-v1.0.0"`.
This example illustrates adding pallets to the `Cargo.toml` file if the other pallets use `branch = "polkadot-v1.9.0"`.

2. Add the `pallet-node-authorization/std` features to the list of `features` to enable when compiling the runtime.

Expand Down Expand Up @@ -222,20 +222,14 @@ To implement the `node-authorization` pallet in your runtime:
}
```

1. Add the pallet to the `construct_runtime` macro with the following line of code:
1. Add the pallet to the construct_runtime macro with the following line of code:

```rust
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
/*** Add This Line ***/
NodeAuthorization: pallet_node_authorization::{Pallet, Call, Storage, Event<T>, Config<T>},
}
);
```
```rust
/*** Add This Line ***/
#[runtime::pallet_index(8)] //adjust pallet_index according to your code,
pub type NodeAuthorization = pallet_node_authorization;

```

1. Save your changes and close the file.

Expand Down Expand Up @@ -279,31 +273,64 @@ To configure genesis storage for authorized nodes:

```rust
/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> GenesisConfig {
fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> serde_json::Value {

```

1. Within the `GenesisConfig` declaration, add the following code block:
1. Within the `GenesisConfig` declaration, update using the following example code block:

```rust
node_authorization: NodeAuthorizationConfig {
nodes: vec![
(
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
endowed_accounts[0].clone()
),
(
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
endowed_accounts[1].clone()
),
],
},
fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> serde_json::Value {
use serde_json::json;

//trying new suggestion
let node_authorization_config = NodeAuthorizationConfig {
nodes: vec![
(
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
endowed_accounts[0].clone(),
),
(
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
endowed_accounts[1].clone(),
),
],
};

// Serialize NodeAuthorizationConfig into JSON
let node_authorization_json = serde_json::to_value(&node_authorization_config).unwrap();

// Construct the overall genesis configuration JSON
let genesis_config = json!({
"balances": {
// Configure endowed accounts with initial balance of 1 << 60.
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
},
"aura": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
},
"grandpa": {
"authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
},
"sudo": {
// Assign network admin rights.
"key": Some(root_key),
},
"nodeAuthorization": node_authorization_json,
});

genesis_config
}
```

In this code, `NodeAuthorizationConfig` contains a `nodes` property, which is a vector with a tuple of two elements.
Expand Down