-
Notifications
You must be signed in to change notification settings - Fork 105
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
Sync beacon execution update on demand #1140
Closed
Closed
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
387e085
Update for Dencun
yrong 846065a
build geth&lodestar from source
yrong 65272d4
Fix makeTrie
yrong d2f0d66
Merge branch 'main' into ron/dencun
yrong 63b0f07
Update go ethereum to v1.13.5
yrong faf5d01
Update packages & Speedup e2e setup
yrong c179311
Update lodestar to v1.12.0
yrong d728f48
Remove unused
yrong 28f23dd
Remove unrelated changes
yrong cce7714
Ignore build geth when binary exist
yrong 48cc44f
Cleanup for deprecated ethashproof
yrong fe1e191
Update with VersionedExecutionPayloadHeader
yrong d37a736
Fix breaking tests
yrong 1aa5a0a
Merge branch 'main' into ron/dencun
yrong 545e267
Update node package
yrong 1c5b33d
Update git modules
yrong 647f57e
Sync packages with nix
yrong 40daff1
Merge branch 'main' of https://github.com/Snowfork/snowbridge into ro…
yrong 565cd83
Update sdk
yrong 7414746
Update contract binding
yrong 70d017b
More cleanup
yrong 585dc78
For deneb(1)
yrong ba67bf3
For deneb(2)
yrong f9f7458
Update sdk
yrong d542799
For deneb(3)
yrong 904e97a
Update sdk
yrong 99c0304
For deneb(4)
yrong 8a50ced
Enable deneb for local setup
yrong e5c2381
Fix tests
yrong 29a2afe
Fix BeaconStateDeneb & more tests
yrong 3f6cb38
Merge branch 'main' into ron/dencun
yrong 4aae19a
Generate test fixture for Deneb and more tests accordingly
yrong 79e79dd
Merge branch 'main' into ron/dencun
yrong ed69a35
Fix parse empty field
yrong 1c1ca20
Setup for switchover test
yrong 8f95e8a
Test workflow specific for deneb
yrong ba5957e
Ignore change detect building polkadot binary
yrong 9673b21
Encode with error handling
yrong e767e6e
Fix format
yrong e5120e8
Merge branch 'main' into ron/dencun
yrong 6a38f79
Update lodestar
yrong c246f70
Improve scripts setting up nodes for production
yrong 6892678
Merge branch 'main' into ron/dencun
yrong b76a4dd
Sync execution update on demand
yrong bdec747
Merge branch 'main' into ron/dencun
yrong 99f5a6d
Fix import
yrong 3580c4d
Reorganize deneb primitives
yrong d1a5b86
Update go mod
yrong ad65ebd
Fix format
yrong 53e4fa6
Remove obsolete
yrong d069f97
Fix import
yrong da3d338
Merge branch 'main' into ron/dencun
yrong 58a28bd
Merge branch 'main' into ron/dencun
yrong 61dadc9
Fix the deneb ForkVersion
yrong 328d541
Upgrade geth and lodestar
yrong 9d633e2
Merge branch 'ron/dencun' into ron/execution-update-on-demand
yrong d37ee40
Download geth release to replace the nix default
yrong d4bc62b
Naming consistently
yrong 0c14e49
Update lodestar with the mock hack
yrong 0ed243a
Fix generate mainnet fixture
yrong 810fa47
Merge branch 'ron/dencun' into ron/execution-update-on-demand
yrong 53c6fb8
Remove fixture unused
yrong 4cdfa96
Backward compatible
yrong b5ea6b2
Check execution_branch
yrong 6bd6723
Remove build geth
yrong b892f77
Remove cross check
yrong a646a4e
sync all lagging periods
yrong ee71d1a
Clean up
yrong 79247a2
More refactoring
yrong 49800bd
Cleanup scripts
yrong cdc7165
Update sdk
yrong 072c3f0
Merge branch 'main' into ron/execution-update-on-demand
yrong c42d0af
Ignore go.work
yrong 5bc2526
Rename function
yrong f465995
Merge branch 'main' into ron/execution-update-on-demand
yrong dd866bb
Fix test
yrong afe2b43
Fix populate checkpoint
yrong 018c565
Fix smoke test
yrong 775e56a
Merge branch 'main' into ron/execution-update-on-demand
yrong 3f0f027
Merge branch 'main' into ron/execution-update-on-demand
yrong 1d67967
Merge branch 'main' into ron/execution-update-on-demand
yrong 7b5e1e3
Update lodestar & polkadot-sdk
yrong 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ contracts/beefy-state.json | |
|
||
go/ | ||
gocache/ | ||
go.work* |
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 |
---|---|---|
|
@@ -34,9 +34,7 @@ mod tests; | |
#[cfg(feature = "runtime-benchmarks")] | ||
mod benchmarking; | ||
|
||
use frame_support::{ | ||
dispatch::DispatchResult, pallet_prelude::OptionQuery, traits::Get, transactional, | ||
}; | ||
use frame_support::{dispatch::DispatchResult, pallet_prelude::OptionQuery, traits::Get}; | ||
use frame_system::ensure_signed; | ||
use primitives::{ | ||
fast_aggregate_verify, verify_merkle_branch, verify_receipt_proof, BeaconHeader, BlsError, | ||
|
@@ -214,8 +212,7 @@ pub mod pallet { | |
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(T::WeightInfo::force_checkpoint())] | ||
#[transactional] | ||
#[pallet::weight((T::WeightInfo::force_checkpoint(), DispatchClass::Operational))] | ||
/// Used for pallet initialization and light client resetting. Needs to be called by | ||
/// the root origin. | ||
pub fn force_checkpoint( | ||
|
@@ -234,7 +231,6 @@ pub mod pallet { | |
Some(_) => T::WeightInfo::submit_with_sync_committee(), | ||
} | ||
})] | ||
#[transactional] | ||
/// Submits a new finalized beacon header update. The update may contain the next | ||
/// sync committee. | ||
pub fn submit(origin: OriginFor<T>, update: Box<Update>) -> DispatchResult { | ||
|
@@ -246,7 +242,6 @@ pub mod pallet { | |
|
||
#[pallet::call_index(2)] | ||
#[pallet::weight(T::WeightInfo::submit_execution_header())] | ||
#[transactional] | ||
/// Submits a new execution header update. The relevant related beacon header | ||
/// is also included to prove the execution header, as well as ancestry proof data. | ||
pub fn submit_execution_header( | ||
|
@@ -330,32 +325,11 @@ pub mod pallet { | |
} | ||
|
||
pub(crate) fn process_update(update: &Update) -> DispatchResult { | ||
Self::cross_check_execution_state()?; | ||
Self::verify_update(update)?; | ||
Self::apply_update(update)?; | ||
Ok(()) | ||
} | ||
|
||
/// Cross check to make sure that execution header import does not fall too far behind | ||
/// finalised beacon header import. If that happens just return an error and pause | ||
/// processing until execution header processing has caught up. | ||
pub(crate) fn cross_check_execution_state() -> DispatchResult { | ||
let latest_finalized_state = | ||
FinalizedBeaconState::<T>::get(LatestFinalizedBlockRoot::<T>::get()) | ||
.ok_or(Error::<T>::NotBootstrapped)?; | ||
let latest_execution_state = Self::latest_execution_state(); | ||
// The execution header import should be at least within the slot range of a sync | ||
// committee period. | ||
let max_latency = config::EPOCHS_PER_SYNC_COMMITTEE_PERIOD * config::SLOTS_PER_EPOCH; | ||
ensure!( | ||
latest_execution_state.beacon_slot == 0 || | ||
latest_finalized_state.slot < | ||
latest_execution_state.beacon_slot + max_latency as u64, | ||
Error::<T>::ExecutionHeaderTooFarBehind | ||
); | ||
Ok(()) | ||
} | ||
|
||
/// References and strictly follows <https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#validate_light_client_update> | ||
/// Verifies that provided next sync committee is valid through a series of checks | ||
/// (including checking that a sync committee period isn't skipped and that the header is | ||
|
@@ -479,6 +453,28 @@ pub mod pallet { | |
) | ||
.map_err(|e| Error::<T>::BLSVerificationFailed(e))?; | ||
|
||
// Execution payload header corresponding to `beacon.body_root` (from Capella onward) | ||
// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/light-client/sync-protocol.md#modified-lightclientheader | ||
if let Some(version_execution_header) = &update.execution_header { | ||
let execution_header_root: H256 = version_execution_header | ||
.hash_tree_root() | ||
.map_err(|_| Error::<T>::BlockBodyHashTreeRootFailed)?; | ||
ensure!( | ||
&update.execution_branch.is_some(), | ||
Error::<T>::InvalidExecutionHeaderProof | ||
); | ||
ensure!( | ||
verify_merkle_branch( | ||
execution_header_root, | ||
&update.execution_branch.clone().unwrap(), | ||
config::EXECUTION_HEADER_SUBTREE_INDEX, | ||
config::EXECUTION_HEADER_DEPTH, | ||
update.finalized_header.body_root | ||
), | ||
Error::<T>::InvalidExecutionHeaderProof | ||
); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
@@ -530,6 +526,19 @@ pub mod pallet { | |
)?; | ||
} | ||
|
||
if let Some(version_execution_header) = &update.execution_header { | ||
let finalized_block_root: H256 = update | ||
.finalized_header | ||
.hash_tree_root() | ||
.map_err(|_| Error::<T>::HeaderHashTreeRootFailed)?; | ||
Self::store_execution_header( | ||
version_execution_header.block_hash(), | ||
version_execution_header.clone().into(), | ||
update.finalized_header.slot, | ||
finalized_block_root, | ||
); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
@@ -548,15 +557,6 @@ pub mod pallet { | |
Error::<T>::HeaderNotFinalized | ||
); | ||
|
||
// Checks that we don't skip execution headers, they need to be imported sequentially. | ||
let latest_execution_state: ExecutionHeaderState = Self::latest_execution_state(); | ||
ensure!( | ||
latest_execution_state.block_number == 0 || | ||
update.execution_header.block_number() == | ||
latest_execution_state.block_number + 1, | ||
Error::<T>::ExecutionHeaderSkippedBlock | ||
); | ||
|
||
Comment on lines
-551
to
-559
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the consecutive check we don't need it any more. |
||
// Gets the hash tree root of the execution header, in preparation for the execution | ||
// header proof (used to check that the execution header is rooted in the beacon | ||
// header body. | ||
|
@@ -709,12 +709,15 @@ pub mod pallet { | |
block_number | ||
); | ||
|
||
LatestExecutionState::<T>::mutate(|s| { | ||
s.beacon_block_root = beacon_block_root; | ||
s.beacon_slot = beacon_slot; | ||
s.block_hash = block_hash; | ||
s.block_number = block_number; | ||
}); | ||
let latest_execution_state = LatestExecutionState::<T>::get(); | ||
if beacon_slot > latest_execution_state.beacon_slot { | ||
LatestExecutionState::<T>::mutate(|s| { | ||
s.beacon_block_root = beacon_block_root; | ||
s.beacon_slot = beacon_slot; | ||
s.block_hash = block_hash; | ||
s.block_number = block_number; | ||
}); | ||
} | ||
|
||
Self::deposit_event(Event::ExecutionHeaderImported { block_hash, block_number }); | ||
} | ||
|
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
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.
Remove the
cross_check
we don't need it any more.