Skip to content

Commit

Permalink
Misc PoS cleanup and improvements (#1207)
Browse files Browse the repository at this point in the history
* Add grandpa RPCs

* Enable warp sync

* Add BadBlocks to chain spec extensions

* Add PoS devnet chainspec

* Remove commented out line

* Appease version check

* Add grandpa RPC sanity integration test

* Auto-update creditcoin-js type definitions

* Make grandpa test a little bit more substantive

* Appease clippy

---------

Co-authored-by: gluwa-bot <[email protected]>
  • Loading branch information
2 people authored and atodorov committed Aug 15, 2023
1 parent 61f98b9 commit bb10ec2
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 53 deletions.
48 changes: 35 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
resolver = "2"

[workspace.package]
version = '2.225.0'
version = '2.225.1'
authors = ['Gluwa Inc.', 'Nathan Whitaker <[email protected]>']
edition = '2021'
license = 'Unlicense'
Expand Down Expand Up @@ -133,6 +133,7 @@ sp-keyring = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://gith
sc-consensus-babe = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git" }
sp-consensus-babe = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git", default-features = false }
sc-consensus-grandpa = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git" }
sc-consensus-grandpa-rpc = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git" }
sp-consensus-grandpa = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git", default-features = false }
pallet-babe = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git", default-features = false }
pallet-grandpa = { branch = "pos-keep-history-polkadot-v0.9.41", git = "https://github.com/gluwa/substrate.git", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions chainspecs/devSpec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"5HHSXsD5zaMb9o4H7JzxUiAYpjArE4CANKbUBiFRVEwn6WPF"
],
"codeSubstitutes": {},
"badBlocks": null,
"genesis": {
"raw": {
"top": {
Expand Down
1 change: 1 addition & 0 deletions chainspecs/mainnetSpec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"consensusEngine": null,
"grandpaInitialAuthorities": [],
"codeSubstitutes": {},
"badBlocks": null,
"genesis": {
"raw": {
"top": {
Expand Down
126 changes: 126 additions & 0 deletions chainspecs/posDevSpec.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions chainspecs/posSwitchSpec.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"grandpaInitialAuthorities": [],
"codeSubstitutes": {},
"badBlocks": null,
"genesis": {
"raw": {
"top": {
Expand Down
1 change: 1 addition & 0 deletions chainspecs/posTestnetSpec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
],
"codeSubstitutes": {},
"badBlocks": null,
"genesis": {
"raw": {
"top": {
Expand Down
1 change: 1 addition & 0 deletions chainspecs/testnetSpec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"consensusEngine": null,
"grandpaInitialAuthorities": [],
"codeSubstitutes": {},
"badBlocks": null,
"genesis": {
"raw": {
"top": {
Expand Down
2 changes: 1 addition & 1 deletion creditcoin-js/creditcoin.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions integration-tests/src/test/rpc/grandpa.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 Gluwa, Inc. & contributors
// SPDX-License-Identifier: The Unlicense

import { ApiPromise, WsProvider } from 'creditcoin-js';

describe('Grandpa RPC sanity test', (): void => {
let api: ApiPromise;

beforeEach(async () => {
const provider = new WsProvider((global as any).CREDITCOIN_API_URL);

api = await ApiPromise.create({ provider });
});

afterEach(async () => {
await api.disconnect();
});

it('rpc.grandpa.roundState() works', async (): Promise<void> => {
const result = await api.rpc.grandpa.roundState();
expect(result.best.round.toNumber()).toBeGreaterThanOrEqual(0);
});
});
2 changes: 2 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ sc-network = { workspace = true }
sc-consensus-slots = { workspace = true }
sp-consensus-grandpa = { workspace = true }
sc-consensus-grandpa = { workspace = true }
sc-consensus-grandpa-rpc = { workspace = true }
sc-rpc = { workspace = true }
sp-session = { workspace = true }
sc-network-sync = { workspace = true }
serde = { workspace = true }
Expand Down
28 changes: 11 additions & 17 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ use sp_runtime::{
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, GrandpaInitialAuthorities>;
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;

#[derive(Clone, Debug, Deserialize, Serialize, ChainSpecExtension)]
#[serde(rename_all = "camelCase")]
pub struct GrandpaInitialAuthorities {
pub struct Extensions {
/// Known bad block hashes.
pub bad_blocks: sc_client_api::BadBlocks<creditcoin_node_runtime::Block>,
/// The public keys for the authorities of the initial round of GRANDPA.
pub grandpa_initial_authorities: Option<Vec<GrandpaId>>,
}

Expand Down Expand Up @@ -80,10 +83,11 @@ pub fn development_config() -> Result<ChainSpec, String> {

let initial_authorities = vec![get_authority_keys_from_seed("Alice")];

let grandpa_initial_authorities = GrandpaInitialAuthorities {
let extensions = Extensions {
grandpa_initial_authorities: Some(
initial_authorities.clone().into_iter().map(|x| x.2).collect(),
),
bad_blocks: None,
};

Ok(ChainSpec::from_genesis(
Expand Down Expand Up @@ -121,18 +125,19 @@ pub fn development_config() -> Result<ChainSpec, String> {
// Properties
Some(chain_properties()),
// Extensions
grandpa_initial_authorities,
extensions,
))
}

pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
let initial_authorities = vec![get_authority_keys_from_seed("Alice")];

let grandpa_initial_authorities = GrandpaInitialAuthorities {
let extensions = Extensions {
grandpa_initial_authorities: Some(
initial_authorities.clone().into_iter().map(|x| x.2).collect(),
),
bad_blocks: None,
};

Ok(ChainSpec::from_genesis(
Expand Down Expand Up @@ -178,7 +183,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
// Properties
Some(chain_properties()),
// Extensions
grandpa_initial_authorities,
extensions,
))
}

Expand Down Expand Up @@ -246,7 +251,6 @@ fn testnet_genesis(
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
force_era: pallet_staking_substrate::Forcing::NotForcing,
slash_reward_fraction: Perbill::from_percent(10),
// min_validator_bond: 1000 * CTC,
..Default::default()
},
session: SessionConfig {
Expand All @@ -262,13 +266,3 @@ fn testnet_genesis(
nomination_pools: Default::default(),
}
}

// #[test]
// fn encode_keys_hack() {
// use parity_scale_codec::Encode;
// let keys = vec![get_authority_keys_from_seed("Alice")];

// let encoded = keys.encode();

// panic!("Encoded: {:?}", encoded);
// }
Loading

0 comments on commit bb10ec2

Please sign in to comment.