mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 02:11:01 +00:00
Grandpa: save all completed prior rounds (#4203)
* Save concluded rounds. * Doc nit * Fix cargo
This commit is contained in:
@@ -36,6 +36,7 @@ use crate::NewAuthoritySet;
|
||||
|
||||
const VERSION_KEY: &[u8] = b"grandpa_schema_version";
|
||||
const SET_STATE_KEY: &[u8] = b"grandpa_completed_round";
|
||||
const CONCLUDED_ROUNDS: &[u8] = b"grandpa_concluded_rounds";
|
||||
const AUTHORITY_SET_KEY: &[u8] = b"grandpa_voters";
|
||||
const CONSENSUS_CHANGES_KEY: &[u8] = b"grandpa_consensus_changes";
|
||||
|
||||
@@ -405,6 +406,18 @@ pub(crate) fn write_voter_set_state<Block: BlockT, B: AuxStore>(
|
||||
)
|
||||
}
|
||||
|
||||
/// Write concluded round.
|
||||
pub(crate) fn write_concluded_round<Block: BlockT, B: AuxStore>(
|
||||
backend: &B,
|
||||
round_data: &CompletedRound<Block>,
|
||||
) -> ClientResult<()> {
|
||||
let mut key = CONCLUDED_ROUNDS.to_vec();
|
||||
let round_number = round_data.number;
|
||||
round_number.using_encoded(|n| key.extend(n));
|
||||
|
||||
backend.insert_aux(&[(&key[..], round_data.encode().as_slice())], &[])
|
||||
}
|
||||
|
||||
/// Update the consensus changes.
|
||||
pub(crate) fn update_consensus_changes<H, N, F, R>(
|
||||
set: &ConsensusChanges<H, N>,
|
||||
@@ -608,4 +621,29 @@ mod test {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_read_concluded_rounds() {
|
||||
let client = test_client::new();
|
||||
let hash = H256::random();
|
||||
let round_state = RoundState::genesis((hash, 0));
|
||||
|
||||
let completed_round = CompletedRound::<test_client::runtime::Block> {
|
||||
number: 42,
|
||||
state: round_state.clone(),
|
||||
base: round_state.prevote_ghost.unwrap(),
|
||||
votes: vec![],
|
||||
};
|
||||
|
||||
assert!(write_concluded_round(&client, &completed_round).is_ok());
|
||||
|
||||
let round_number = completed_round.number;
|
||||
let mut key = CONCLUDED_ROUNDS.to_vec();
|
||||
round_number.using_encoded(|n| key.extend(n));
|
||||
|
||||
assert_eq!(
|
||||
load_decode::<_, CompletedRound::<test_client::runtime::Block>>(&client, &key).unwrap(),
|
||||
Some(completed_round),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,6 +865,7 @@ where
|
||||
historical_votes.seen().iter().skip(n_existing_votes).cloned()
|
||||
);
|
||||
already_completed.state = state;
|
||||
crate::aux_schema::write_concluded_round(&*self.client, &already_completed);
|
||||
}
|
||||
|
||||
let set_state = VoterSetState::<Block>::Live {
|
||||
|
||||
Reference in New Issue
Block a user