Skip to content

Commit

Permalink
Merge pull request #2782 from subspace/block-fees-fp
Browse files Browse the repository at this point in the history
Set CollectedBlockFees to an empty value during block initialization
  • Loading branch information
NingLin-P authored May 28, 2024
2 parents b8bd0e0 + 1d28e03 commit d3096b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
19 changes: 2 additions & 17 deletions domains/client/domain-operator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ async fn test_invalid_block_fees_proof_creation() {
);

// Run Alice (a evm domain authority node)
let mut alice = domain_test_service::DomainNodeBuilder::new(
let alice = domain_test_service::DomainNodeBuilder::new(
tokio_handle.clone(),
Alice,
BasePath::new(directory.path().join("alice")),
Expand All @@ -1989,26 +1989,11 @@ async fn test_invalid_block_fees_proof_creation() {

produce_blocks!(ferdie, alice, 5).await.unwrap();

alice
.construct_and_send_extrinsic(pallet_balances::Call::transfer_allow_death {
dest: Bob.to_account_id(),
value: 1,
})
.await
.expect("Failed to send extrinsic");

// Produce a bundle that contains the previously sent extrinsic and record that bundle for later use
let (slot, target_bundle) = ferdie.produce_slot_and_wait_for_bundle_submission().await;
assert_eq!(target_bundle.extrinsics.len(), 1);
produce_block_with!(ferdie.produce_block_with_slot(slot), alice)
.await
.unwrap();

// Get a bundle from the txn pool and modify the receipt of the target bundle to an invalid one
let (slot, mut opaque_bundle) = ferdie.produce_slot_and_wait_for_bundle_submission().await;
let (bad_receipt_hash, bad_submit_bundle_tx) = {
let receipt = &mut opaque_bundle.sealed_header.header.receipt;
receipt.block_fees = Default::default();
receipt.block_fees.consensus_storage_fee = 12345;
opaque_bundle.sealed_header.signature = Sr25519Keyring::Alice
.pair()
.sign(opaque_bundle.sealed_header.pre_hash().as_ref())
Expand Down
5 changes: 4 additions & 1 deletion domains/pallets/block-fees/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_now: BlockNumberFor<T>) -> Weight {
CollectedBlockFees::<T>::take();
// NOTE: set the `CollectedBlockFees` to an empty value instead of removing the value
// completely so we can generate a storage proof to prove the empty value, which is used
// in the fraud proof.
CollectedBlockFees::<T>::set(BlockFees::<T::Balance>::default());
T::DbWeight::get().writes(1)
}

Expand Down
3 changes: 3 additions & 0 deletions domains/pallets/transporter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
// NOTE: set the `ChainTransfers` to an empty value instead of removing the value completely
// so we can generate a storage proof to prove the empty value, which is required by the fraud
// proof.
ChainTransfers::<T>::set(Default::default());
T::DbWeight::get().writes(1)
}
Expand Down

0 comments on commit d3096b8

Please sign in to comment.