pub(crate) fn update_authority_set<H, N, F, R>(
	set: &AuthoritySet<H, N>,
	new_set: Option<&NewAuthoritySet<H, N>>,
	write_aux: F
) -> R where
	H: Encode + Clone,
	N: Encode + Clone,
	F: FnOnce(&[(&'static [u8], &[u8])]) -> R,
{
	// write new authority set state to disk.
	let encoded_set = set.encode();

	if let Some(new_set) = new_set {
		// we also overwrite the "last completed round" entry with a blank slate
		// because from the perspective of the finality gadget, the chain has
		// reset.
		let round_state = RoundState::genesis((
			new_set.canon_hash.clone(),
			new_set.canon_number.clone(),
		));
		let set_state = VoterSetState::Live(0, round_state);
		let encoded = set_state.encode();

		write_aux(&[
			(AUTHORITY_SET_KEY, &encoded_set[..]),
			(SET_STATE_KEY, &encoded[..]),
		])
	} else {
		write_aux(&[(AUTHORITY_SET_KEY, &encoded_set[..])])
	}
}
/// Update the authority set on disk after a change.
Update the authority set on disk after a change.
Update the authority set on disk after a change .
pub(crate) fn update_authority_set<H, N, F, R>(
	set: &AuthoritySet<H, N>,
	new_set: Option<&NewAuthoritySet<H, N>>,
	write_aux: F
) -> R where
	H: Encode + Clone,
	N: Encode + Clone,
	F: FnOnce(&[(&'static [u8], &[u8])]) -> R,
{
	// write new authority set state to disk.
	let encoded_set = set.encode();
	if let Some(new_set) = new_set {
		// we also overwrite the "last completed round" entry with a blank slate
		// because from the perspective of the finality gadget, the chain has
		// reset.
		let round_state = RoundState::genesis((
			new_set.canon_hash.clone(),
			new_set.canon_number.clone(),
		));
		let set_state = VoterSetState::Live(0, round_state);
		let encoded = set_state.encode();
		write_aux(&[
			(AUTHORITY_SET_KEY, &encoded_set[..]),
			(SET_STATE_KEY, &encoded[..]),
		])
	} else {
		write_aux(&[(AUTHORITY_SET_KEY, &encoded_set[..])])
	}
}
pub ( crate ) fn update_authority_set < H , N , F , R > ( set : & AuthoritySet < H , N > , new_set : Option < & NewAuthoritySet < H , N > > , write_aux : F ) -> R where H : Encode + Clone , N : Encode + Clone , F : FnOnce ( & [ ( & ' static [ u8 ] , & [ u8 ] ) ] ) -> R , { // write new authority set state to disk. let encoded_set = set . encode ( ) ; if let Some ( new_set ) = new_set { // we also overwrite the "last completed round" entry with a blank slate // because from the perspective of the finality gadget, the chain has // reset. let round_state = RoundState :: genesis ( ( new_set . canon_hash . clone ( ) , new_set . canon_number . clone ( ) , ) ) ; let set_state = VoterSetState :: Live ( 0 , round_state ) ; let encoded = set_state . encode ( ) ; write_aux ( & [ ( AUTHORITY_SET_KEY , & encoded_set [ .. ] ) , ( SET_STATE_KEY , & encoded [ .. ] ) , ] ) } else { write_aux ( & [ ( AUTHORITY_SET_KEY , & encoded_set [ .. ] ) ] ) } }
Update the authority set on disk after a change.
Update the authority set on disk after a change .
set
&AuthoritySet<H, N>
new_set
Option<&NewAuthoritySet<H, N>>
write_aux
F
set
&AuthoritySet<H, N>
new_set
Option<&NewAuthoritySet<H, N>>
write_aux
F