Skip to content

Commit f1d0678

Browse files
Hotfix for Kusama (paritytech#724)
* 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>
1 parent eac2ae7 commit f1d0678

File tree

11 files changed

+206
-159
lines changed

11 files changed

+206
-159
lines changed

Cargo.lock

+127-142
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,15 @@ where
140140
service::new_light::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
141141
exit.into_exit(),
142142
),
143-
_ => run_until_exit(
144-
runtime,
145-
service::new_full::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
146-
exit.into_exit(),
147-
),
143+
_ => {
144+
service::kusama_chain_hotfix::<R, D>(&config);
145+
146+
run_until_exit(
147+
runtime,
148+
service::new_full::<R, D, E>(config).map_err(|e| format!("{:?}", e))?,
149+
exit.into_exit(),
150+
)
151+
},
148152
}.map_err(|e| format!("{:?}", e))
149153
}),
150154
cli::ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(&load_spec),

runtime/common/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "polkadot-runtime-common"
3-
version = "0.7.10"
3+
version = "0.7.11"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2018"
66

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

4747
[features]

runtime/kusama/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ libsecp256k1 = "0.3.2"
6868
tiny-keccak = "1.5.0"
6969
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
7070
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
71-
trie-db = "0.16.0"
71+
trie-db = "0.18.0"
7272
serde_json = "1.0.41"
7373

7474
[build-dependencies]

runtime/kusama/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
7979
impl_name: create_runtime_str!("parity-kusama"),
8080
authoring_version: 2,
8181
spec_version: 1034,
82-
impl_version: 0,
82+
impl_version: 1,
8383
apis: RUNTIME_API_VERSIONS,
8484
};
8585

runtime/polkadot/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ libsecp256k1 = "0.3.2"
6666
tiny-keccak = "1.5.0"
6767
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
6868
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
69-
trie-db = "0.16.0"
69+
trie-db = "0.18.0"
7070
serde_json = "1.0.41"
7171

7272
[build-dependencies]

runtime/polkadot/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,8 @@ pallet_staking_reward_curve::build! {
273273

274274
parameter_types! {
275275
// Six sessions in an era (24 hours).
276-
// pub const SessionsPerEra: SessionIndex = 6;
277276
pub const SessionsPerEra: SessionIndex = 6;
278277
// 28 eras for unbonding (28 days).
279-
// KUSAMA: This value is 1/4 of what we expect for the mainnet, however session length is also
280-
// a quarter, so the figure remains the same.
281278
pub const BondingDuration: staking::EraIndex = 28;
282279
pub const SlashDeferDuration: staking::EraIndex = 28;
283280
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;

scripts/gitlab/check_runtime.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ github_label () {
2929
}
3030

3131

32-
33-
for VERSIONS_FILE in runtime/kusama/src/lib.rs runtime/polkadot/src/lib.rs
32+
# Introduce runtime/polkadot/src/lib.rs once Polkadot mainnet is live.
33+
for VERSIONS_FILE in runtime/kusama/src/lib.rs
3434
do
3535
# check if the wasm sources changed
3636
if ! git diff --name-only origin/master...${CI_COMMIT_SHA} \

service/res/kusama.json

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
},
2727
"consensusEngine": null,
2828
"forkBlocks": null,
29+
"badBlocks": [
30+
"0x15b1b925b0aa5cfe43c88cd024f74258cb5cfe3af424882c901014e8acd0d241"
31+
],
2932
"genesis": {
3033
"raw": [
3134
{

service/src/chain_spec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const DEFAULT_PROTOCOL_ID: &str = "dot";
4343
pub struct Extensions {
4444
/// Block numbers with known hashes.
4545
pub fork_blocks: client::ForkBlocks<polkadot_primitives::Block>,
46+
/// Known bad block hashes.
47+
pub bad_blocks: client::BadBlocks<polkadot_primitives::Block>,
4648
}
4749

4850
/// The `ChainSpec`.

service/src/lib.rs

+58-2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,57 @@ pub fn kusama_new_full(config: Configuration)
263263
new_full(config)
264264
}
265265

266+
pub fn kusama_chain_hotfix<Runtime, Dispatch>(config: &Configuration) where
267+
Dispatch: NativeExecutionDispatch,
268+
Runtime: Send + Sync,
269+
{
270+
use std::str::FromStr;
271+
use sp_blockchain::HeaderBackend;
272+
273+
let client: service::TFullClient<Block, Runtime, Dispatch> =
274+
service::new_full_client(&config).unwrap();
275+
276+
let fork_block = 516510; // target_block - reverted_blocks + 1;
277+
let fork_hash = primitives::H256::from_str(
278+
"15b1b925b0aa5cfe43c88cd024f74258cb5cfe3af424882c901014e8acd0d241",
279+
).unwrap();
280+
281+
let best_number = client.info().best_number;
282+
let target_hash = client.hash(fork_block).unwrap();
283+
284+
if target_hash == Some(fork_hash) {
285+
let diff = best_number.saturating_sub(fork_block - 1);
286+
client.unsafe_revert(diff).unwrap();
287+
}
288+
}
289+
290+
pub fn kusama_grandpa_hotfix<Runtime, Dispatch>(
291+
client: &service::TFullClient<Block, Runtime, Dispatch>,
292+
persistent_data: &mut grandpa::PersistentData<Block>,
293+
) where
294+
Dispatch: NativeExecutionDispatch,
295+
Runtime: Send + Sync,
296+
{
297+
let authority_set = &persistent_data.authority_set;
298+
299+
let finalized = {
300+
use sp_blockchain::HeaderBackend;
301+
let info = client.info();
302+
(info.finalized_hash, info.finalized_number)
303+
};
304+
305+
let canon_finalized_height = 516509;
306+
if authority_set.set_id() == 235 && finalized.1 == canon_finalized_height {
307+
let set_state = grandpa::VoterSetState::<Block>::live(
308+
authority_set.set_id(),
309+
&authority_set.inner().read(),
310+
finalized,
311+
);
312+
313+
persistent_data.set_state = set_state.into();
314+
}
315+
}
316+
266317
/// Builds a new service for a full client.
267318
pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
268319
-> Result<impl AbstractService<
@@ -315,7 +366,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
315366
)?
316367
.build()?;
317368

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

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

414-
415465
let block_import = availability_store.block_import(
416466
block_import,
417467
client.clone(),
@@ -477,6 +527,11 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
477527

478528
let enable_grandpa = !disable_grandpa;
479529
if enable_grandpa {
530+
kusama_grandpa_hotfix(
531+
&client,
532+
&mut link_half.persistent_data,
533+
);
534+
480535
// start the full GRANDPA voter
481536
// NOTE: unlike in substrate we are currently running the full
482537
// GRANDPA voter protocol for all full nodes (regardless of whether
@@ -493,6 +548,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
493548
voting_rule: grandpa::VotingRulesBuilder::default().build(),
494549
executor: service.spawn_task_handle(),
495550
};
551+
496552
service.spawn_essential_task(grandpa::run_grandpa_voter(grandpa_config)?);
497553
} else {
498554
grandpa::setup_disabled_grandpa(

0 commit comments

Comments
 (0)