grandpa: support for hard forking any pending standard changes (#5306)

* grandpa: support for hard forking any pending standard changes

* grandpa: expose authority_set_hard_forks in block import constructor

* grandpa: don't break the public api
This commit is contained in:
André Silva
2020-03-19 10:37:29 +00:00
committed by GitHub
parent 86410de227
commit c7a23d836d
2 changed files with 104 additions and 6 deletions
+54 -2
View File
@@ -417,10 +417,43 @@ pub fn block_import<BE, Block: BlockT, Client, SC>(
client: Arc<Client>,
genesis_authorities_provider: &dyn GenesisAuthoritySetProvider<Block>,
select_chain: SC,
) -> Result<(
) -> Result<
(
GrandpaBlockImport<BE, Block, Client, SC>,
LinkHalf<Block, Client, SC>,
), ClientError>
),
ClientError,
>
where
SC: SelectChain<Block>,
BE: Backend<Block> + 'static,
Client: ClientForGrandpa<Block, BE> + 'static,
{
block_import_with_authority_set_hard_forks(
client,
genesis_authorities_provider,
select_chain,
Default::default(),
)
}
/// 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
/// block when importing it) will be replaced by a standard change with the
/// given static authorities.
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,
>
where
SC: SelectChain<Block>,
BE: Backend<Block> + 'static,
@@ -444,6 +477,24 @@ where
let (voter_commands_tx, voter_commands_rx) = mpsc::unbounded();
// create pending change objects with 0 delay and enacted on finality
// (i.e. standard changes) for each authority set hard fork.
let authority_set_hard_forks = authority_set_hard_forks
.into_iter()
.map(|(set_id, (hash, number), authorities)| {
(
set_id,
authorities::PendingChange {
next_authorities: authorities,
delay: Zero::zero(),
canon_hash: hash,
canon_height: number,
delay_kind: authorities::DelayKind::Finalized,
},
)
})
.collect();
Ok((
GrandpaBlockImport::new(
client.clone(),
@@ -451,6 +502,7 @@ where
persistent_data.authority_set.clone(),
voter_commands_tx,
persistent_data.consensus_changes.clone(),
authority_set_hard_forks,
),
LinkHalf {
client,