This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Free consensus updates border condition (#172)
* illustrates border condition * adds test payloads * cleanup * update comment * fmt * shuffle things around * a few more test checks * Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs Co-authored-by: Adrian Catangiu <[email protected]> --------- Co-authored-by: Adrian Catangiu <[email protected]>
- Loading branch information
1 parent
b19c1e1
commit 7004ded
Showing
5 changed files
with
651 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pub use crate::mock::*; | ||
use crate::{ | ||
config::{EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT}, | ||
functions::compute_period, | ||
mock::{ | ||
get_message_verification_payload, load_checkpoint_update_fixture, | ||
load_finalized_header_update_fixture, load_next_finalized_header_update_fixture, | ||
load_next_sync_committee_update_fixture, load_sync_committee_update_fixture, | ||
}, | ||
sync_committee_sum, verify_merkle_branch, BeaconHeader, CompactBeaconState, Error, | ||
FinalizedBeaconState, LatestFinalizedBlockRoot, NextSyncCommittee, SyncCommitteePrepared, | ||
FinalizedBeaconState, LatestFinalizedBlockRoot, LatestFreeSyncCommitteeUpdatePeriod, | ||
NextSyncCommittee, SyncCommitteePrepared, | ||
}; | ||
|
||
pub use crate::mock::*; | ||
|
||
use crate::config::{EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT}; | ||
use frame_support::{assert_err, assert_noop, assert_ok, pallet_prelude::Pays}; | ||
use hex_literal::hex; | ||
use snowbridge_beacon_primitives::{ | ||
|
@@ -358,7 +357,7 @@ fn submit_update_in_current_period() { | |
assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); | ||
let result = EthereumBeaconClient::submit(RuntimeOrigin::signed(1), update.clone()); | ||
assert_ok!(result); | ||
assert_eq!(result.unwrap().pays_fee, Pays::Yes); | ||
assert_eq!(result.unwrap().pays_fee, Pays::No); | ||
let block_root: H256 = update.finalized_header.hash_tree_root().unwrap(); | ||
assert!(<FinalizedBeaconState<Test>>::contains_key(block_root)); | ||
}); | ||
|
@@ -693,8 +692,40 @@ fn duplicate_sync_committee_updates_are_not_free() { | |
// Check that if the same update is submitted, the update is not free. | ||
let second_result = | ||
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), sync_committee_update); | ||
assert_err!(second_result, Error::<Test>::IrrelevantUpdate); | ||
assert_eq!(second_result.unwrap_err().post_info.pays_fee, Pays::Yes); | ||
assert_ok!(second_result); | ||
assert_eq!(second_result.unwrap().pays_fee, Pays::Yes); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn sync_committee_update_for_sync_committee_already_imported_are_not_free() { | ||
let checkpoint = Box::new(load_checkpoint_update_fixture()); | ||
let sync_committee_update = Box::new(load_sync_committee_update_fixture()); | ||
let second_sync_committee_update = Box::new(load_sync_committee_update_period_0_fixture()); | ||
let third_sync_committee_update = Box::new(load_next_sync_committee_update_fixture()); | ||
|
||
new_tester().execute_with(|| { | ||
assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); | ||
assert_eq!(<LatestFreeSyncCommitteeUpdatePeriod<Test>>::get(), 0); | ||
|
||
// Check that setting the next sync committee for period 0 is free (it is not set yet). | ||
let result = | ||
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), sync_committee_update.clone()); | ||
assert_ok!(result); | ||
assert_eq!(result.unwrap().pays_fee, Pays::No); | ||
assert_eq!(<LatestFreeSyncCommitteeUpdatePeriod<Test>>::get(), 0); | ||
|
||
// Check that setting the next sync committee for period 0 again is not free. | ||
let second_result = | ||
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), second_sync_committee_update); | ||
assert_eq!(second_result.unwrap().pays_fee, Pays::Yes); | ||
assert_eq!(<LatestFreeSyncCommitteeUpdatePeriod<Test>>::get(), 0); | ||
|
||
// Check that setting the next sync committee for period 1 is free. | ||
let third_result = | ||
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), third_sync_committee_update); | ||
assert_eq!(third_result.unwrap().pays_fee, Pays::No); | ||
assert_eq!(<LatestFreeSyncCommitteeUpdatePeriod<Test>>::get(), 1); | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.