mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 03:38:00 +00:00
grandpa: allow authority set hard forks to be forced (#10444)
* 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
This commit is contained in:
@@ -541,6 +541,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
|
||||
@@ -550,7 +568,7 @@ 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)>,
|
||||
authority_set_hard_forks: Vec<AuthoritySetHardFork<Block>>,
|
||||
telemetry: Option<TelemetryHandle>,
|
||||
) -> Result<(GrandpaBlockImport<BE, Block, Client, SC>, LinkHalf<Block, Client, SC>), ClientError>
|
||||
where
|
||||
@@ -580,19 +598,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,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
use sp_runtime::codec::{self, Decode, Encode};
|
||||
|
||||
use crate::{
|
||||
best_justification, find_scheduled_change, AuthoritySetChanges, BlockNumberOps,
|
||||
GrandpaJustification, SharedAuthoritySet,
|
||||
best_justification, find_scheduled_change, AuthoritySetChanges, AuthoritySetHardFork,
|
||||
BlockNumberOps, GrandpaJustification, SharedAuthoritySet,
|
||||
};
|
||||
use sc_client_api::Backend as ClientBackend;
|
||||
use sc_network::warp_request_handler::{EncodedProof, VerificationResult, WarpSyncProvider};
|
||||
@@ -255,12 +255,15 @@ where
|
||||
pub fn new(
|
||||
backend: Arc<Backend>,
|
||||
authority_set: SharedAuthoritySet<Block::Hash, NumberFor<Block>>,
|
||||
hard_forks: Vec<(SetId, (Block::Hash, NumberFor<Block>), AuthorityList)>,
|
||||
hard_forks: Vec<AuthoritySetHardFork<Block>>,
|
||||
) -> Self {
|
||||
NetworkProvider {
|
||||
backend,
|
||||
authority_set,
|
||||
hard_forks: hard_forks.into_iter().map(|(s, hn, list)| (hn, (s, list))).collect(),
|
||||
hard_forks: hard_forks
|
||||
.into_iter()
|
||||
.map(|fork| (fork.block, (fork.set_id, fork.authorities)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user