Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set CollectedBlockFees to an empty value during block initialization #2782

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
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
Loading