Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
grandpa: allow authority set hard forks to be forced (#10444)
Browse files Browse the repository at this point in the history
* grandpa: allow authority set hard forks to be forced

* grandpa: fix authority set hard forks in warp proof provider

* grandpa: make AuthoritySetHardFork public

* grandpa: extend comment
  • Loading branch information
andresilva committed Dec 7, 2021
1 parent 49a4103 commit 272965a
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,24 @@ where
)
}

/// A descriptor for an authority set hard fork. These are authority set changes
/// that are not signalled by the runtime and instead are defined off-chain
/// (hence the hard fork).
pub struct AuthoritySetHardFork<Block: BlockT> {
/// The new authority set id.
pub set_id: SetId,
/// The block hash and number at which the hard fork should be applied.
pub block: (Block::Hash, NumberFor<Block>),
/// The authorities in the new set.
pub authorities: AuthorityList,
/// The latest block number that was finalized before this authority set
/// hard fork. When defined, the authority set change will be forced, i.e.
/// the node won't wait for the block above to be finalized before enacting
/// the change, and the given finalized number will be used as a base for
/// voting.
pub last_finalized: Option<NumberFor<Block>>,
}

/// Make block importer and link half necessary to tie the background voter to
/// it. A vector of authority set hard forks can be passed, any authority set
/// change signaled at the given block (either already signalled or in a further
Expand All @@ -528,14 +546,8 @@ pub fn block_import_with_authority_set_hard_forks<BE, Block: BlockT, Client, SC>
client: Arc<Client>,
genesis_authorities_provider: &dyn GenesisAuthoritySetProvider<Block>,
select_chain: SC,
authority_set_hard_forks: Vec<(SetId, (Block::Hash, NumberFor<Block>), AuthorityList)>,
) -> Result<
(
GrandpaBlockImport<BE, Block, Client, SC>,
LinkHalf<Block, Client, SC>,
),
ClientError,
>
authority_set_hard_forks: Vec<AuthoritySetHardFork<Block>>,
) -> Result<(GrandpaBlockImport<BE, Block, Client, SC>, LinkHalf<Block, Client, SC>), ClientError>
where
SC: SelectChain<Block>,
BE: Backend<Block> + 'static,
Expand All @@ -562,19 +574,24 @@ where
let (justification_sender, justification_stream) =
GrandpaJustificationStream::channel();

// create pending change objects with 0 delay and enacted on finality
// (i.e. standard changes) for each authority set hard fork.
// create pending change objects with 0 delay for each authority set hard fork.
let authority_set_hard_forks = authority_set_hard_forks
.into_iter()
.map(|(set_id, (hash, number), authorities)| {
.map(|fork| {
let delay_kind = if let Some(last_finalized) = fork.last_finalized {
authorities::DelayKind::Best { median_last_finalized: last_finalized }
} else {
authorities::DelayKind::Finalized
};

(
set_id,
fork.set_id,
authorities::PendingChange {
next_authorities: authorities,
next_authorities: fork.authorities,
delay: Zero::zero(),
canon_hash: hash,
canon_height: number,
delay_kind: authorities::DelayKind::Finalized,
canon_hash: fork.block.0,
canon_height: fork.block.1,
delay_kind,
},
)
})
Expand Down

0 comments on commit 272965a

Please sign in to comment.