Skip to content

Commit 5ed52a2

Browse files
committed
update comments, optimisations, and code reverts
1 parent 0391dcb commit 5ed52a2

File tree

6 files changed

+58
-59
lines changed

6 files changed

+58
-59
lines changed

crates/pallet-domains/src/block_tree.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,15 @@ pub(crate) fn process_execution_receipt<T: Config>(
372372
// Collect the paid bundle storage fees and the invalid bundle author
373373
let mut paid_bundle_storage_fees = BTreeMap::new();
374374
let mut invalid_bundle_authors = Vec::new();
375-
let bundle_digests = ExecutionInbox::<T>::get((
376-
domain_id,
377-
to_prune,
378-
execution_receipt.consensus_block_number(),
379-
));
375+
let consensus_block_number = *execution_receipt.consensus_block_number();
376+
let bundle_digests =
377+
ExecutionInbox::<T>::get((domain_id, to_prune, consensus_block_number));
378+
let inboxed_bundles = execution_receipt.inboxed_bundles();
380379
for (index, bd) in bundle_digests.into_iter().enumerate() {
381380
if let Some(bundle_author) = InboxedBundleAuthor::<T>::take(bd.header_hash) {
382381
// It is okay to index `ER::bundles` here since `verify_execution_receipt` have checked
383382
// the `ER::bundles` have the same length of `ExecutionInbox`
384-
if execution_receipt.inboxed_bundles()[index].is_invalid() {
383+
if inboxed_bundles[index].is_invalid() {
385384
invalid_bundle_authors.push(bundle_author);
386385
} else {
387386
paid_bundle_storage_fees
@@ -401,10 +400,7 @@ pub(crate) fn process_execution_receipt<T: Config>(
401400
execution_receipt.clone(),
402401
);
403402

404-
ConsensusBlockHash::<T>::remove(
405-
domain_id,
406-
execution_receipt.consensus_block_number(),
407-
);
403+
ConsensusBlockHash::<T>::remove(domain_id, consensus_block_number);
408404

409405
let block_fees = execution_receipt
410406
.block_fees()
@@ -430,10 +426,7 @@ pub(crate) fn process_execution_receipt<T: Config>(
430426
.map_err(|_| Error::DomainTransfersTracking)?;
431427
}
432428

433-
update_domain_runtime_upgrade_records::<T>(
434-
domain_id,
435-
*execution_receipt.consensus_block_number(),
436-
)?;
429+
update_domain_runtime_upgrade_records::<T>(domain_id, consensus_block_number)?;
437430

438431
// handle chain rewards from the domain
439432
execution_receipt
@@ -445,7 +438,7 @@ pub(crate) fn process_execution_receipt<T: Config>(
445438
});
446439

447440
return Ok(Some(ConfirmedDomainBlockInfo {
448-
consensus_block_number: *execution_receipt.consensus_block_number(),
441+
consensus_block_number,
449442
domain_block_number: to_prune,
450443
operator_ids,
451444
rewards: execution_receipt.block_fees().domain_execution_fee,

crates/pallet-domains/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,8 @@ impl<T: Config> Pallet<T> {
24032403
Ok(())
24042404
}
24052405

2406+
/// Verifies if the submitted ER version matches with the version
2407+
/// defined at the block number ER is derived from.
24062408
fn check_execution_receipt_version(
24072409
er_derived_consensus_number: BlockNumberFor<T>,
24082410
receipt_version: ExecutionReceiptVersion,

crates/pallet-domains/src/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,10 @@ fn get_mock_upgrades() -> Vec<(u32, MockBundleAndExecutionReceiptVersion, bool)>
13161316
]
13171317
}
13181318

1319+
/// Returns mock version queries.
1320+
/// (block_number, current_version)
1321+
/// block_number: Consensus block at which ER is derived
1322+
/// current_version: Version defined at the consensus block number.
13191323
fn get_mock_version_queries() -> Vec<(u32, MockBundleAndExecutionReceiptVersion)> {
13201324
vec![
13211325
// version from 0..100

crates/sp-domains-fraud-proof/src/fraud_proof.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,6 @@ impl<DomainHash> From<storage_proof::VerificationError> for VerificationError<Do
315315
}
316316
}
317317

318-
/// Represents a valid bundle index and all the extrinsics within that bundle.
319-
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
320-
pub struct ValidBundleDigest {
321-
/// Index of this bundle in the original list of bundles in the consensus block.
322-
pub bundle_index: u32,
323-
/// `Vec<(tx_signer, tx_hash)>` of all extrinsics
324-
pub bundle_digest: Vec<(
325-
Option<domain_runtime_primitives::opaque::AccountId>,
326-
ExtrinsicDigest,
327-
)>,
328-
}
329-
330318
/// Fraud proof for domains.
331319
#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
332320
pub struct FraudProof<Number, Hash, DomainHeader: HeaderT, MmrHash> {
@@ -467,6 +455,18 @@ impl<Number, Hash, MmrHash, DomainHeader: HeaderT> fmt::Debug
467455
}
468456
}
469457

458+
/// Represents a valid bundle index and all the extrinsics within that bundle.
459+
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
460+
pub struct ValidBundleDigest {
461+
/// Index of this bundle in the original list of bundles in the consensus block.
462+
pub bundle_index: u32,
463+
/// `Vec<(tx_signer, tx_hash)>` of all extrinsics
464+
pub bundle_digest: Vec<(
465+
Option<domain_runtime_primitives::opaque::AccountId>,
466+
ExtrinsicDigest,
467+
)>,
468+
}
469+
470470
// Domain runtime code at a specific block
471471
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
472472
pub struct DomainRuntimeCodeAt<Number, Hash, MmrHash> {

crates/sp-domains-fraud-proof/src/verification.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ where
384384
Ok(())
385385
}
386386

387-
/// Verifies invalid transfers fraud proof.
388-
pub fn verify_invalid_transfers_fraud_proof<
387+
/// Verifies invalid block fees fraud proof.
388+
pub fn verify_invalid_block_fees_fraud_proof<
389389
CBlock,
390390
DomainNumber,
391391
DomainHash,
@@ -405,37 +405,38 @@ pub fn verify_invalid_transfers_fraud_proof<
405405
where
406406
CBlock: BlockT,
407407
Balance: PartialEq + Decode + Encode + Zero + Default,
408+
DomainHashing: Hasher<Out = DomainHash>,
408409
DomainNumber: Encode + Zero,
409410
DomainHash: Clone + Encode + Default + Copy,
410-
DomainHashing: Hasher<Out = DomainHash>,
411411
{
412412
let storage_key = fraud_proof_runtime_interface::domain_storage_key(
413413
domain_runtime_code,
414-
DomainStorageKeyRequest::Transfers,
414+
DomainStorageKeyRequest::BlockFees,
415415
)
416416
.ok_or(VerificationError::FailedToGetDomainStorageKey)?;
417417

418-
let transfers = StorageProofVerifier::<DomainHashing>::get_decoded_value::<Transfers<Balance>>(
419-
bad_receipt.final_state_root(),
420-
storage_proof.clone(),
421-
StorageKey(storage_key),
422-
)
423-
.map_err(|err| {
424-
VerificationError::StorageProof(storage_proof::VerificationError::TransfersStorageProof(
425-
err,
426-
))
427-
})?;
418+
let block_fees =
419+
StorageProofVerifier::<DomainHashing>::get_decoded_value::<BlockFees<Balance>>(
420+
bad_receipt.final_state_root(),
421+
storage_proof.clone(),
422+
StorageKey(storage_key),
423+
)
424+
.map_err(|err| {
425+
VerificationError::StorageProof(
426+
storage_proof::VerificationError::BlockFeesStorageProof(err),
427+
)
428+
})?;
428429

429430
// if the rewards matches, then this is an invalid fraud proof since rewards must be different.
430-
if bad_receipt.transfers() == &transfers {
431+
if bad_receipt.block_fees() == &block_fees {
431432
return Err(VerificationError::InvalidProof);
432433
}
433434

434435
Ok(())
435436
}
436437

437-
/// Verifies invalid block fees fraud proof.
438-
pub fn verify_invalid_block_fees_fraud_proof<
438+
/// Verifies invalid transfers fraud proof.
439+
pub fn verify_invalid_transfers_fraud_proof<
439440
CBlock,
440441
DomainNumber,
441442
DomainHash,
@@ -455,30 +456,29 @@ pub fn verify_invalid_block_fees_fraud_proof<
455456
where
456457
CBlock: BlockT,
457458
Balance: PartialEq + Decode + Encode + Zero + Default,
458-
DomainHashing: Hasher<Out = DomainHash>,
459459
DomainNumber: Encode + Zero,
460460
DomainHash: Clone + Encode + Default + Copy,
461+
DomainHashing: Hasher<Out = DomainHash>,
461462
{
462463
let storage_key = fraud_proof_runtime_interface::domain_storage_key(
463464
domain_runtime_code,
464-
DomainStorageKeyRequest::BlockFees,
465+
DomainStorageKeyRequest::Transfers,
465466
)
466467
.ok_or(VerificationError::FailedToGetDomainStorageKey)?;
467468

468-
let block_fees =
469-
StorageProofVerifier::<DomainHashing>::get_decoded_value::<BlockFees<Balance>>(
470-
bad_receipt.final_state_root(),
471-
storage_proof.clone(),
472-
StorageKey(storage_key),
473-
)
474-
.map_err(|err| {
475-
VerificationError::StorageProof(
476-
storage_proof::VerificationError::BlockFeesStorageProof(err),
477-
)
478-
})?;
469+
let transfers = StorageProofVerifier::<DomainHashing>::get_decoded_value::<Transfers<Balance>>(
470+
bad_receipt.final_state_root(),
471+
storage_proof.clone(),
472+
StorageKey(storage_key),
473+
)
474+
.map_err(|err| {
475+
VerificationError::StorageProof(storage_proof::VerificationError::TransfersStorageProof(
476+
err,
477+
))
478+
})?;
479479

480480
// if the rewards matches, then this is an invalid fraud proof since rewards must be different.
481-
if bad_receipt.block_fees() == &block_fees {
481+
if bad_receipt.transfers() == &transfers {
482482
return Err(VerificationError::InvalidProof);
483483
}
484484

crates/sp-domains/src/bundle/bundle_v0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<Number: Encode, Hash: Encode, DomainHeader: HeaderT, Balance: Encode>
6363
}
6464
}
6565

66-
/// Domain bundle v1.
66+
/// Domain bundle v0.
6767
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
6868
pub struct BundleV0<Extrinsic, Number, Hash, DomainHeader: HeaderT, Balance> {
6969
/// Sealed bundle header.

0 commit comments

Comments
 (0)