Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit story around unknown digest log items #2481

Merged
merged 10 commits into from
Jul 8, 2022
6 changes: 3 additions & 3 deletions bin/full-node/src/run/consensus_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ impl SyncBackground {
chain_information::ChainInformationConsensusRef::Babe { .. } => {
Some(keystore::KeyNamespace::Babe)
}
chain_information::ChainInformationConsensusRef::AllAuthorized => {
// In `AllAuthorized` mode, all keys are accepted and there is no
// filter on the namespace.
chain_information::ChainInformationConsensusRef::Unknown => {
// In `Unknown` mode, all keys are accepted and there is no
// filter on the namespace, as we can't author blocks anyway.
// TODO: is that correct?
None
}
Expand Down
2 changes: 2 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Changed

- Block headers with an unknown consensus engine now parse successfully. This adds support for parachains using consensus engines that smoldot doesn't recognized. As smoldot cannot verify the validity of blocks with an unrecognized consensus engine, standalone/relay chains using headers with an unrecognized consensus engine remain unsupported. ([#2481](https://github.com/paritytech/smoldot/pull/2481))
- Standalone/relay chains that use neither Aura nor Babe are no longer supported. Parachains that don't use Aura continue to work. ([#2481](https://github.com/paritytech/smoldot/pull/2481))
- No warning is generated anymore if the discovery process doesn't work due to having 0 peers, or failed due to a benign networking issue. ([#2476](https://github.com/paritytech/smoldot/pull/2476))

### Fixed
Expand Down
15 changes: 7 additions & 8 deletions src/chain/blocks_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl<T> NonFinalizedTree<T> {
},
},
finalized_consensus: match chain_information.consensus {
chain_information::ChainInformationConsensus::AllAuthorized => {
FinalizedConsensus::AllAuthorized
chain_information::ChainInformationConsensus::Unknown => {
FinalizedConsensus::Unknown
}
chain_information::ChainInformationConsensus::Aura {
finalized_authorities_list,
Expand Down Expand Up @@ -220,8 +220,8 @@ impl<T> NonFinalizedTree<T> {
let attempt = chain_information::ChainInformationRef {
finalized_block_header: (&inner.finalized_block_header).into(),
consensus: match &inner.finalized_consensus {
FinalizedConsensus::AllAuthorized => {
chain_information::ChainInformationConsensusRef::AllAuthorized
FinalizedConsensus::Unknown => {
chain_information::ChainInformationConsensusRef::Unknown
}
FinalizedConsensus::Aura {
authorities_list,
Expand Down Expand Up @@ -303,8 +303,8 @@ impl<T> NonFinalizedTree<T> {
.current_best
.map(|idx| &inner.blocks.get(idx).unwrap().consensus),
) {
(FinalizedConsensus::AllAuthorized, _) => {
chain_information::ChainInformationConsensusRef::AllAuthorized
(FinalizedConsensus::Unknown, _) => {
chain_information::ChainInformationConsensusRef::Unknown
}
(
FinalizedConsensus::Aura {
Expand Down Expand Up @@ -446,7 +446,7 @@ struct NonFinalizedTreeInner<T> {
/// State of the consensus of the finalized block.
#[derive(Clone)]
enum FinalizedConsensus {
AllAuthorized,
Unknown,
Aura {
/// List of authorities that must sign the child of the finalized block.
authorities_list: Arc<Vec<header::AuraAuthority>>,
Expand Down Expand Up @@ -498,7 +498,6 @@ struct Block<T> {
/// Changes to the consensus made by a block.
#[derive(Clone)]
enum BlockConsensus {
AllAuthorized,
Aura {
/// If `Some`, list of authorities that must verify the child of this block.
/// This can be a clone of the value of the parent, a clone of
Expand Down
35 changes: 19 additions & 16 deletions src/chain/blocks_tree/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ impl<T> NonFinalizedTreeInner<T> {
// information is found either in the parent block, or in the finalized block.
let consensus = if let Some(parent_tree_index) = parent_tree_index {
match &self.blocks.get(parent_tree_index).unwrap().consensus {
BlockConsensus::AllAuthorized => VerifyConsensusSpecific::AllAuthorized,
BlockConsensus::Aura { authorities_list } => VerifyConsensusSpecific::Aura {
authorities_list: authorities_list.clone(),
},
Expand All @@ -191,7 +190,7 @@ impl<T> NonFinalizedTreeInner<T> {
}
} else {
match &self.finalized_consensus {
FinalizedConsensus::AllAuthorized => VerifyConsensusSpecific::AllAuthorized,
FinalizedConsensus::Unknown => VerifyConsensusSpecific::Unknown,
FinalizedConsensus::Aura {
authorities_list, ..
} => VerifyConsensusSpecific::Aura {
Expand Down Expand Up @@ -255,8 +254,11 @@ impl<T> NonFinalizedTreeInner<T> {
slots_per_epoch: *slots_per_epoch,
now_from_unix_epoch,
},
(FinalizedConsensus::AllAuthorized, VerifyConsensusSpecific::AllAuthorized) => {
verify::header_only::ConfigConsensus::AllAuthorized
(FinalizedConsensus::Unknown, VerifyConsensusSpecific::Unknown) => {
return VerifyOut::HeaderErr(
context.chain,
HeaderVerifyError::UnknownConsensusEngine,
)
}
_ => {
return VerifyOut::HeaderErr(
Expand Down Expand Up @@ -301,9 +303,6 @@ impl<T> VerifyContext<T> {
success_consensus: verify::header_only::Success,
) -> (bool, BlockConsensus) {
let success_consensus = match success_consensus {
verify::header_only::Success::AllAuthorized => {
verify::header_body::SuccessConsensus::AllAuthorized
}
verify::header_only::Success::Aura { authorities_change } => {
verify::header_body::SuccessConsensus::Aura { authorities_change }
}
Expand Down Expand Up @@ -341,12 +340,6 @@ impl<T> VerifyContext<T> {
self.parent_tree_index
.map(|idx| self.chain.blocks.get(idx).unwrap().consensus.clone()),
) {
(
verify::header_body::SuccessConsensus::AllAuthorized,
VerifyConsensusSpecific::AllAuthorized,
FinalizedConsensus::AllAuthorized,
_,
) => BlockConsensus::AllAuthorized,
(
verify::header_body::SuccessConsensus::Aura { authorities_change },
VerifyConsensusSpecific::Aura {
Expand Down Expand Up @@ -568,7 +561,7 @@ pub enum BodyVerifyStep1<T> {

#[derive(Debug)]
enum VerifyConsensusSpecific {
AllAuthorized,
Unknown,
Aura {
authorities_list: Arc<Vec<header::AuraAuthority>>,
},
Expand Down Expand Up @@ -665,8 +658,14 @@ impl<T> BodyVerifyRuntimeRequired<T> {
&self.context.chain.finalized_consensus,
&self.context.consensus,
) {
(FinalizedConsensus::AllAuthorized, VerifyConsensusSpecific::AllAuthorized) => {
verify::header_body::ConfigConsensus::AllAuthorized
(FinalizedConsensus::Unknown, VerifyConsensusSpecific::Unknown) => {
return BodyVerifyStep2::Error {
chain: NonFinalizedTree {
inner: Some(self.context.chain),
},
error: BodyVerifyError::UnknownConsensusEngine,
parent_runtime,
}
}
(
FinalizedConsensus::Aura { slot_duration, .. },
Expand Down Expand Up @@ -780,6 +779,8 @@ pub enum BodyVerifyError {
/// Error during the consensus-related check.
#[display(fmt = "{}", _0)]
Consensus(verify::header_body::Error),
/// Block can't be verified as it uses an unknown consensus engine.
UnknownConsensusEngine,
/// Block uses a different consensus than the rest of the chain.
ConsensusMismatch,
}
Expand Down Expand Up @@ -1086,6 +1087,8 @@ pub enum HeaderVerifyError {
/// Error while decoding the header.
#[display(fmt = "Error while decoding the header: {}", _0)]
InvalidHeader(header::Error),
/// Block can't be verified as it uses an unknown consensus engine.
UnknownConsensusEngine,
/// Block uses a different consensus than the rest of the chain.
ConsensusMismatch,
/// The parent of the block isn't known.
Expand Down
14 changes: 5 additions & 9 deletions src/chain/chain_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ impl<'a> From<ChainInformationRef<'a>> for ChainInformation {
ChainInformation {
finalized_block_header: info.finalized_block_header.into(),
consensus: match info.consensus {
ChainInformationConsensusRef::AllAuthorized => {
ChainInformationConsensus::AllAuthorized
}
ChainInformationConsensusRef::Unknown => ChainInformationConsensus::Unknown,
ChainInformationConsensusRef::Aura {
finalized_authorities_list,
slot_duration,
Expand Down Expand Up @@ -172,7 +170,7 @@ pub enum ChainInformationConsensus {
/// > **Note**: Be warned that this variant makes it possible for a huge number of blocks to
/// > be produced. If this variant is used, the user is encouraged to limit, through
/// > other means, the number of blocks being accepted.
AllAuthorized,
Unknown,

/// Chain is using the Aura consensus engine.
Aura {
Expand Down Expand Up @@ -426,9 +424,7 @@ impl<'a> From<&'a ChainInformation> for ChainInformationRef<'a> {
ChainInformationRef {
finalized_block_header: (&info.finalized_block_header).into(),
consensus: match &info.consensus {
ChainInformationConsensus::AllAuthorized => {
ChainInformationConsensusRef::AllAuthorized
}
ChainInformationConsensus::Unknown => ChainInformationConsensusRef::Unknown,
ChainInformationConsensus::Aura {
finalized_authorities_list,
slot_duration,
Expand Down Expand Up @@ -458,8 +454,8 @@ impl<'a> From<&'a ChainInformation> for ChainInformationRef<'a> {
/// Extra items that depend on the consensus engine.
#[derive(Debug, Clone)]
pub enum ChainInformationConsensusRef<'a> {
/// See [`ChainInformationConsensus::AllAuthorized`].
AllAuthorized,
/// See [`ChainInformationConsensus::Unknown`].
Unknown,

/// Chain is using the Aura consensus engine.
Aura {
Expand Down
3 changes: 1 addition & 2 deletions src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ impl ChainSpec {
(Err(err1), Err(err2))
if err1.is_function_not_found() && err2.is_function_not_found() =>
{
// TODO: seems a bit risky to automatically fall back to this?
ChainInformationConsensus::AllAuthorized
ChainInformationConsensus::Unknown
}
(Err(error), _) => {
// Note that Babe might have produced an error as well, which is intentionally
Expand Down
2 changes: 1 addition & 1 deletion src/database/full_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl SqliteFullDatabase {
slot_duration,
}
}
(None, None, None) => chain_information::ChainInformationConsensus::AllAuthorized,
(None, None, None) => chain_information::ChainInformationConsensus::Unknown,
_ => {
return Err(FinalizedAccessError::Access(AccessError::Corrupted(
CorruptedError::ConsensusAlgorithmMix,
Expand Down
2 changes: 1 addition & 1 deletion src/database/full_sqlite/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl DatabaseEmpty {
}

match &chain_information.consensus {
chain_information::ChainInformationConsensusRef::AllAuthorized => {}
chain_information::ChainInformationConsensusRef::Unknown => {}
chain_information::ChainInformationConsensusRef::Aura {
finalized_authorities_list,
slot_duration,
Expand Down
Loading