style: Migrate to stable-only rustfmt configuration
- Remove nightly-only features from .rustfmt.toml and vendor/ss58-registry/rustfmt.toml - Removed features: imports_granularity, wrap_comments, comment_width, reorder_impl_items, spaces_around_ranges, binop_separator, match_arm_blocks, trailing_semicolon, trailing_comma - Format all 898 affected files with stable rustfmt - Ensures long-term reliability without nightly toolchain dependency
This commit is contained in:
@@ -88,8 +88,9 @@ where
|
||||
|
||||
Ok(CheckedHeader::Checked(header, (slot, seal)))
|
||||
},
|
||||
Err(SealVerificationError::Deferred(header, slot)) =>
|
||||
Ok(CheckedHeader::Deferred(header, slot)),
|
||||
Err(SealVerificationError::Deferred(header, slot)) => {
|
||||
Ok(CheckedHeader::Deferred(header, slot))
|
||||
},
|
||||
Err(SealVerificationError::Unsealed) => Err(Error::HeaderUnsealed(hash)),
|
||||
Err(SealVerificationError::BadSeal) => Err(Error::HeaderBadSeal(hash)),
|
||||
Err(SealVerificationError::BadSignature) => Err(Error::BadSignature(hash)),
|
||||
|
||||
@@ -520,7 +520,7 @@ where
|
||||
match compatibility_mode {
|
||||
CompatibilityMode::None => {},
|
||||
// Use `initialize_block` until we hit the block that should disable the mode.
|
||||
CompatibilityMode::UseInitializeBlock { until } =>
|
||||
CompatibilityMode::UseInitializeBlock { until } => {
|
||||
if *until > context_block_number {
|
||||
runtime_api
|
||||
.initialize_block(
|
||||
@@ -534,7 +534,8 @@ where
|
||||
),
|
||||
)
|
||||
.map_err(|_| ConsensusError::InvalidAuthoritiesSet)?;
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
runtime_api
|
||||
|
||||
@@ -208,7 +208,7 @@ where
|
||||
match compatibility_mode {
|
||||
CompatibilityMode::None => {},
|
||||
// Use `initialize_block` until we hit the block that should disable the mode.
|
||||
CompatibilityMode::UseInitializeBlock { until } =>
|
||||
CompatibilityMode::UseInitializeBlock { until } => {
|
||||
if *until > context_block_number {
|
||||
runtime_api
|
||||
.initialize_block(
|
||||
@@ -222,7 +222,8 @@ where
|
||||
),
|
||||
)
|
||||
.map_err(|_| ConsensusError::InvalidAuthoritiesSet)?;
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
runtime_api
|
||||
|
||||
@@ -53,8 +53,8 @@ pub(super) fn calculate_primary_threshold(
|
||||
|
||||
let c = c.0 as f64 / c.1 as f64;
|
||||
|
||||
let theta = authorities[authority_index].1 as f64 /
|
||||
authorities.iter().map(|(_, weight)| weight).sum::<u64>() as f64;
|
||||
let theta = authorities[authority_index].1 as f64
|
||||
/ authorities.iter().map(|(_, weight)| weight).sum::<u64>() as f64;
|
||||
|
||||
assert!(theta > 0.0, "authority with weight 0.");
|
||||
|
||||
@@ -204,8 +204,8 @@ pub fn claim_slot_using_keys(
|
||||
keys: &[(AuthorityId, usize)],
|
||||
) -> Option<(PreDigest, AuthorityId)> {
|
||||
claim_primary_slot(slot, epoch, epoch.config.c, keystore, keys).or_else(|| {
|
||||
if epoch.config.allowed_slots.is_secondary_plain_slots_allowed() ||
|
||||
epoch.config.allowed_slots.is_secondary_vrf_slots_allowed()
|
||||
if epoch.config.allowed_slots.is_secondary_plain_slots_allowed()
|
||||
|| epoch.config.allowed_slots.is_secondary_vrf_slots_allowed()
|
||||
{
|
||||
claim_secondary_slot(
|
||||
slot,
|
||||
|
||||
@@ -62,21 +62,25 @@ pub fn load_epoch_changes<Block: BlockT, B: AuxStore>(
|
||||
let version = load_decode::<_, u32>(backend, BABE_EPOCH_CHANGES_VERSION)?;
|
||||
|
||||
let maybe_epoch_changes = match version {
|
||||
None =>
|
||||
None => {
|
||||
load_decode::<_, EpochChangesV0For<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
.map(|v0| v0.migrate().map(|_, _, epoch| epoch.migrate(config))),
|
||||
Some(1) =>
|
||||
.map(|v0| v0.migrate().map(|_, _, epoch| epoch.migrate(config)))
|
||||
},
|
||||
Some(1) => {
|
||||
load_decode::<_, EpochChangesV1For<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
.map(|v1| v1.migrate().map(|_, _, epoch| epoch.migrate(config))),
|
||||
.map(|v1| v1.migrate().map(|_, _, epoch| epoch.migrate(config)))
|
||||
},
|
||||
Some(2) => {
|
||||
// v2 still uses `EpochChanges` v1 format but with a different `Epoch` type.
|
||||
load_decode::<_, EpochChangesV1For<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
.map(|v2| v2.migrate())
|
||||
},
|
||||
Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) =>
|
||||
load_decode::<_, EpochChangesFor<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?,
|
||||
Some(other) =>
|
||||
return Err(ClientError::Backend(format!("Unsupported BABE DB version: {:?}", other))),
|
||||
Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) => {
|
||||
load_decode::<_, EpochChangesFor<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?
|
||||
},
|
||||
Some(other) => {
|
||||
return Err(ClientError::Backend(format!("Unsupported BABE DB version: {:?}", other)))
|
||||
},
|
||||
};
|
||||
|
||||
let epoch_changes =
|
||||
@@ -199,8 +203,8 @@ mod test {
|
||||
.tree()
|
||||
.iter()
|
||||
.map(|(_, _, epoch)| epoch.clone())
|
||||
.collect::<Vec<_>>() ==
|
||||
vec![PersistedEpochHeader::Regular(EpochHeader {
|
||||
.collect::<Vec<_>>()
|
||||
== vec![PersistedEpochHeader::Regular(EpochHeader {
|
||||
start_slot: 0.into(),
|
||||
end_slot: 100.into(),
|
||||
})],
|
||||
|
||||
@@ -401,10 +401,11 @@ where
|
||||
}
|
||||
},
|
||||
Some(2) => runtime_api.configuration(at_hash)?,
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(pezsp_blockchain::Error::VersionInvalid(
|
||||
"Unsupported or invalid BabeApi version".to_string(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
Ok(config)
|
||||
}
|
||||
@@ -791,13 +792,14 @@ where
|
||||
let sinks = &mut self.slot_notification_sinks.lock();
|
||||
sinks.retain_mut(|sink| match sink.try_send((slot, epoch_descriptor.clone())) {
|
||||
Ok(()) => true,
|
||||
Err(e) =>
|
||||
Err(e) => {
|
||||
if e.is_full() {
|
||||
warn!(target: LOG_TARGET, "Trying to notify a slot but the channel is full");
|
||||
true
|
||||
} else {
|
||||
false
|
||||
},
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -927,8 +929,9 @@ pub fn find_next_epoch_digest<B: BlockT>(
|
||||
trace!(target: LOG_TARGET, "Checking log {:?}, looking for epoch change digest.", log);
|
||||
let log = log.try_to::<ConsensusLog>(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID));
|
||||
match (log, epoch_digest.is_some()) {
|
||||
(Some(ConsensusLog::NextEpochData(_)), true) =>
|
||||
return Err(babe_err(Error::MultipleEpochChangeDigests)),
|
||||
(Some(ConsensusLog::NextEpochData(_)), true) => {
|
||||
return Err(babe_err(Error::MultipleEpochChangeDigests))
|
||||
},
|
||||
(Some(ConsensusLog::NextEpochData(epoch)), false) => epoch_digest = Some(epoch),
|
||||
_ => trace!(target: LOG_TARGET, "Ignoring digest not meant for us"),
|
||||
}
|
||||
@@ -946,8 +949,9 @@ fn find_next_config_digest<B: BlockT>(
|
||||
trace!(target: LOG_TARGET, "Checking log {:?}, looking for epoch change digest.", log);
|
||||
let log = log.try_to::<ConsensusLog>(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID));
|
||||
match (log, config_digest.is_some()) {
|
||||
(Some(ConsensusLog::NextConfigData(_)), true) =>
|
||||
return Err(babe_err(Error::MultipleConfigChangeDigests)),
|
||||
(Some(ConsensusLog::NextConfigData(_)), true) => {
|
||||
return Err(babe_err(Error::MultipleConfigChangeDigests))
|
||||
},
|
||||
(Some(ConsensusLog::NextConfigData(config)), false) => config_digest = Some(config),
|
||||
_ => trace!(target: LOG_TARGET, "Ignoring digest not meant for us"),
|
||||
}
|
||||
@@ -1094,8 +1098,8 @@ fn is_state_sync_or_gap_sync_import<B: BlockT>(
|
||||
) -> bool {
|
||||
let number = *block.header.number();
|
||||
let info = client.info();
|
||||
info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end) ||
|
||||
block.with_state()
|
||||
info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end)
|
||||
|| block.with_state()
|
||||
}
|
||||
|
||||
/// A block-import handler for BABE.
|
||||
@@ -1200,11 +1204,12 @@ where
|
||||
let import_result = self.inner.import_block(block).await;
|
||||
let aux = match import_result {
|
||||
Ok(ImportResult::Imported(aux)) => aux,
|
||||
Ok(r) =>
|
||||
Ok(r) => {
|
||||
return Err(ConsensusError::ClientImport(format!(
|
||||
"Unexpected import result: {:?}",
|
||||
r
|
||||
))),
|
||||
)))
|
||||
},
|
||||
Err(r) => return Err(r.into()),
|
||||
};
|
||||
|
||||
@@ -1271,8 +1276,9 @@ where
|
||||
.get(babe_pre_digest.authority_index() as usize)
|
||||
{
|
||||
Some(author) => author.0.clone(),
|
||||
None =>
|
||||
return Err(ConsensusError::Other(Error::<Block>::SlotAuthorNotFound.into())),
|
||||
None => {
|
||||
return Err(ConsensusError::Other(Error::<Block>::SlotAuthorNotFound.into()))
|
||||
},
|
||||
}
|
||||
};
|
||||
if let Err(err) = self
|
||||
@@ -1321,12 +1327,14 @@ where
|
||||
.await
|
||||
.map_err(|e| {
|
||||
ConsensusError::Other(Box::new(match e {
|
||||
CheckInherentsError::CreateInherentData(e) =>
|
||||
Error::<Block>::CreateInherents(e),
|
||||
CheckInherentsError::CreateInherentData(e) => {
|
||||
Error::<Block>::CreateInherents(e)
|
||||
},
|
||||
CheckInherentsError::Client(e) => Error::RuntimeApi(e),
|
||||
CheckInherentsError::CheckInherents(e) => Error::CheckInherents(e),
|
||||
CheckInherentsError::CheckInherentsUnknownError(id) =>
|
||||
Error::CheckInherentsUnhandled(id),
|
||||
CheckInherentsError::CheckInherentsUnknownError(id) => {
|
||||
Error::CheckInherentsUnhandled(id)
|
||||
},
|
||||
}))
|
||||
})?;
|
||||
let (_, inner_body) = new_block.deconstruct();
|
||||
@@ -1463,8 +1471,8 @@ where
|
||||
// Skip babe logic if block already in chain or importing blocks during initial sync,
|
||||
// otherwise the check for epoch changes will error because trying to re-import an
|
||||
// epoch change or because of missing epoch data in the tree, respectively.
|
||||
if info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end) ||
|
||||
block_status == BlockStatus::InChain
|
||||
if info.block_gap.map_or(false, |gap| gap.start <= number && number <= gap.end)
|
||||
|| block_status == BlockStatus::InChain
|
||||
{
|
||||
// When re-importing existing block strip away intermediates.
|
||||
// In case of initial sync intermediates should not be present...
|
||||
@@ -1552,18 +1560,21 @@ where
|
||||
match (first_in_epoch, next_epoch_digest.is_some(), next_config_digest.is_some()) {
|
||||
(true, true, _) => {},
|
||||
(false, false, false) => {},
|
||||
(false, false, true) =>
|
||||
(false, false, true) => {
|
||||
return Err(ConsensusError::ClientImport(
|
||||
babe_err(Error::<Block>::UnexpectedConfigChange).into(),
|
||||
)),
|
||||
(true, false, _) =>
|
||||
))
|
||||
},
|
||||
(true, false, _) => {
|
||||
return Err(ConsensusError::ClientImport(
|
||||
babe_err(Error::<Block>::ExpectedEpochChange(hash, slot)).into(),
|
||||
)),
|
||||
(false, true, _) =>
|
||||
))
|
||||
},
|
||||
(false, true, _) => {
|
||||
return Err(ConsensusError::ClientImport(
|
||||
babe_err(Error::<Block>::UnexpectedEpochChange).into(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
}
|
||||
|
||||
if let Some(next_epoch_descriptor) = next_epoch_digest {
|
||||
@@ -1953,8 +1964,8 @@ where
|
||||
let mut hash = leaf;
|
||||
loop {
|
||||
let meta = client.header_metadata(hash)?;
|
||||
if meta.number <= revert_up_to_number ||
|
||||
!weight_keys.insert(aux_schema::block_weight_key(hash))
|
||||
if meta.number <= revert_up_to_number
|
||||
|| !weight_keys.insert(aux_schema::block_weight_key(hash))
|
||||
{
|
||||
// We've reached the revert point or an already processed branch, stop here.
|
||||
break;
|
||||
|
||||
@@ -73,10 +73,12 @@ where
|
||||
{
|
||||
warn!(target: LOG_TARGET, "🥩 backend contains a BEEFY state of an obsolete version {v}. ignoring...")
|
||||
},
|
||||
Some(4) =>
|
||||
return load_decode::<_, PersistedState<B, AuthorityId>>(backend, WORKER_STATE_KEY),
|
||||
other =>
|
||||
return Err(ClientError::Backend(format!("Unsupported BEEFY DB version: {:?}", other))),
|
||||
Some(4) => {
|
||||
return load_decode::<_, PersistedState<B, AuthorityId>>(backend, WORKER_STATE_KEY)
|
||||
},
|
||||
other => {
|
||||
return Err(ClientError::Backend(format!("Unsupported BEEFY DB version: {:?}", other)))
|
||||
},
|
||||
}
|
||||
|
||||
// No persistent state found in DB.
|
||||
|
||||
@@ -150,12 +150,13 @@ impl<B: Block, AuthorityId: AuthorityIdBound> Filter<B, AuthorityId> {
|
||||
f.start = cfg.start;
|
||||
f.end = cfg.end;
|
||||
},
|
||||
_ =>
|
||||
_ => {
|
||||
self.inner = Some(FilterInner {
|
||||
start: cfg.start,
|
||||
end: cfg.end,
|
||||
validator_set: cfg.validator_set.clone(),
|
||||
}),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,9 @@ pub(crate) fn proof_block_num_and_set_id<Block: BlockT, AuthorityId: AuthorityId
|
||||
proof: &BeefyVersionedFinalityProof<Block, AuthorityId>,
|
||||
) -> (NumberFor<Block>, ValidatorSetId) {
|
||||
match proof {
|
||||
VersionedFinalityProof::V1(sc) =>
|
||||
(sc.commitment.block_number, sc.commitment.validator_set_id),
|
||||
VersionedFinalityProof::V1(sc) => {
|
||||
(sc.commitment.block_number, sc.commitment.validator_set_id)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -787,10 +787,11 @@ where
|
||||
Some(active) => return Ok(active),
|
||||
// Move up the chain. Ultimately we'll get it from chain genesis state, or error out
|
||||
// there.
|
||||
None =>
|
||||
None => {
|
||||
header = wait_for_parent_header(blockchain, header, HEADER_SYNC_DELAY)
|
||||
.await
|
||||
.map_err(|e| Error::Backend(e.to_string()))?,
|
||||
.map_err(|e| Error::Backend(e.to_string()))?
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ where
|
||||
|
||||
// add valid vote
|
||||
let round = self.rounds.entry(vote.commitment.clone()).or_default();
|
||||
if round.add_vote((vote.id, vote.signature)) &&
|
||||
round.is_done(threshold(self.validator_set.len()))
|
||||
if round.add_vote((vote.id, vote.signature))
|
||||
&& round.is_done(threshold(self.validator_set.len()))
|
||||
{
|
||||
if let Some(round) = self.rounds.remove_entry(&vote.commitment) {
|
||||
return VoteImportResult::RoundConcluded(self.signed_commitment(round));
|
||||
|
||||
@@ -1576,8 +1576,9 @@ async fn gossipped_finality_proofs() {
|
||||
.ok()
|
||||
.and_then(|message| match message {
|
||||
GossipMessage::<Block, ecdsa_crypto::AuthorityId>::Vote(_) => unreachable!(),
|
||||
GossipMessage::<Block, ecdsa_crypto::AuthorityId>::FinalityProof(proof) =>
|
||||
Some(proof),
|
||||
GossipMessage::<Block, ecdsa_crypto::AuthorityId>::FinalityProof(proof) => {
|
||||
Some(proof)
|
||||
},
|
||||
})
|
||||
})
|
||||
.fuse(),
|
||||
|
||||
@@ -526,7 +526,7 @@ where
|
||||
{
|
||||
let block_num = vote.commitment.block_number;
|
||||
match self.voting_oracle().triage_round(block_num)? {
|
||||
RoundAction::Process =>
|
||||
RoundAction::Process => {
|
||||
if let Some(finality_proof) = self.handle_vote(vote)? {
|
||||
let gossip_proof =
|
||||
GossipMessage::<B, AuthorityId>::FinalityProof(finality_proof);
|
||||
@@ -536,7 +536,8 @@ where
|
||||
encoded_proof,
|
||||
true,
|
||||
);
|
||||
},
|
||||
}
|
||||
},
|
||||
RoundAction::Drop => metric_inc!(self.metrics, beefy_stale_votes),
|
||||
RoundAction::Enqueue => error!(target: LOG_TARGET, "🥩 unexpected vote: {:?}.", vote),
|
||||
};
|
||||
|
||||
@@ -157,9 +157,9 @@ impl<Block: BlockT> StateAction<Block> {
|
||||
/// Check if execution checks that require runtime calls should be skipped.
|
||||
pub fn skip_execution_checks(&self) -> bool {
|
||||
match self {
|
||||
StateAction::ApplyChanges(_) |
|
||||
StateAction::Execute |
|
||||
StateAction::ExecuteIfPossible => false,
|
||||
StateAction::ApplyChanges(_)
|
||||
| StateAction::Execute
|
||||
| StateAction::ExecuteIfPossible => false,
|
||||
StateAction::Skip => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,8 +193,8 @@ impl<BlockNumber: fmt::Debug + PartialEq> BlockImportStatus<BlockNumber> {
|
||||
/// Returns the imported block number.
|
||||
pub fn number(&self) -> &BlockNumber {
|
||||
match self {
|
||||
BlockImportStatus::ImportedKnown(n, _) |
|
||||
BlockImportStatus::ImportedUnknown(n, _, _) => n,
|
||||
BlockImportStatus::ImportedKnown(n, _)
|
||||
| BlockImportStatus::ImportedUnknown(n, _, _) => n,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,8 +242,9 @@ pub async fn import_single_block<B: BlockT, V: Verifier<B>>(
|
||||
) -> BlockImportResult<B> {
|
||||
match verify_single_block_metered(import_handle, block_origin, block, verifier, None).await? {
|
||||
SingleBlockVerificationOutcome::Imported(import_status) => Ok(import_status),
|
||||
SingleBlockVerificationOutcome::Verified(import_parameters) =>
|
||||
import_single_block_metered(import_handle, import_parameters, None).await,
|
||||
SingleBlockVerificationOutcome::Verified(import_parameters) => {
|
||||
import_single_block_metered(import_handle, import_parameters, None).await
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,8 +263,9 @@ where
|
||||
trace!(target: LOG_TARGET, "Block already in chain {}: {:?}", number, hash);
|
||||
Ok(BlockImportStatus::ImportedKnown(number, block_origin))
|
||||
},
|
||||
Ok(ImportResult::Imported(aux)) =>
|
||||
Ok(BlockImportStatus::ImportedUnknown(number, aux, block_origin)),
|
||||
Ok(ImportResult::Imported(aux)) => {
|
||||
Ok(BlockImportStatus::ImportedUnknown(number, aux, block_origin))
|
||||
},
|
||||
Ok(ImportResult::MissingState) => {
|
||||
debug!(
|
||||
target: LOG_TARGET,
|
||||
|
||||
@@ -310,8 +310,9 @@ impl<B: BlockT> BlockImportWorker<B> {
|
||||
// Make sure to first process all justifications
|
||||
while let Poll::Ready(justification) = futures::poll!(justification_port.next()) {
|
||||
match justification {
|
||||
Some(ImportJustification(who, hash, number, justification)) =>
|
||||
worker.import_justification(who, hash, number, justification).await,
|
||||
Some(ImportJustification(who, hash, number, justification)) => {
|
||||
worker.import_justification(who, hash, number, justification).await
|
||||
},
|
||||
None => {
|
||||
log::debug!(
|
||||
target: LOG_TARGET,
|
||||
@@ -361,8 +362,9 @@ impl<B: BlockT> BlockImportWorker<B> {
|
||||
});
|
||||
match result {
|
||||
Ok(()) => JustificationImportResult::Success,
|
||||
Err(pezsp_consensus::Error::OutdatedJustification) =>
|
||||
JustificationImportResult::OutdatedJustification,
|
||||
Err(pezsp_consensus::Error::OutdatedJustification) => {
|
||||
JustificationImportResult::OutdatedJustification
|
||||
},
|
||||
Err(_) => JustificationImportResult::Failure,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -127,12 +127,15 @@ impl<B: BlockT> BufferedLinkReceiver<B> {
|
||||
/// Send action for the synchronization to perform.
|
||||
pub fn send_actions(&mut self, msg: BlockImportWorkerMsg<B>, link: &dyn Link<B>) {
|
||||
match msg {
|
||||
BlockImportWorkerMsg::BlocksProcessed(imported, count, results) =>
|
||||
link.blocks_processed(imported, count, results),
|
||||
BlockImportWorkerMsg::JustificationImported(who, hash, number, import_result) =>
|
||||
link.justification_imported(who, &hash, number, import_result),
|
||||
BlockImportWorkerMsg::RequestJustification(hash, number) =>
|
||||
link.request_justification(&hash, number),
|
||||
BlockImportWorkerMsg::BlocksProcessed(imported, count, results) => {
|
||||
link.blocks_processed(imported, count, results)
|
||||
},
|
||||
BlockImportWorkerMsg::JustificationImported(who, hash, number, import_result) => {
|
||||
link.justification_imported(who, &hash, number, import_result)
|
||||
},
|
||||
BlockImportWorkerMsg::RequestJustification(hash, number) => {
|
||||
link.request_justification(&hash, number)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -199,8 +199,9 @@ where
|
||||
pub fn increment(&self, next_descriptor: E::NextEpochDescriptor) -> IncrementedEpoch<E> {
|
||||
let next = self.as_ref().increment(next_descriptor);
|
||||
let to_persist = match *self {
|
||||
ViableEpoch::UnimportedGenesis(ref epoch_0) =>
|
||||
PersistedEpoch::Genesis(epoch_0.clone(), next),
|
||||
ViableEpoch::UnimportedGenesis(ref epoch_0) => {
|
||||
PersistedEpoch::Genesis(epoch_0.clone(), next)
|
||||
},
|
||||
ViableEpoch::Signaled(_) => PersistedEpoch::Regular(next),
|
||||
};
|
||||
|
||||
@@ -246,8 +247,9 @@ impl<E> PersistedEpoch<E> {
|
||||
impl<'a, E: Epoch> From<&'a PersistedEpoch<E>> for PersistedEpochHeader<E> {
|
||||
fn from(epoch: &'a PersistedEpoch<E>) -> Self {
|
||||
match epoch {
|
||||
PersistedEpoch::Genesis(ref epoch_0, ref epoch_1) =>
|
||||
PersistedEpochHeader::Genesis(epoch_0.into(), epoch_1.into()),
|
||||
PersistedEpoch::Genesis(ref epoch_0, ref epoch_1) => {
|
||||
PersistedEpochHeader::Genesis(epoch_0.into(), epoch_1.into())
|
||||
},
|
||||
PersistedEpoch::Regular(ref epoch_n) => PersistedEpochHeader::Regular(epoch_n.into()),
|
||||
}
|
||||
}
|
||||
@@ -261,8 +263,9 @@ impl<E: Epoch> PersistedEpoch<E> {
|
||||
F: FnMut(&Hash, &Number, E) -> B,
|
||||
{
|
||||
match self {
|
||||
PersistedEpoch::Genesis(epoch_0, epoch_1) =>
|
||||
PersistedEpoch::Genesis(f(h, n, epoch_0), f(h, n, epoch_1)),
|
||||
PersistedEpoch::Genesis(epoch_0, epoch_1) => {
|
||||
PersistedEpoch::Genesis(f(h, n, epoch_0), f(h, n, epoch_1))
|
||||
},
|
||||
PersistedEpoch::Regular(epoch_n) => PersistedEpoch::Regular(f(h, n, epoch_n)),
|
||||
}
|
||||
}
|
||||
@@ -426,13 +429,19 @@ where
|
||||
self.epochs.get(&(id.hash, id.number)).and_then(|v| match v {
|
||||
PersistedEpoch::Genesis(ref epoch_0, _)
|
||||
if id.position == EpochIdentifierPosition::Genesis0 =>
|
||||
Some(epoch_0),
|
||||
{
|
||||
Some(epoch_0)
|
||||
},
|
||||
PersistedEpoch::Genesis(_, ref epoch_1)
|
||||
if id.position == EpochIdentifierPosition::Genesis1 =>
|
||||
Some(epoch_1),
|
||||
{
|
||||
Some(epoch_1)
|
||||
},
|
||||
PersistedEpoch::Regular(ref epoch_n)
|
||||
if id.position == EpochIdentifierPosition::Regular =>
|
||||
Some(epoch_n),
|
||||
{
|
||||
Some(epoch_n)
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -447,10 +456,12 @@ where
|
||||
G: FnOnce(E::Slot) -> E,
|
||||
{
|
||||
match descriptor {
|
||||
ViableEpochDescriptor::UnimportedGenesis(slot) =>
|
||||
Some(ViableEpoch::UnimportedGenesis(make_genesis(*slot))),
|
||||
ViableEpochDescriptor::Signaled(identifier, _) =>
|
||||
self.epoch(identifier).map(ViableEpoch::Signaled),
|
||||
ViableEpochDescriptor::UnimportedGenesis(slot) => {
|
||||
Some(ViableEpoch::UnimportedGenesis(make_genesis(*slot)))
|
||||
},
|
||||
ViableEpochDescriptor::Signaled(identifier, _) => {
|
||||
self.epoch(identifier).map(ViableEpoch::Signaled)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,13 +470,19 @@ where
|
||||
self.epochs.get_mut(&(id.hash, id.number)).and_then(|v| match v {
|
||||
PersistedEpoch::Genesis(ref mut epoch_0, _)
|
||||
if id.position == EpochIdentifierPosition::Genesis0 =>
|
||||
Some(epoch_0),
|
||||
{
|
||||
Some(epoch_0)
|
||||
},
|
||||
PersistedEpoch::Genesis(_, ref mut epoch_1)
|
||||
if id.position == EpochIdentifierPosition::Genesis1 =>
|
||||
Some(epoch_1),
|
||||
{
|
||||
Some(epoch_1)
|
||||
},
|
||||
PersistedEpoch::Regular(ref mut epoch_n)
|
||||
if id.position == EpochIdentifierPosition::Regular =>
|
||||
Some(epoch_n),
|
||||
{
|
||||
Some(epoch_n)
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -480,10 +497,12 @@ where
|
||||
G: FnOnce(E::Slot) -> E,
|
||||
{
|
||||
match descriptor {
|
||||
ViableEpochDescriptor::UnimportedGenesis(slot) =>
|
||||
Some(ViableEpoch::UnimportedGenesis(make_genesis(*slot))),
|
||||
ViableEpochDescriptor::Signaled(identifier, _) =>
|
||||
self.epoch_mut(identifier).map(ViableEpoch::Signaled),
|
||||
ViableEpochDescriptor::UnimportedGenesis(slot) => {
|
||||
Some(ViableEpoch::UnimportedGenesis(make_genesis(*slot)))
|
||||
},
|
||||
ViableEpochDescriptor::Signaled(identifier, _) => {
|
||||
self.epoch_mut(identifier).map(ViableEpoch::Signaled)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,8 +608,9 @@ where
|
||||
(EpochIdentifierPosition::Genesis0, epoch_0.clone())
|
||||
}
|
||||
},
|
||||
PersistedEpochHeader::Regular(ref epoch_n) =>
|
||||
(EpochIdentifierPosition::Regular, epoch_n.clone()),
|
||||
PersistedEpochHeader::Regular(ref epoch_n) => {
|
||||
(EpochIdentifierPosition::Regular, epoch_n.clone())
|
||||
},
|
||||
},
|
||||
node,
|
||||
)
|
||||
@@ -665,8 +685,8 @@ where
|
||||
let is_descendent_of = descendent_of_builder.build_is_descendent_of(None);
|
||||
|
||||
let filter = |node_hash: &Hash, node_num: &Number, _: &PersistedEpochHeader<E>| {
|
||||
if number >= *node_num &&
|
||||
(is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
|
||||
if number >= *node_num
|
||||
&& (is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
|
||||
{
|
||||
// Continue the search in this subtree.
|
||||
FilterAction::KeepNode
|
||||
@@ -1063,18 +1083,18 @@ mod tests {
|
||||
|
||||
let is_descendent_of = |base: &Hash, block: &Hash| -> Result<bool, TestError> {
|
||||
match (block, base) {
|
||||
| (b"A", b"0") |
|
||||
(b"B", b"0" | b"A") |
|
||||
(b"C", b"0" | b"A" | b"B") |
|
||||
(b"D", b"0" | b"A" | b"B" | b"C") |
|
||||
(b"E", b"0" | b"A" | b"B" | b"C" | b"D") |
|
||||
(b"F", b"0" | b"A" | b"B" | b"C" | b"D" | b"E") |
|
||||
(b"G", b"0" | b"A" | b"B" | b"C" | b"D" | b"E") |
|
||||
(b"H", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G") |
|
||||
(b"I", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H") |
|
||||
(b"J", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H" | b"I") |
|
||||
(b"K", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H" | b"I" | b"J") |
|
||||
(
|
||||
| (b"A", b"0")
|
||||
| (b"B", b"0" | b"A")
|
||||
| (b"C", b"0" | b"A" | b"B")
|
||||
| (b"D", b"0" | b"A" | b"B" | b"C")
|
||||
| (b"E", b"0" | b"A" | b"B" | b"C" | b"D")
|
||||
| (b"F", b"0" | b"A" | b"B" | b"C" | b"D" | b"E")
|
||||
| (b"G", b"0" | b"A" | b"B" | b"C" | b"D" | b"E")
|
||||
| (b"H", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G")
|
||||
| (b"I", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H")
|
||||
| (b"J", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H" | b"I")
|
||||
| (b"K", b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H" | b"I" | b"J")
|
||||
| (
|
||||
b"L",
|
||||
b"0" | b"A" | b"B" | b"C" | b"D" | b"E" | b"G" | b"H" | b"I" | b"J" | b"K",
|
||||
) => Ok(true),
|
||||
|
||||
@@ -230,8 +230,8 @@ where
|
||||
F: Fn(&H, &H) -> Result<bool, E>,
|
||||
{
|
||||
let filter = |node_hash: &H, node_num: &N, _: &PendingChange<H, N>| {
|
||||
if number >= *node_num &&
|
||||
(is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
|
||||
if number >= *node_num
|
||||
&& (is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
|
||||
{
|
||||
// Continue the search in this subtree.
|
||||
FilterAction::KeepNode
|
||||
@@ -291,8 +291,9 @@ where
|
||||
}
|
||||
|
||||
let earliest = match (forced, standard) {
|
||||
(Some(forced), Some(standard)) =>
|
||||
Some(if forced.1 < standard.1 { forced } else { standard }),
|
||||
(Some(forced), Some(standard)) => {
|
||||
Some(if forced.1 < standard.1 { forced } else { standard })
|
||||
},
|
||||
(Some(forced), None) => Some(forced),
|
||||
(None, Some(standard)) => Some(standard),
|
||||
(None, None) => None,
|
||||
@@ -476,8 +477,8 @@ where
|
||||
|
||||
// check if there's any pending standard change that we depend on
|
||||
for (_, _, standard_change) in self.pending_standard_changes.roots() {
|
||||
if standard_change.effective_number() <= median_last_finalized &&
|
||||
is_descendent_of(&standard_change.canon_hash, &change.canon_hash)?
|
||||
if standard_change.effective_number() <= median_last_finalized
|
||||
&& is_descendent_of(&standard_change.canon_hash, &change.canon_hash)?
|
||||
{
|
||||
log::info!(target: LOG_TARGET,
|
||||
"Not applying authority set change forced at block #{:?}, due to pending standard change at block #{:?}",
|
||||
@@ -566,8 +567,8 @@ where
|
||||
// we will keep all forced changes for any later blocks and that are a
|
||||
// descendent of the finalized block (i.e. they are part of this branch).
|
||||
for change in pending_forced_changes {
|
||||
if change.effective_number() > finalized_number &&
|
||||
is_descendent_of(&finalized_hash, &change.canon_hash)?
|
||||
if change.effective_number() > finalized_number
|
||||
&& is_descendent_of(&finalized_hash, &change.canon_hash)?
|
||||
{
|
||||
self.pending_forced_changes.push(change)
|
||||
}
|
||||
|
||||
@@ -382,8 +382,12 @@ where
|
||||
});
|
||||
}
|
||||
},
|
||||
Some(other) =>
|
||||
return Err(ClientError::Backend(format!("Unsupported GRANDPA DB version: {:?}", other))),
|
||||
Some(other) => {
|
||||
return Err(ClientError::Backend(format!(
|
||||
"Unsupported GRANDPA DB version: {:?}",
|
||||
other
|
||||
)))
|
||||
},
|
||||
}
|
||||
|
||||
// genesis.
|
||||
|
||||
@@ -199,12 +199,13 @@ impl<N: Ord> View<N> {
|
||||
// the one we're aware of.
|
||||
match self.last_commit {
|
||||
None => Consider::Accept,
|
||||
Some(ref num) =>
|
||||
Some(ref num) => {
|
||||
if num < &number {
|
||||
Consider::Accept
|
||||
} else {
|
||||
Consider::RejectPast
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -549,17 +550,17 @@ impl<N: Ord> Peers<N> {
|
||||
) -> Result<Option<&View<N>>, Misbehavior> {
|
||||
let Some(peer) = self.inner.get_mut(who) else { return Ok(None) };
|
||||
|
||||
let invalid_change = peer.view.set_id > update.set_id ||
|
||||
peer.view.round > update.round && peer.view.set_id == update.set_id ||
|
||||
peer.view.last_commit.as_ref() > Some(&update.commit_finalized_height);
|
||||
let invalid_change = peer.view.set_id > update.set_id
|
||||
|| peer.view.round > update.round && peer.view.set_id == update.set_id
|
||||
|| peer.view.last_commit.as_ref() > Some(&update.commit_finalized_height);
|
||||
|
||||
if invalid_change {
|
||||
return Err(Misbehavior::InvalidViewChange);
|
||||
}
|
||||
|
||||
let now = Instant::now();
|
||||
let duplicate_packet = (update.set_id, update.round, Some(&update.commit_finalized_height)) ==
|
||||
(peer.view.set_id, peer.view.round, peer.view.last_commit.as_ref());
|
||||
let duplicate_packet = (update.set_id, update.round, Some(&update.commit_finalized_height))
|
||||
== (peer.view.set_id, peer.view.round, peer.view.last_commit.as_ref());
|
||||
|
||||
if duplicate_packet {
|
||||
if let Some(last_update) = peer.view.last_update {
|
||||
@@ -820,8 +821,8 @@ impl<Block: BlockT> Inner<Block> {
|
||||
ref mut x @ None => x.get_or_insert(LocalView::new(set_id, Round(1))),
|
||||
Some(ref mut v) => {
|
||||
if v.set_id == set_id {
|
||||
let diff_authorities = self.authorities.iter().collect::<HashSet<_>>() !=
|
||||
authorities.iter().collect::<HashSet<_>>();
|
||||
let diff_authorities = self.authorities.iter().collect::<HashSet<_>>()
|
||||
!= authorities.iter().collect::<HashSet<_>>();
|
||||
|
||||
if diff_authorities {
|
||||
debug!(
|
||||
@@ -902,10 +903,12 @@ impl<Block: BlockT> Inner<Block> {
|
||||
) -> Action<Block::Hash> {
|
||||
match self.consider_vote(full.round, full.set_id) {
|
||||
Consider::RejectFuture => return Action::Discard(Misbehavior::FutureMessage.cost()),
|
||||
Consider::RejectOutOfScope =>
|
||||
return Action::Discard(Misbehavior::OutOfScopeMessage.cost()),
|
||||
Consider::RejectPast =>
|
||||
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id)),
|
||||
Consider::RejectOutOfScope => {
|
||||
return Action::Discard(Misbehavior::OutOfScopeMessage.cost())
|
||||
},
|
||||
Consider::RejectPast => {
|
||||
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id))
|
||||
},
|
||||
Consider::Accept => {},
|
||||
}
|
||||
|
||||
@@ -955,15 +958,17 @@ impl<Block: BlockT> Inner<Block> {
|
||||
|
||||
match self.consider_global(full.set_id, full.message.target_number) {
|
||||
Consider::RejectFuture => return Action::Discard(Misbehavior::FutureMessage.cost()),
|
||||
Consider::RejectPast =>
|
||||
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id)),
|
||||
Consider::RejectOutOfScope =>
|
||||
return Action::Discard(Misbehavior::OutOfScopeMessage.cost()),
|
||||
Consider::RejectPast => {
|
||||
return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id))
|
||||
},
|
||||
Consider::RejectOutOfScope => {
|
||||
return Action::Discard(Misbehavior::OutOfScopeMessage.cost())
|
||||
},
|
||||
Consider::Accept => {},
|
||||
}
|
||||
|
||||
if full.message.precommits.len() != full.message.auth_data.len() ||
|
||||
full.message.precommits.is_empty()
|
||||
if full.message.precommits.len() != full.message.auth_data.len()
|
||||
|| full.message.precommits.is_empty()
|
||||
{
|
||||
debug!(target: LOG_TARGET, "Malformed compact commit");
|
||||
telemetry!(
|
||||
@@ -1046,8 +1051,8 @@ impl<Block: BlockT> Inner<Block> {
|
||||
// race where the peer sent us the request before it observed that
|
||||
// we had transitioned to a new set. In this case we charge a lower
|
||||
// cost.
|
||||
if request.set_id.0.saturating_add(1) == local_view.set_id.0 &&
|
||||
local_view.round.0.saturating_sub(CATCH_UP_THRESHOLD) == 0
|
||||
if request.set_id.0.saturating_add(1) == local_view.set_id.0
|
||||
&& local_view.round.0.saturating_sub(CATCH_UP_THRESHOLD) == 0
|
||||
{
|
||||
return (None, Action::Discard(cost::HONEST_OUT_OF_SCOPE_CATCH_UP));
|
||||
}
|
||||
@@ -1057,8 +1062,9 @@ impl<Block: BlockT> Inner<Block> {
|
||||
|
||||
match self.peers.peer(who) {
|
||||
None => return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost())),
|
||||
Some(peer) if peer.view.round >= request.round =>
|
||||
return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost())),
|
||||
Some(peer) if peer.view.round >= request.round => {
|
||||
return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost()))
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
@@ -1131,9 +1137,9 @@ impl<Block: BlockT> Inner<Block> {
|
||||
// won't be able to reply since they don't follow the full GRANDPA
|
||||
// protocol and therefore might not have the vote data available.
|
||||
if let (Some(peer), Some(local_view)) = (self.peers.peer(who), &self.local_view) {
|
||||
if self.catch_up_config.request_allowed(peer) &&
|
||||
peer.view.set_id == local_view.set_id &&
|
||||
peer.view.round.0.saturating_sub(CATCH_UP_THRESHOLD) > local_view.round.0
|
||||
if self.catch_up_config.request_allowed(peer)
|
||||
&& peer.view.set_id == local_view.set_id
|
||||
&& peer.view.round.0.saturating_sub(CATCH_UP_THRESHOLD) > local_view.round.0
|
||||
{
|
||||
// send catch up request if allowed
|
||||
let round = peer.view.round.0 - 1; // peer.view.round is > 0
|
||||
@@ -1166,8 +1172,9 @@ impl<Block: BlockT> Inner<Block> {
|
||||
let update_res = self.peers.update_peer_state(who, update);
|
||||
|
||||
let (cost_benefit, topics) = match update_res {
|
||||
Ok(view) =>
|
||||
(benefit::NEIGHBOR_MESSAGE, view.map(|view| neighbor_topics::<Block>(view))),
|
||||
Ok(view) => {
|
||||
(benefit::NEIGHBOR_MESSAGE, view.map(|view| neighbor_topics::<Block>(view)))
|
||||
},
|
||||
Err(misbehavior) => (misbehavior.cost(), None),
|
||||
};
|
||||
|
||||
@@ -1249,8 +1256,8 @@ impl<Block: BlockT> Inner<Block> {
|
||||
if round_elapsed < round_duration.mul_f32(PROPAGATION_SOME) {
|
||||
self.peers.first_stage_peers.contains(who)
|
||||
} else if round_elapsed < round_duration.mul_f32(PROPAGATION_ALL) {
|
||||
self.peers.first_stage_peers.contains(who) ||
|
||||
self.peers.second_stage_peers.contains(who)
|
||||
self.peers.first_stage_peers.contains(who)
|
||||
|| self.peers.second_stage_peers.contains(who)
|
||||
} else {
|
||||
self.peers.peer(who).map(|info| !info.roles.is_light()).unwrap_or(false)
|
||||
}
|
||||
@@ -1278,9 +1285,9 @@ impl<Block: BlockT> Inner<Block> {
|
||||
};
|
||||
|
||||
if round_elapsed < round_duration.mul_f32(PROPAGATION_ALL) {
|
||||
self.peers.first_stage_peers.contains(who) ||
|
||||
self.peers.second_stage_peers.contains(who) ||
|
||||
self.peers.lucky_light_peers.contains(who)
|
||||
self.peers.first_stage_peers.contains(who)
|
||||
|| self.peers.second_stage_peers.contains(who)
|
||||
|| self.peers.lucky_light_peers.contains(who)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
@@ -1611,9 +1618,9 @@ impl<Block: BlockT> pezsc_network_gossip::Validator<Block> for GossipValidator<B
|
||||
// set the peer is in and if the commit is better than the
|
||||
// last received by peer, additionally we make sure to only
|
||||
// broadcast our best commit.
|
||||
peer.view.consider_global(set_id, full.message.target_number) ==
|
||||
Consider::Accept && Some(&full.message.target_number) ==
|
||||
local_view.last_commit_height()
|
||||
peer.view.consider_global(set_id, full.message.target_number)
|
||||
== Consider::Accept
|
||||
&& Some(&full.message.target_number) == local_view.last_commit_height()
|
||||
},
|
||||
Ok(GossipMessage::Neighbor(_)) => false,
|
||||
Ok(GossipMessage::CatchUpRequest(_)) => false,
|
||||
@@ -1646,8 +1653,11 @@ impl<Block: BlockT> pezsc_network_gossip::Validator<Block> for GossipValidator<B
|
||||
Some((number, round, set_id)) =>
|
||||
// we expire any commit message that doesn't target the same block
|
||||
// as our best commit or isn't from the same round and set id
|
||||
!(full.message.target_number == number &&
|
||||
full.round == round && full.set_id == set_id),
|
||||
{
|
||||
!(full.message.target_number == number
|
||||
&& full.round == round
|
||||
&& full.set_id == set_id)
|
||||
},
|
||||
None => true,
|
||||
},
|
||||
Ok(_) => true,
|
||||
@@ -2323,8 +2333,8 @@ mod tests {
|
||||
|
||||
let test = |rounds_elapsed, peers| {
|
||||
// rewind n round durations
|
||||
val.inner.write().local_view.as_mut().unwrap().round_start = Instant::now() -
|
||||
Duration::from_millis(
|
||||
val.inner.write().local_view.as_mut().unwrap().round_start = Instant::now()
|
||||
- Duration::from_millis(
|
||||
(round_duration.as_millis() as f32 * rounds_elapsed) as u64,
|
||||
);
|
||||
|
||||
|
||||
@@ -505,10 +505,11 @@ impl<B: BlockT, N: Network<B>, S: Syncing<B>> Future for NetworkBridge<B, N, S>
|
||||
Poll::Ready(Some((to, packet))) => {
|
||||
self.gossip_engine.lock().send_message(to, packet.encode());
|
||||
},
|
||||
Poll::Ready(None) =>
|
||||
Poll::Ready(None) => {
|
||||
return Poll::Ready(Err(Error::Network(
|
||||
"Neighbor packet worker stream closed.".into(),
|
||||
))),
|
||||
)))
|
||||
},
|
||||
Poll::Pending => break,
|
||||
}
|
||||
}
|
||||
@@ -518,17 +519,19 @@ impl<B: BlockT, N: Network<B>, S: Syncing<B>> Future for NetworkBridge<B, N, S>
|
||||
Poll::Ready(Some(PeerReport { who, cost_benefit })) => {
|
||||
self.gossip_engine.lock().report(who, cost_benefit);
|
||||
},
|
||||
Poll::Ready(None) =>
|
||||
Poll::Ready(None) => {
|
||||
return Poll::Ready(Err(Error::Network(
|
||||
"Gossip validator report stream closed.".into(),
|
||||
))),
|
||||
)))
|
||||
},
|
||||
Poll::Pending => break,
|
||||
}
|
||||
}
|
||||
|
||||
match self.gossip_engine.lock().poll_unpin(cx) {
|
||||
Poll::Ready(()) =>
|
||||
return Poll::Ready(Err(Error::Network("Gossip engine future finished.".into()))),
|
||||
Poll::Ready(()) => {
|
||||
return Poll::Ready(Err(Error::Network("Gossip engine future finished.".into())))
|
||||
},
|
||||
Poll::Pending => {},
|
||||
}
|
||||
|
||||
@@ -666,10 +669,12 @@ fn incoming_global<B: BlockT>(
|
||||
})
|
||||
.filter_map(move |(notification, msg)| {
|
||||
future::ready(match msg {
|
||||
GossipMessage::Commit(msg) =>
|
||||
process_commit(msg, notification, &gossip_engine, &gossip_validator, &voters),
|
||||
GossipMessage::CatchUp(msg) =>
|
||||
process_catch_up(msg, notification, &gossip_engine, &gossip_validator, &voters),
|
||||
GossipMessage::Commit(msg) => {
|
||||
process_commit(msg, notification, &gossip_engine, &gossip_validator, &voters)
|
||||
},
|
||||
GossipMessage::CatchUp(msg) => {
|
||||
process_catch_up(msg, notification, &gossip_engine, &gossip_validator, &voters)
|
||||
},
|
||||
_ => {
|
||||
debug!(target: LOG_TARGET, "Skipping unknown message type");
|
||||
None
|
||||
|
||||
@@ -270,10 +270,11 @@ impl Tester {
|
||||
futures::future::poll_fn(move |cx| loop {
|
||||
match Stream::poll_next(Pin::new(&mut s.as_mut().unwrap().events), cx) {
|
||||
Poll::Ready(None) => panic!("concluded early"),
|
||||
Poll::Ready(Some(item)) =>
|
||||
Poll::Ready(Some(item)) => {
|
||||
if pred(item) {
|
||||
return Poll::Ready(s.take().unwrap());
|
||||
},
|
||||
}
|
||||
},
|
||||
Poll::Pending => return Poll::Pending,
|
||||
}
|
||||
})
|
||||
@@ -622,8 +623,9 @@ fn bad_commit_leads_to_report() {
|
||||
let fut = future::join(send_message, handle_commit)
|
||||
.then(move |(tester, ())| {
|
||||
tester.filter_network_events(move |event| match event {
|
||||
Event::Report(who, cost_benefit) =>
|
||||
who == id && cost_benefit == super::cost::INVALID_COMMIT,
|
||||
Event::Report(who, cost_benefit) => {
|
||||
who == id && cost_benefit == super::cost::INVALID_COMMIT
|
||||
},
|
||||
_ => false,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -277,8 +277,8 @@ impl<Header: HeaderT> HasVoted<Header> {
|
||||
pub fn propose(&self) -> Option<&PrimaryPropose<Header>> {
|
||||
match self {
|
||||
HasVoted::Yes(_, Vote::Propose(propose)) => Some(propose),
|
||||
HasVoted::Yes(_, Vote::Prevote(propose, _)) |
|
||||
HasVoted::Yes(_, Vote::Precommit(propose, _, _)) => propose.as_ref(),
|
||||
HasVoted::Yes(_, Vote::Prevote(propose, _))
|
||||
| HasVoted::Yes(_, Vote::Precommit(propose, _, _)) => propose.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -286,8 +286,8 @@ impl<Header: HeaderT> HasVoted<Header> {
|
||||
/// Returns the prevote we should vote with (if any.)
|
||||
pub fn prevote(&self) -> Option<&Prevote<Header>> {
|
||||
match self {
|
||||
HasVoted::Yes(_, Vote::Prevote(_, prevote)) |
|
||||
HasVoted::Yes(_, Vote::Precommit(_, prevote, _)) => Some(prevote),
|
||||
HasVoted::Yes(_, Vote::Prevote(_, prevote))
|
||||
| HasVoted::Yes(_, Vote::Precommit(_, prevote, _)) => Some(prevote),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -528,8 +528,9 @@ where
|
||||
|
||||
// find the hash of the latest block in the current set
|
||||
let current_set_latest_hash = match next_change {
|
||||
Some((_, n)) if n.is_zero() =>
|
||||
return Err(Error::Safety("Authority set change signalled at genesis.".to_string())),
|
||||
Some((_, n)) if n.is_zero() => {
|
||||
return Err(Error::Safety("Authority set change signalled at genesis.".to_string()))
|
||||
},
|
||||
// the next set starts at `n` so the current one lasts until `n - 1`. if
|
||||
// `n` is later than the best block, then the current set is still live
|
||||
// at best block.
|
||||
@@ -733,12 +734,13 @@ where
|
||||
let local_id = local_authority_id(&self.voters, self.config.keystore.as_ref());
|
||||
|
||||
let has_voted = match self.voter_set_state.has_voted(round) {
|
||||
HasVoted::Yes(id, vote) =>
|
||||
HasVoted::Yes(id, vote) => {
|
||||
if local_id.as_ref().map(|k| k == &id).unwrap_or(false) {
|
||||
HasVoted::Yes(id, vote)
|
||||
} else {
|
||||
HasVoted::No
|
||||
},
|
||||
}
|
||||
},
|
||||
HasVoted::No => HasVoted::No,
|
||||
};
|
||||
|
||||
@@ -1253,10 +1255,10 @@ where
|
||||
|
||||
let is_descendent_of = is_descendent_of(&*client, None);
|
||||
|
||||
if target_header.number() > best_header.number() ||
|
||||
target_header.number() == best_header.number() &&
|
||||
target_header.hash() != best_header.hash() ||
|
||||
!is_descendent_of(&target_header.hash(), &best_header.hash())?
|
||||
if target_header.number() > best_header.number()
|
||||
|| target_header.number() == best_header.number()
|
||||
&& target_header.hash() != best_header.hash()
|
||||
|| !is_descendent_of(&target_header.hash(), &best_header.hash())?
|
||||
{
|
||||
debug!(
|
||||
target: LOG_TARGET,
|
||||
|
||||
@@ -111,9 +111,9 @@ where
|
||||
self.authority_set.inner().pending_changes().cloned().collect();
|
||||
|
||||
for pending_change in pending_changes {
|
||||
if pending_change.delay_kind == DelayKind::Finalized &&
|
||||
pending_change.effective_number() > chain_info.finalized_number &&
|
||||
pending_change.effective_number() <= chain_info.best_number
|
||||
if pending_change.delay_kind == DelayKind::Finalized
|
||||
&& pending_change.effective_number() > chain_info.finalized_number
|
||||
&& pending_change.effective_number() <= chain_info.best_number
|
||||
{
|
||||
let effective_block_hash = if !pending_change.delay.is_zero() {
|
||||
self.select_chain
|
||||
@@ -685,7 +685,7 @@ where
|
||||
);
|
||||
}
|
||||
},
|
||||
None =>
|
||||
None => {
|
||||
if needs_justification {
|
||||
debug!(
|
||||
target: LOG_TARGET,
|
||||
@@ -694,7 +694,8 @@ where
|
||||
);
|
||||
|
||||
imported_aux.needs_justification = true;
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Ok(ImportResult::Imported(imported_aux))
|
||||
@@ -799,8 +800,9 @@ where
|
||||
let justification = match justification {
|
||||
Err(e) => {
|
||||
return match e {
|
||||
pezsp_blockchain::Error::OutdatedJustification =>
|
||||
Err(ConsensusError::OutdatedJustification),
|
||||
pezsp_blockchain::Error::OutdatedJustification => {
|
||||
Err(ConsensusError::OutdatedJustification)
|
||||
},
|
||||
_ => Err(ConsensusError::ClientImport(e.to_string())),
|
||||
};
|
||||
},
|
||||
@@ -832,7 +834,7 @@ where
|
||||
// send the command to the voter
|
||||
let _ = self.send_voter_commands.unbounded_send(command);
|
||||
},
|
||||
Err(CommandOrError::Error(e)) =>
|
||||
Err(CommandOrError::Error(e)) => {
|
||||
return Err(match e {
|
||||
Error::Grandpa(error) => ConsensusError::ClientImport(error.to_string()),
|
||||
Error::Network(error) => ConsensusError::ClientImport(error),
|
||||
@@ -842,7 +844,8 @@ where
|
||||
Error::Signing(error) => ConsensusError::ClientImport(error),
|
||||
Error::Timer(error) => ConsensusError::ClientImport(error.to_string()),
|
||||
Error::RuntimeApi(error) => ConsensusError::ClientImport(error.to_string()),
|
||||
}),
|
||||
})
|
||||
},
|
||||
Ok(_) => {
|
||||
assert!(
|
||||
!enacts_change,
|
||||
|
||||
@@ -214,12 +214,14 @@ impl<Block: BlockT> GrandpaJustification<Block> {
|
||||
&mut buf,
|
||||
);
|
||||
match signature_result {
|
||||
pezsp_consensus_grandpa::SignatureResult::Invalid =>
|
||||
pezsp_consensus_grandpa::SignatureResult::Invalid => {
|
||||
return Err(ClientError::BadJustification(
|
||||
"invalid signature for precommit in grandpa justification".to_string(),
|
||||
)),
|
||||
pezsp_consensus_grandpa::SignatureResult::OutdatedSet =>
|
||||
return Err(ClientError::OutdatedJustification),
|
||||
))
|
||||
},
|
||||
pezsp_consensus_grandpa::SignatureResult::OutdatedSet => {
|
||||
return Err(ClientError::OutdatedJustification)
|
||||
},
|
||||
pezsp_consensus_grandpa::SignatureResult::Valid => {},
|
||||
}
|
||||
|
||||
@@ -236,10 +238,11 @@ impl<Block: BlockT> GrandpaJustification<Block> {
|
||||
visited_hashes.insert(hash);
|
||||
}
|
||||
},
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(ClientError::BadJustification(
|
||||
"invalid precommit ancestry proof in grandpa justification".to_string(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1231,8 +1231,8 @@ async fn voter_persists_its_votes() {
|
||||
Pin::new(&mut *round_tx.lock())
|
||||
.start_send(finality_grandpa::Message::Prevote(prevote))
|
||||
.unwrap();
|
||||
} else if state.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap() ==
|
||||
1
|
||||
} else if state.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap()
|
||||
== 1
|
||||
{
|
||||
// the next message we receive should be our own prevote
|
||||
let prevote = match signed.message {
|
||||
@@ -1246,8 +1246,8 @@ async fn voter_persists_its_votes() {
|
||||
// after alice restarts it should send its previous prevote
|
||||
// therefore we won't ever receive it again since it will be a
|
||||
// known message on the gossip layer
|
||||
} else if state.compare_exchange(2, 3, Ordering::SeqCst, Ordering::SeqCst).unwrap() ==
|
||||
2
|
||||
} else if state.compare_exchange(2, 3, Ordering::SeqCst, Ordering::SeqCst).unwrap()
|
||||
== 2
|
||||
{
|
||||
// we then receive a precommit from alice for block 15
|
||||
// even though we casted a prevote for block 30
|
||||
|
||||
@@ -940,8 +940,8 @@ mod tests {
|
||||
let block_sync_requests = block_sync_requester.requests.lock();
|
||||
|
||||
// we request blocks targeted by the precommits that aren't imported
|
||||
if block_sync_requests.contains(&(h2.hash(), *h2.number())) &&
|
||||
block_sync_requests.contains(&(h3.hash(), *h3.number()))
|
||||
if block_sync_requests.contains(&(h2.hash(), *h2.number()))
|
||||
&& block_sync_requests.contains(&(h3.hash(), *h3.number()))
|
||||
{
|
||||
return Poll::Ready(());
|
||||
}
|
||||
|
||||
@@ -236,8 +236,8 @@ where
|
||||
.await
|
||||
.filter(|(_, restricted_number)| {
|
||||
// NOTE: we can only restrict votes within the interval [base, target)
|
||||
restricted_number >= base.number() &&
|
||||
restricted_number < restricted_target.number()
|
||||
restricted_number >= base.number()
|
||||
&& restricted_number < restricted_target.number()
|
||||
})
|
||||
.and_then(|(hash, _)| backend.header(hash).ok())
|
||||
.and_then(std::convert::identity)
|
||||
|
||||
@@ -297,14 +297,15 @@ where
|
||||
|
||||
// manually hard code epoch descriptor
|
||||
epoch_descriptor = match epoch_descriptor {
|
||||
ViableEpochDescriptor::Signaled(identifier, _header) =>
|
||||
ViableEpochDescriptor::Signaled(identifier, _header) => {
|
||||
ViableEpochDescriptor::Signaled(
|
||||
identifier,
|
||||
EpochHeader {
|
||||
start_slot: slot,
|
||||
end_slot: (*slot * self.config.epoch_length).into(),
|
||||
},
|
||||
),
|
||||
)
|
||||
},
|
||||
_ => unreachable!(
|
||||
"we're not in the authorities, so this isn't the genesis epoch; qed"
|
||||
),
|
||||
|
||||
@@ -96,8 +96,9 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
|
||||
// use the parent_hash supplied via `EngineCommand`
|
||||
// or fetch the best_block.
|
||||
let parent = match parent_hash {
|
||||
Some(hash) =>
|
||||
client.header(hash)?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))?,
|
||||
Some(hash) => {
|
||||
client.header(hash)?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))?
|
||||
},
|
||||
None => select_chain.best_chain().await?,
|
||||
};
|
||||
|
||||
|
||||
@@ -285,8 +285,9 @@ where
|
||||
CheckInherentsError::CreateInherentData(e) => Error::CreateInherents(e),
|
||||
CheckInherentsError::Client(e) => Error::Client(e.into()),
|
||||
CheckInherentsError::CheckInherents(e) => Error::CheckInherents(e),
|
||||
CheckInherentsError::CheckInherentsUnknownError(id) =>
|
||||
Error::CheckInherentsUnknownError(id),
|
||||
CheckInherentsError::CheckInherentsUnknownError(id) => {
|
||||
Error::CheckInherentsUnknownError(id)
|
||||
},
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
@@ -409,12 +410,13 @@ impl<B: BlockT, Algorithm> PowVerifier<B, Algorithm> {
|
||||
let hash = header.hash();
|
||||
|
||||
let (seal, inner_seal) = match header.digest_mut().pop() {
|
||||
Some(DigestItem::Seal(id, seal)) =>
|
||||
Some(DigestItem::Seal(id, seal)) => {
|
||||
if id == POW_ENGINE_ID {
|
||||
(DigestItem::Seal(id, seal.clone()), seal)
|
||||
} else {
|
||||
return Err(Error::WrongEngine(id));
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => return Err(Error::HeaderUnsealed(hash)),
|
||||
};
|
||||
|
||||
@@ -646,8 +648,9 @@ fn find_pre_digest<B: BlockT>(header: &B::Header) -> Result<Option<Vec<u8>>, Err
|
||||
for log in header.digest().logs() {
|
||||
trace!(target: LOG_TARGET, "Checking log {:?}, looking for pre runtime digest", log);
|
||||
match (log, pre_digest.is_some()) {
|
||||
(DigestItem::PreRuntime(POW_ENGINE_ID, _), true) =>
|
||||
return Err(Error::MultiplePreRuntimeDigests),
|
||||
(DigestItem::PreRuntime(POW_ENGINE_ID, _), true) => {
|
||||
return Err(Error::MultiplePreRuntimeDigests)
|
||||
},
|
||||
(DigestItem::PreRuntime(POW_ENGINE_ID, v), false) => {
|
||||
pre_digest = Some(v.clone());
|
||||
},
|
||||
@@ -661,12 +664,13 @@ fn find_pre_digest<B: BlockT>(header: &B::Header) -> Result<Option<Vec<u8>>, Err
|
||||
/// Fetch PoW seal.
|
||||
fn fetch_seal<B: BlockT>(digest: Option<&DigestItem>, hash: B::Hash) -> Result<Vec<u8>, Error<B>> {
|
||||
match digest {
|
||||
Some(DigestItem::Seal(id, seal)) =>
|
||||
Some(DigestItem::Seal(id, seal)) => {
|
||||
if id == &POW_ENGINE_ID {
|
||||
Ok(seal.clone())
|
||||
} else {
|
||||
Err(Error::<B>::WrongEngine(*id))
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => Err(Error::<B>::HeaderUnsealed(hash)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,9 +335,9 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
|
||||
let authorities_len = self.authorities_len(&aux_data);
|
||||
|
||||
if !self.force_authoring() &&
|
||||
self.sync_oracle().is_offline() &&
|
||||
authorities_len.map(|a| a > 1).unwrap_or(false)
|
||||
if !self.force_authoring()
|
||||
&& self.sync_oracle().is_offline()
|
||||
&& authorities_len.map(|a| a > 1).unwrap_or(false)
|
||||
{
|
||||
debug!(target: logging_target, "Skipping proposal slot. Waiting for the network.");
|
||||
telemetry!(
|
||||
|
||||
Reference in New Issue
Block a user