Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions polkadot/consensus/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,37 +103,43 @@ fn prune_unneeded_availability<C>(client: Arc<C>, extrinsic_store: ExtrinsicStor
use polkadot_runtime::CheckedBlock;

enum NotifyError {
NoBody(::client::error::Error),
NoBody,
BodyFetch(::client::error::Error),
UnexpectedFormat,
ExtrinsicsWrong,
}

impl NotifyError {
fn log(&self, hash: &::polkadot_primitives::Hash) {
match *self {
NotifyError::NoBody(ref err) => warn!("Failed to fetch block body for imported block {:?}: {:?}", hash, err),
NotifyError::NoBody => warn!("No block body for imported block {:?}", hash),
NotifyError::BodyFetch(ref err) => warn!("Failed to fetch block body for imported block {:?}: {:?}", hash, err),
NotifyError::UnexpectedFormat => warn!("Consensus outdated: Block {:?} has unexpected body format", hash),
NotifyError::ExtrinsicsWrong => warn!("Consensus outdated: Failed to fetch block body for imported block {:?}", hash),
NotifyError::ExtrinsicsWrong => warn!("Consensus outdated: Extrinsics cannot be decoded for {:?}", hash),
}
}
}

client.import_notification_stream()
.for_each(move |notification| {
let checked_block = client.block_body(&BlockId::hash(notification.hash))
.map_err(NotifyError::NoBody)
.map(|b| ::polkadot_runtime::Block::decode(&mut b.encode().as_slice()))
let hash = notification.hash;
let parent_hash = notification.header.parent_hash;
let checked_block = client.block_body(&BlockId::hash(hash))
.map_err(NotifyError::BodyFetch)
.and_then(|maybe_body| maybe_body.ok_or(NotifyError::NoBody))
.map(|extrinsics| Block { header: notification.header, extrinsics })
.map(|b: Block| ::polkadot_runtime::Block::decode(&mut b.encode().as_slice()))
.and_then(|maybe_block| maybe_block.ok_or(NotifyError::UnexpectedFormat))
.and_then(|block| CheckedBlock::new(block).map_err(|_| NotifyError::ExtrinsicsWrong));

match checked_block {
Ok(block) => {
let candidate_hashes = block.parachain_heads().iter().map(|c| c.hash()).collect();
if let Err(e) = extrinsic_store.candidates_finalized(notification.header.parent_hash, candidate_hashes) {
if let Err(e) = extrinsic_store.candidates_finalized(parent_hash, candidate_hashes) {
warn!(target: "consensus", "Failed to prune unneeded available data: {:?}", e);
}
}
Err(e) => e.log(&notification.hash)
Err(e) => e.log(&hash)
}

Ok(())
Expand Down