mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 00:57:57 +00:00
fix block body fetch for availability pruning (#539)
This commit is contained in:
committed by
Gav Wood
parent
a330f2e058
commit
c2b20fe5b0
@@ -103,7 +103,8 @@ 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,
|
||||
}
|
||||
@@ -111,29 +112,34 @@ fn prune_unneeded_availability<C>(client: Arc<C>, extrinsic_store: ExtrinsicStor
|
||||
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(¬ification.hash)
|
||||
Err(e) => e.log(&hash)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user