Skip to content

Commit

Permalink
Merge pull request #2947 from autonomys/fix-receipt-gap-check
Browse files Browse the repository at this point in the history
Fix an edge case when checking the receipt's domain block number in `block-preprocessor`
  • Loading branch information
NingLin-P committed Jul 29, 2024
2 parents 0a89bdb + 2c45278 commit 5438c64
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
4 changes: 3 additions & 1 deletion crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,9 @@ impl<T: Config> Pallet<T> {
| BundleError::SlotInThePast
| BundleError::SlotInTheFuture
| BundleError::InvalidProofOfTime
| BundleError::SlotSmallerThanPreviousBlockBundle => {
| BundleError::SlotSmallerThanPreviousBlockBundle
| BundleError::ExpectingReceiptGap
| BundleError::UnexpectedReceiptGap => {
log::debug!(
target: "runtime::domains",
"Bad bundle/receipt, domain {domain_id:?}, operator {operator_id:?}, error: {err:?}",
Expand Down
44 changes: 34 additions & 10 deletions domains/client/block-preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use sp_domains::{
};
use sp_messenger::MessengerApi;
use sp_mmr_primitives::MmrApi;
use sp_runtime::traits::{Block as BlockT, Hash as HashT, NumberFor};
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header, NumberFor};
use sp_runtime::DigestItem;
use sp_state_machine::LayoutV1;
use sp_subspace_mmr::ConsensusChainMmrLeafProof;
use sp_weights::Weight;
Expand Down Expand Up @@ -235,15 +236,38 @@ where
if consensus_spec_version >= 6
&& bundle.receipt().domain_block_number != parent_domain_number
{
return Err(sp_blockchain::Error::RuntimeApiError(
ApiError::Application(
format!(
"Unexpected bundle in consensus block: {:?}, something must be wrong",
at_consensus_hash
)
.into(),
),
));
// If there consensus runtime just upgraded to spec version 6, which bring the receipt
// gap check, the bundle that included in the same block is doesn't perform the check
// because the new runtime take effect in the next block so skip the check here too.
let is_consensus_runtime_upgraded_to_6 = {
let consensus_header = self
.consensus_client
.header(at_consensus_hash)?
.ok_or_else(|| {
sp_blockchain::Error::Backend(format!(
"Consensus block header of {at_consensus_hash:?} unavailable"
))
})?;

let runtime_upgraded = consensus_header
.digest()
.logs()
.iter()
.any(|di| di == &DigestItem::RuntimeEnvironmentUpdated);

runtime_upgraded && consensus_spec_version == 6
};
if !is_consensus_runtime_upgraded_to_6 {
return Err(sp_blockchain::Error::RuntimeApiError(
ApiError::Application(
format!(
"Unexpected bundle in consensus block: {:?}, something must be wrong",
at_consensus_hash
)
.into(),
),
));
}
}

let extrinsic_root = bundle.extrinsics_root();
Expand Down

0 comments on commit 5438c64

Please sign in to comment.