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
Free consensus updates border condition #172
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a27360
illustrates border condition
claravanstaden 209274b
adds test payloads
claravanstaden c8307f7
cleanup
claravanstaden c2ed92d
update comment
claravanstaden 25c83b5
fmt
claravanstaden 3997df7
shuffle things around
claravanstaden 6919815
a few more test checks
claravanstaden 9ad72e8
Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs
claravanstaden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this up so we can check if the
NextSyncCommittee
is empty before updating this update.