-
Notifications
You must be signed in to change notification settings - Fork 781
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
Add Fulu boilerplate #6695
Open
macladson
wants to merge
4
commits into
sigp:unstable
Choose a base branch
from
macladson:fulu-boilerplate
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Fulu boilerplate #6695
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
//! Provides tools for checking if a node is ready for the Fulu upgrade. | ||
|
||
use crate::{BeaconChain, BeaconChainTypes}; | ||
use execution_layer::http::{ENGINE_GET_PAYLOAD_V5, ENGINE_NEW_PAYLOAD_V5}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
use std::time::Duration; | ||
use types::*; | ||
|
||
/// The time before the Fulu fork when we will start issuing warnings about preparation. | ||
use super::bellatrix_readiness::SECONDS_IN_A_WEEK; | ||
pub const FULU_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 FuluReadiness { | ||
/// The execution engine is fulu-enabled (as far as we can tell) | ||
Ready, | ||
/// We are connected to an execution engine which doesn't support the V4 engine api methods | ||
V5MethodsNotSupported { 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 FuluReadiness { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
FuluReadiness::Ready => { | ||
write!(f, "This node appears ready for Fulu.") | ||
} | ||
FuluReadiness::ExchangeCapabilitiesFailed { error } => write!( | ||
f, | ||
"Could not exchange capabilities with the \ | ||
execution endpoint: {}", | ||
error | ||
), | ||
FuluReadiness::NoExecutionEndpoint => write!( | ||
f, | ||
"The --execution-endpoint flag is not specified, this is a \ | ||
requirement post-merge" | ||
), | ||
FuluReadiness::V5MethodsNotSupported { error } => write!( | ||
f, | ||
"Execution endpoint does not support Fulu methods: {}", | ||
error | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl<T: BeaconChainTypes> BeaconChain<T> { | ||
/// Returns `true` if fulu epoch is set and Fulu fork has occurred or will | ||
/// occur within `FULU_READINESS_PREPARATION_SECONDS` | ||
pub fn is_time_to_prepare_for_fulu(&self, current_slot: Slot) -> bool { | ||
if let Some(fulu_epoch) = self.spec.fulu_fork_epoch { | ||
let fulu_slot = fulu_epoch.start_slot(T::EthSpec::slots_per_epoch()); | ||
let fulu_readiness_preparation_slots = | ||
FULU_READINESS_PREPARATION_SECONDS / self.spec.seconds_per_slot; | ||
// Return `true` if Fulu has happened or is within the preparation time. | ||
current_slot + fulu_readiness_preparation_slots > fulu_slot | ||
} else { | ||
// The Fulu 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 fulu. | ||
pub async fn check_fulu_readiness(&self) -> FuluReadiness { | ||
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 | ||
FuluReadiness::ExchangeCapabilitiesFailed { | ||
error: format!("{:?}", e), | ||
} | ||
} | ||
Ok(capabilities) => { | ||
let mut missing_methods = String::from("Required Methods Unsupported:"); | ||
let mut all_good = true; | ||
if !capabilities.get_payload_v5 { | ||
missing_methods.push(' '); | ||
missing_methods.push_str(ENGINE_GET_PAYLOAD_V5); | ||
all_good = false; | ||
} | ||
if !capabilities.new_payload_v5 { | ||
missing_methods.push(' '); | ||
missing_methods.push_str(ENGINE_NEW_PAYLOAD_V5); | ||
all_good = false; | ||
} | ||
|
||
if all_good { | ||
FuluReadiness::Ready | ||
} else { | ||
FuluReadiness::V5MethodsNotSupported { | ||
error: missing_methods, | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
FuluReadiness::NoExecutionEndpoint | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -501,6 +501,9 @@ where | |
spec.electra_fork_epoch.map(|epoch| { | ||
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64() | ||
}); | ||
mock.server.execution_block_generator().osaka_time = spec.fulu_fork_epoch.map(|epoch| { | ||
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64() | ||
}); | ||
|
||
self | ||
} | ||
|
@@ -623,6 +626,9 @@ pub fn mock_execution_layer_from_parts<E: EthSpec>( | |
let prague_time = spec.electra_fork_epoch.map(|epoch| { | ||
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64() | ||
}); | ||
let osaka_time = spec.fulu_fork_epoch.map(|epoch| { | ||
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64() | ||
}); | ||
|
||
let kzg = get_kzg(spec); | ||
|
||
|
@@ -632,6 +638,7 @@ pub fn mock_execution_layer_from_parts<E: EthSpec>( | |
shanghai_time, | ||
cancun_time, | ||
prague_time, | ||
osaka_time, | ||
Some(JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap()), | ||
spec.clone(), | ||
Some(kzg), | ||
|
@@ -918,9 +925,9 @@ where | |
| SignedBeaconBlock::Altair(_) | ||
| SignedBeaconBlock::Bellatrix(_) | ||
| SignedBeaconBlock::Capella(_) => (signed_block, None), | ||
SignedBeaconBlock::Deneb(_) | SignedBeaconBlock::Electra(_) => { | ||
(signed_block, block_response.blob_items) | ||
} | ||
SignedBeaconBlock::Deneb(_) | ||
| SignedBeaconBlock::Electra(_) | ||
| SignedBeaconBlock::Fulu(_) => (signed_block, block_response.blob_items), | ||
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. This can also be |
||
}; | ||
|
||
(block_contents, block_response.state) | ||
|
@@ -982,9 +989,9 @@ where | |
| SignedBeaconBlock::Altair(_) | ||
| SignedBeaconBlock::Bellatrix(_) | ||
| SignedBeaconBlock::Capella(_) => (signed_block, None), | ||
SignedBeaconBlock::Deneb(_) | SignedBeaconBlock::Electra(_) => { | ||
(signed_block, block_response.blob_items) | ||
} | ||
SignedBeaconBlock::Deneb(_) | ||
| SignedBeaconBlock::Electra(_) | ||
| SignedBeaconBlock::Fulu(_) => (signed_block, block_response.blob_items), | ||
}; | ||
(block_contents, pre_state) | ||
} | ||
|
@@ -2863,6 +2870,25 @@ pub fn generate_rand_block_and_blobs<E: EthSpec>( | |
message.body.blob_kzg_commitments = bundle.commitments.clone(); | ||
bundle | ||
} | ||
SignedBeaconBlock::Fulu(SignedBeaconBlockFulu { | ||
ref mut message, .. | ||
}) => { | ||
// Get either zero blobs or a random number of blobs between 1 and Max Blobs. | ||
let payload: &mut FullPayloadFulu<E> = &mut message.body.execution_payload; | ||
let num_blobs = match num_blobs { | ||
NumBlobs::Random => rng.gen_range(1..=E::max_blobs_per_block()), | ||
NumBlobs::Number(n) => n, | ||
NumBlobs::None => 0, | ||
}; | ||
let (bundle, transactions) = | ||
execution_layer::test_utils::generate_blobs::<E>(num_blobs).unwrap(); | ||
payload.execution_payload.transactions = <_>::default(); | ||
for tx in Vec::from(transactions) { | ||
payload.execution_payload.transactions.push(tx).unwrap(); | ||
} | ||
message.body.blob_kzg_commitments = bundle.commitments.clone(); | ||
bundle | ||
} | ||
_ => return (block, blob_sidecars), | ||
}; | ||
|
||
|
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.
Can we do
fork.after_bellatrix
here? the argument of using a match to force us to think about the fork is broken here, because we don't know what EIPs will exist in the fork and if we need a new handler. So now we are getting the worst of both worlds. a 1980 lines boilerplate PR and no guarantees or correctness