-
Notifications
You must be signed in to change notification settings - Fork 875
Add Electra fork boilerplate #5122
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
24edf45
Add Electra fork boilerplate
macladson bc36e97
Remove electra from spec tests
macladson 150e37c
Fix tests
macladson ae60752
Remove sneaky log file
macladson f7848a5
Fix more tests
macladson 2dfb580
Fix even more tests and add suggestions
macladson 6948b94
Remove unrelated lcli addition
macladson ad8ad52
Update more tests
macladson 811f50c
Merge branch 'unstable' into electra
macladson 02dd670
Add comment for test-suite lcli override
macladson 8e54a9b
Merge branch 'unstable' into electra
macladson 7b9765a
Cleanup
macladson 1089cb5
Merge branch 'unstable' into electra
macladson ef724dc
Apply suggestions
macladson ec88934
Merge branch 'unstable' into electra
macladson 9d7089b
Merge sigp/unstable into electra
dapplion 24178cc
Merge branch 'unstable' into electra
dapplion 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
//! Provides tools for checking if a node is ready for the Electra upgrade and following merge | ||
//! transition. | ||
|
||
use crate::{BeaconChain, BeaconChainTypes}; | ||
use execution_layer::http::{ | ||
ENGINE_FORKCHOICE_UPDATED_V3, ENGINE_GET_PAYLOAD_V3, ENGINE_NEW_PAYLOAD_V3, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
use std::time::Duration; | ||
use types::*; | ||
|
||
/// The time before the Electra fork when we will start issuing warnings about preparation. | ||
use super::merge_readiness::SECONDS_IN_A_WEEK; | ||
pub const ELECTRA_READINESS_PREPARATION_SECONDS: u64 = SECONDS_IN_A_WEEK * 2; | ||
pub const ENGINE_CAPABILITIES_REFRESH_INTERVAL: u64 = 300; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "snake_case")] | ||
#[serde(tag = "type")] | ||
pub enum ElectraReadiness { | ||
/// The execution engine is electra-enabled (as far as we can tell) | ||
Ready, | ||
/// We are connected to an execution engine which doesn't support the V3 engine api methods | ||
V3MethodsNotSupported { error: String }, | ||
/// The transition configuration with the EL failed, there might be a problem with | ||
/// connectivity, authentication or a difference in configuration. | ||
ExchangeCapabilitiesFailed { error: String }, | ||
/// The user has not configured an execution endpoint | ||
NoExecutionEndpoint, | ||
} | ||
|
||
impl fmt::Display for ElectraReadiness { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
ElectraReadiness::Ready => { | ||
write!(f, "This node appears ready for Electra.") | ||
} | ||
ElectraReadiness::ExchangeCapabilitiesFailed { error } => write!( | ||
f, | ||
"Could not exchange capabilities with the \ | ||
execution endpoint: {}", | ||
error | ||
), | ||
ElectraReadiness::NoExecutionEndpoint => write!( | ||
f, | ||
"The --execution-endpoint flag is not specified, this is a \ | ||
requirement post-merge" | ||
), | ||
ElectraReadiness::V3MethodsNotSupported { error } => write!( | ||
f, | ||
"Execution endpoint does not support Electra methods: {}", | ||
error | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl<T: BeaconChainTypes> BeaconChain<T> { | ||
/// Returns `true` if electra epoch is set and Electra fork has occurred or will | ||
/// occur within `ELECTRA_READINESS_PREPARATION_SECONDS` | ||
pub fn is_time_to_prepare_for_electra(&self, current_slot: Slot) -> bool { | ||
if let Some(electra_epoch) = self.spec.electra_fork_epoch { | ||
let electra_slot = electra_epoch.start_slot(T::EthSpec::slots_per_epoch()); | ||
let electra_readiness_preparation_slots = | ||
ELECTRA_READINESS_PREPARATION_SECONDS / self.spec.seconds_per_slot; | ||
// Return `true` if Electra has happened or is within the preparation time. | ||
current_slot + electra_readiness_preparation_slots > electra_slot | ||
} else { | ||
// The Electra fork epoch has not been defined yet, no need to prepare. | ||
false | ||
} | ||
} | ||
|
||
/// Attempts to connect to the EL and confirm that it is ready for electra. | ||
pub async fn check_electra_readiness(&self) -> ElectraReadiness { | ||
if let Some(el) = self.execution_layer.as_ref() { | ||
match el | ||
.get_engine_capabilities(Some(Duration::from_secs( | ||
ENGINE_CAPABILITIES_REFRESH_INTERVAL, | ||
))) | ||
.await | ||
{ | ||
Err(e) => { | ||
// The EL was either unreachable or responded with an error | ||
ElectraReadiness::ExchangeCapabilitiesFailed { | ||
error: format!("{:?}", e), | ||
} | ||
} | ||
Ok(capabilities) => { | ||
let mut missing_methods = String::from("Required Methods Unsupported:"); | ||
let mut all_good = true; | ||
if !capabilities.get_payload_v3 { | ||
missing_methods.push(' '); | ||
missing_methods.push_str(ENGINE_GET_PAYLOAD_V3); | ||
macladson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
all_good = false; | ||
} | ||
if !capabilities.forkchoice_updated_v3 { | ||
missing_methods.push(' '); | ||
missing_methods.push_str(ENGINE_FORKCHOICE_UPDATED_V3); | ||
all_good = false; | ||
} | ||
if !capabilities.new_payload_v3 { | ||
missing_methods.push(' '); | ||
missing_methods.push_str(ENGINE_NEW_PAYLOAD_V3); | ||
all_good = false; | ||
} | ||
|
||
if all_good { | ||
ElectraReadiness::Ready | ||
} else { | ||
ElectraReadiness::V3MethodsNotSupported { | ||
error: missing_methods, | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
ElectraReadiness::NoExecutionEndpoint | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.