Skip to content

Commit

Permalink
Hotfix for Kusama (paritytech#724)
Browse files Browse the repository at this point in the history
* cli: revert borked kusama chain on startup

* Docs.

* cli: fix reversal of bork kusama fork

* cli: force always can author

* Version bump

* service: support setting fork blocks in config

* service: add support for bad blocks extension

* service: add badBlocks to kusama chainspec

* Bump Substrate to hotfix version.

* service: add bad block to kusama chain spec

* cleanup kusama hotfix

* add kusama grandpa hotfix

* Bump substrate

* Bump spec_version

* Rebump

* cli: remove unnecessary dependencies

* service: revert can_author_with fix

* service: remove unnecessary method

* Don't try to track polkadot runtime verion yet

* Versions

* service: better grandpa fix detection

Co-authored-by: André Silva <andre.beat@gmail.com>
  • Loading branch information
gavofyork and andresilva committed Jan 6, 2020
1 parent eac2ae7 commit f1d0678
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 159 deletions.
269 changes: 127 additions & 142 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ where
service::new_light::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
exit.into_exit(),
),
_ => run_until_exit(
runtime,
service::new_full::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
exit.into_exit(),
),
_ => {
service::kusama_chain_hotfix::<R, D>(&config);

run_until_exit(
runtime,
service::new_full::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
exit.into_exit(),
)
},
}.map_err(|e| format!("{:?}", e))
}),
cli::ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(&load_spec),
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-runtime-common"
version = "0.7.10"
version = "0.7.11"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

Expand Down Expand Up @@ -41,7 +41,7 @@ babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate
randomness-collective-flip = { package = "pallet-randomness-collective-flip", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
trie-db = "0.16.0"
trie-db = "0.18.0"
serde_json = "1.0.41"

[features]
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ libsecp256k1 = "0.3.2"
tiny-keccak = "1.5.0"
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie-db = "0.16.0"
trie-db = "0.18.0"
serde_json = "1.0.41"

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2,
spec_version: 1034,
impl_version: 0,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
};

Expand Down
2 changes: 1 addition & 1 deletion runtime/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ libsecp256k1 = "0.3.2"
tiny-keccak = "1.5.0"
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie-db = "0.16.0"
trie-db = "0.18.0"
serde_json = "1.0.41"

[build-dependencies]
Expand Down
3 changes: 0 additions & 3 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,8 @@ pallet_staking_reward_curve::build! {

parameter_types! {
// Six sessions in an era (24 hours).
// pub const SessionsPerEra: SessionIndex = 6;
pub const SessionsPerEra: SessionIndex = 6;
// 28 eras for unbonding (28 days).
// KUSAMA: This value is 1/4 of what we expect for the mainnet, however session length is also
// a quarter, so the figure remains the same.
pub const BondingDuration: staking::EraIndex = 28;
pub const SlashDeferDuration: staking::EraIndex = 28;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
Expand Down
4 changes: 2 additions & 2 deletions scripts/gitlab/check_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ github_label () {
}



for VERSIONS_FILE in runtime/kusama/src/lib.rs runtime/polkadot/src/lib.rs
# Introduce runtime/polkadot/src/lib.rs once Polkadot mainnet is live.
for VERSIONS_FILE in runtime/kusama/src/lib.rs
do
# check if the wasm sources changed
if ! git diff --name-only origin/master...${CI_COMMIT_SHA} \
Expand Down
3 changes: 3 additions & 0 deletions service/res/kusama.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
},
"consensusEngine": null,
"forkBlocks": null,
"badBlocks": [
"0x15b1b925b0aa5cfe43c88cd024f74258cb5cfe3af424882c901014e8acd0d241"
],
"genesis": {
"raw": [
{
Expand Down
2 changes: 2 additions & 0 deletions service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const DEFAULT_PROTOCOL_ID: &str = "dot";
pub struct Extensions {
/// Block numbers with known hashes.
pub fork_blocks: client::ForkBlocks<polkadot_primitives::Block>,
/// Known bad block hashes.
pub bad_blocks: client::BadBlocks<polkadot_primitives::Block>,
}

/// The `ChainSpec`.
Expand Down
60 changes: 58 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,57 @@ pub fn kusama_new_full(config: Configuration)
new_full(config)
}

pub fn kusama_chain_hotfix<Runtime, Dispatch>(config: &Configuration) where
Dispatch: NativeExecutionDispatch,
Runtime: Send + Sync,
{
use std::str::FromStr;
use sp_blockchain::HeaderBackend;

let client: service::TFullClient<Block, Runtime, Dispatch> =
service::new_full_client(&config).unwrap();

let fork_block = 516510; // target_block - reverted_blocks + 1;
let fork_hash = primitives::H256::from_str(
"15b1b925b0aa5cfe43c88cd024f74258cb5cfe3af424882c901014e8acd0d241",
).unwrap();

let best_number = client.info().best_number;
let target_hash = client.hash(fork_block).unwrap();

if target_hash == Some(fork_hash) {
let diff = best_number.saturating_sub(fork_block - 1);
client.unsafe_revert(diff).unwrap();
}
}

pub fn kusama_grandpa_hotfix<Runtime, Dispatch>(
client: &service::TFullClient<Block, Runtime, Dispatch>,
persistent_data: &mut grandpa::PersistentData<Block>,
) where
Dispatch: NativeExecutionDispatch,
Runtime: Send + Sync,
{
let authority_set = &persistent_data.authority_set;

let finalized = {
use sp_blockchain::HeaderBackend;
let info = client.info();
(info.finalized_hash, info.finalized_number)
};

let canon_finalized_height = 516509;
if authority_set.set_id() == 235 && finalized.1 == canon_finalized_height {
let set_state = grandpa::VoterSetState::<Block>::live(
authority_set.set_id(),
&authority_set.inner().read(),
finalized,
);

persistent_data.set_state = set_state.into();
}
}

/// Builds a new service for a full client.
pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
-> Result<impl AbstractService<
Expand Down Expand Up @@ -315,7 +366,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
)?
.build()?;

let (block_import, link_half, babe_link) = import_setup.take()
let (block_import, mut link_half, babe_link) = import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");

let client = service.client();
Expand Down Expand Up @@ -411,7 +462,6 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
let can_author_with =
consensus_common::CanAuthorWithNativeVersion::new(client.executor().clone());


let block_import = availability_store.block_import(
block_import,
client.clone(),
Expand Down Expand Up @@ -477,6 +527,11 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)

let enable_grandpa = !disable_grandpa;
if enable_grandpa {
kusama_grandpa_hotfix(
&client,
&mut link_half.persistent_data,
);

// start the full GRANDPA voter
// NOTE: unlike in substrate we are currently running the full
// GRANDPA voter protocol for all full nodes (regardless of whether
Expand All @@ -493,6 +548,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
voting_rule: grandpa::VotingRulesBuilder::default().build(),
executor: service.spawn_task_handle(),
};

service.spawn_essential_task(grandpa::run_grandpa_voter(grandpa_config)?);
} else {
grandpa::setup_disabled_grandpa(
Expand Down

0 comments on commit f1d0678

Please sign in to comment.