Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

40 changes: 35 additions & 5 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,50 @@ pub fn kusama_grandpa_hotfix<Runtime, Dispatch>(
Dispatch: NativeExecutionDispatch,
Runtime: Send + Sync,
{
use std::str::FromStr;
use sp_blockchain::HeaderBackend;

let authority_set = &persistent_data.authority_set;
let last_completed_round = persistent_data.set_state
.read()
.last_completed_round()
.number;

let canon_finalized_block = 516509;
let canon_finalized_hash = primitives::H256::from_str(
"f432b7655a848094e6c67f8064ea642bd18f5cf184e1cf9f05a1a9886dd8b9cc",
).unwrap();

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(
// our finalized block is lower than the fork block, nothing to do
if finalized.1 < canon_finalized_block {
return;
}

// we have finalized past the fork block, we need to make sure we're on the
// correct fork (should be guaranteed by the previous chain revert)
if finalized.1 >= canon_finalized_block {
assert_eq!(
client.hash(canon_finalized_block).unwrap().unwrap(),
canon_finalized_hash,
);
}

// assuming the previous preconditions, if we are in any previous grandpa
// round then we restart at the given reset round.
let grandpa_reset_round = 999999;
if authority_set.set_id() == 235 &&
last_completed_round < grandpa_reset_round
{
let set_state = grandpa::VoterSetState::<Block>::live_at(
authority_set.set_id(),
grandpa_reset_round,
&authority_set.inner().read(),
finalized,
(canon_finalized_hash, canon_finalized_block),
);

persistent_data.set_state = set_state.into();
Expand Down