mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-01 05:37:05 +00:00
Fork boilerplate
This commit is contained in:
@@ -19,9 +19,9 @@ use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
use types::{
|
||||
Blob, ChainSpec, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadBellatrix,
|
||||
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra, ExecutionPayloadFulu,
|
||||
ExecutionPayloadHeader, FixedBytesExtended, ForkName, Hash256, Transaction, Transactions,
|
||||
Uint256,
|
||||
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadEip7805,
|
||||
ExecutionPayloadElectra, ExecutionPayloadFulu, ExecutionPayloadHeader, FixedBytesExtended,
|
||||
ForkName, Hash256, Transaction, Transactions, Uint256,
|
||||
};
|
||||
|
||||
use super::DEFAULT_TERMINAL_BLOCK;
|
||||
@@ -147,6 +147,7 @@ pub struct ExecutionBlockGenerator<E: EthSpec> {
|
||||
pub shanghai_time: Option<u64>, // capella
|
||||
pub cancun_time: Option<u64>, // deneb
|
||||
pub prague_time: Option<u64>, // electra
|
||||
pub eip7805_time: Option<u64>, // eip7805
|
||||
pub osaka_time: Option<u64>, // fulu
|
||||
/*
|
||||
* deneb stuff
|
||||
@@ -172,6 +173,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
shanghai_time: Option<u64>,
|
||||
cancun_time: Option<u64>,
|
||||
prague_time: Option<u64>,
|
||||
eip7805_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
spec: Arc<ChainSpec>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
@@ -190,6 +192,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
shanghai_time,
|
||||
cancun_time,
|
||||
prague_time,
|
||||
eip7805_time,
|
||||
osaka_time,
|
||||
blobs_bundles: <_>::default(),
|
||||
kzg,
|
||||
@@ -242,13 +245,16 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
pub fn get_fork_at_timestamp(&self, timestamp: u64) -> ForkName {
|
||||
match self.osaka_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Fulu,
|
||||
_ => match self.prague_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Electra,
|
||||
_ => match self.cancun_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Deneb,
|
||||
_ => match self.shanghai_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Capella,
|
||||
_ => ForkName::Bellatrix,
|
||||
_ => match self.eip7805_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Eip7805,
|
||||
_ => match self.prague_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Electra,
|
||||
_ => match self.cancun_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Deneb,
|
||||
_ => match self.shanghai_time {
|
||||
Some(fork_time) if timestamp >= fork_time => ForkName::Capella,
|
||||
_ => ForkName::Bellatrix,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -674,6 +680,25 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
blob_gas_used: 0,
|
||||
excess_blob_gas: 0,
|
||||
}),
|
||||
ForkName::Eip7805 => ExecutionPayload::Eip7805(ExecutionPayloadEip7805 {
|
||||
parent_hash: head_block_hash,
|
||||
fee_recipient: pa.suggested_fee_recipient,
|
||||
receipts_root: Hash256::repeat_byte(42),
|
||||
state_root: Hash256::repeat_byte(43),
|
||||
logs_bloom: vec![0; 256].into(),
|
||||
prev_randao: pa.prev_randao,
|
||||
block_number: parent.block_number() + 1,
|
||||
gas_limit: DEFAULT_GAS_LIMIT,
|
||||
gas_used: GAS_USED,
|
||||
timestamp: pa.timestamp,
|
||||
extra_data: mock_el_extra_data::<E>(),
|
||||
base_fee_per_gas: Uint256::from(1u64),
|
||||
block_hash: ExecutionBlockHash::zero(),
|
||||
transactions: vec![].into(),
|
||||
withdrawals: pa.withdrawals.clone().into(),
|
||||
blob_gas_used: 0,
|
||||
excess_blob_gas: 0,
|
||||
}),
|
||||
ForkName::Fulu => ExecutionPayload::Fulu(ExecutionPayloadFulu {
|
||||
parent_hash: head_block_hash,
|
||||
fee_recipient: pa.suggested_fee_recipient,
|
||||
@@ -844,6 +869,12 @@ pub fn generate_genesis_header<E: EthSpec>(
|
||||
*header.transactions_root_mut() = empty_transactions_root;
|
||||
Some(header)
|
||||
}
|
||||
ForkName::Eip7805 => {
|
||||
let mut header = ExecutionPayloadHeader::Eip7805(<_>::default());
|
||||
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
|
||||
*header.transactions_root_mut() = empty_transactions_root;
|
||||
Some(header)
|
||||
}
|
||||
ForkName::Fulu => {
|
||||
let mut header = ExecutionPayloadHeader::Fulu(<_>::default());
|
||||
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
|
||||
@@ -923,6 +954,7 @@ mod test {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
spec,
|
||||
None,
|
||||
);
|
||||
|
||||
@@ -229,6 +229,44 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
));
|
||||
}
|
||||
}
|
||||
ForkName::Eip7805 => {
|
||||
if method == ENGINE_NEW_PAYLOAD_V1
|
||||
|| method == ENGINE_NEW_PAYLOAD_V2
|
||||
|| method == ENGINE_NEW_PAYLOAD_V3
|
||||
{
|
||||
return Err((
|
||||
format!("{} called after Electra fork!", method),
|
||||
GENERIC_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
if matches!(request, JsonExecutionPayload::V1(_)) {
|
||||
return Err((
|
||||
format!(
|
||||
"{} called with `ExecutionPayloadV1` after Electra fork!",
|
||||
method
|
||||
),
|
||||
GENERIC_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
if matches!(request, JsonExecutionPayload::V2(_)) {
|
||||
return Err((
|
||||
format!(
|
||||
"{} called with `ExecutionPayloadV2` after Electra fork!",
|
||||
method
|
||||
),
|
||||
GENERIC_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
if matches!(request, JsonExecutionPayload::V3(_)) {
|
||||
return Err((
|
||||
format!(
|
||||
"{} called with `ExecutionPayloadV3` after Electra fork!",
|
||||
method
|
||||
),
|
||||
GENERIC_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
}
|
||||
ForkName::Fulu => {
|
||||
if method == ENGINE_NEW_PAYLOAD_V1
|
||||
|| method == ENGINE_NEW_PAYLOAD_V2
|
||||
@@ -488,7 +526,23 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
JsonExecutionPayload::V4(execution_payload) => {
|
||||
serde_json::to_value(JsonGetPayloadResponseV4 {
|
||||
execution_payload,
|
||||
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
|
||||
blobs_bundle: maybe_blobs
|
||||
.ok_or((
|
||||
"No blobs returned despite V4 Payload".to_string(),
|
||||
GENERIC_ERROR_CODE,
|
||||
))?
|
||||
.into(),
|
||||
should_override_builder: false,
|
||||
// TODO(electra): add EL requests in mock el
|
||||
execution_requests: Default::default(),
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
other => unreachable!("check {:?}", other),
|
||||
}),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -588,7 +642,7 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
));
|
||||
}
|
||||
}
|
||||
ForkName::Deneb | ForkName::Electra | ForkName::Fulu => {
|
||||
ForkName::Deneb | ForkName::Electra | ForkName::Eip7805 | ForkName::Fulu => {
|
||||
if method == ENGINE_FORKCHOICE_UPDATED_V1 {
|
||||
return Err((
|
||||
format!("{} called after Deneb fork!", method),
|
||||
|
||||
@@ -26,8 +26,8 @@ use tokio_stream::StreamExt;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use tree_hash::TreeHash;
|
||||
use types::builder_bid::{
|
||||
BuilderBid, BuilderBidBellatrix, BuilderBidCapella, BuilderBidDeneb, BuilderBidElectra,
|
||||
BuilderBidFulu, SignedBuilderBid,
|
||||
BuilderBid, BuilderBidBellatrix, BuilderBidCapella, BuilderBidDeneb, BuilderBidEip7805,
|
||||
BuilderBidElectra, BuilderBidFulu, SignedBuilderBid,
|
||||
};
|
||||
use types::{
|
||||
Address, BeaconState, ChainSpec, Epoch, EthSpec, ExecPayload, ExecutionPayload,
|
||||
@@ -112,6 +112,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.fee_recipient = fee_recipient;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.fee_recipient = fee_recipient;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.fee_recipient = fee_recipient;
|
||||
}
|
||||
@@ -132,6 +135,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.gas_limit = gas_limit;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.gas_limit = gas_limit;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.gas_limit = gas_limit;
|
||||
}
|
||||
@@ -156,6 +162,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.parent_hash = ExecutionBlockHash::from_root(parent_hash);
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.parent_hash = ExecutionBlockHash::from_root(parent_hash);
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.parent_hash = ExecutionBlockHash::from_root(parent_hash);
|
||||
}
|
||||
@@ -176,6 +185,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.prev_randao = prev_randao;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.prev_randao = prev_randao;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.prev_randao = prev_randao;
|
||||
}
|
||||
@@ -196,6 +208,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.block_number = block_number;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.block_number = block_number;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.block_number = block_number;
|
||||
}
|
||||
@@ -216,6 +231,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.timestamp = timestamp;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.timestamp = timestamp;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.timestamp = timestamp;
|
||||
}
|
||||
@@ -236,6 +254,9 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
ExecutionPayloadHeaderRefMut::Electra(header) => {
|
||||
header.withdrawals_root = withdrawals_root;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.withdrawals_root = withdrawals_root;
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.withdrawals_root = withdrawals_root;
|
||||
}
|
||||
@@ -268,6 +289,10 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
|
||||
header.extra_data = extra_data;
|
||||
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Eip7805(header) => {
|
||||
header.extra_data = extra_data;
|
||||
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
|
||||
}
|
||||
ExecutionPayloadHeaderRefMut::Fulu(header) => {
|
||||
header.extra_data = extra_data;
|
||||
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
|
||||
@@ -454,6 +479,9 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
SignedBlindedBeaconBlock::Electra(block) => {
|
||||
block.message.body.execution_payload.tree_hash_root()
|
||||
}
|
||||
SignedBlindedBeaconBlock::Eip7805(block) => {
|
||||
block.message.body.execution_payload.tree_hash_root()
|
||||
}
|
||||
SignedBlindedBeaconBlock::Fulu(block) => {
|
||||
block.message.body.execution_payload.tree_hash_root()
|
||||
}
|
||||
@@ -552,6 +580,18 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
pubkey: self.builder_sk.public_key().compress(),
|
||||
execution_requests: maybe_requests.unwrap_or_default(),
|
||||
}),
|
||||
ForkName::Eip7805 => BuilderBid::Eip7805(BuilderBidEip7805 {
|
||||
header: payload
|
||||
.as_eip7805()
|
||||
.map_err(|_| "incorrect payload variant".to_string())?
|
||||
.into(),
|
||||
blob_kzg_commitments: maybe_blobs_bundle
|
||||
.map(|b| b.commitments)
|
||||
.unwrap_or_default(),
|
||||
value: self.get_bid_value(value),
|
||||
pubkey: self.builder_sk.public_key().compress(),
|
||||
execution_requests: maybe_requests.unwrap_or_default(),
|
||||
}),
|
||||
ForkName::Electra => BuilderBid::Electra(BuilderBidElectra {
|
||||
header: payload
|
||||
.as_electra()
|
||||
@@ -845,13 +885,15 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
expected_withdrawals,
|
||||
None,
|
||||
),
|
||||
ForkName::Deneb | ForkName::Electra | ForkName::Fulu => PayloadAttributes::new(
|
||||
timestamp,
|
||||
*prev_randao,
|
||||
fee_recipient,
|
||||
expected_withdrawals,
|
||||
Some(head_block_root),
|
||||
),
|
||||
ForkName::Deneb | ForkName::Electra | ForkName::Eip7805 | ForkName::Fulu => {
|
||||
PayloadAttributes::new(
|
||||
timestamp,
|
||||
*prev_randao,
|
||||
fee_recipient,
|
||||
expected_withdrawals,
|
||||
Some(head_block_root),
|
||||
)
|
||||
}
|
||||
ForkName::Base | ForkName::Altair => {
|
||||
return Err("invalid fork".to_string());
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap()),
|
||||
Arc::new(spec),
|
||||
None,
|
||||
@@ -42,6 +43,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
shanghai_time: Option<u64>,
|
||||
cancun_time: Option<u64>,
|
||||
prague_time: Option<u64>,
|
||||
eip7805_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
jwt_key: Option<JwtKey>,
|
||||
spec: Arc<ChainSpec>,
|
||||
@@ -59,6 +61,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
shanghai_time,
|
||||
cancun_time,
|
||||
prague_time,
|
||||
eip7805_time,
|
||||
osaka_time,
|
||||
spec.clone(),
|
||||
kzg,
|
||||
|
||||
@@ -86,6 +86,7 @@ pub struct MockExecutionConfig {
|
||||
pub shanghai_time: Option<u64>,
|
||||
pub cancun_time: Option<u64>,
|
||||
pub prague_time: Option<u64>,
|
||||
pub eip7805_time: Option<u64>,
|
||||
pub osaka_time: Option<u64>,
|
||||
}
|
||||
|
||||
@@ -100,6 +101,7 @@ impl Default for MockExecutionConfig {
|
||||
shanghai_time: None,
|
||||
cancun_time: None,
|
||||
prague_time: None,
|
||||
eip7805_time: None,
|
||||
osaka_time: None,
|
||||
}
|
||||
}
|
||||
@@ -123,6 +125,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
None, // FIXME(capella): should this be the default?
|
||||
None, // FIXME(deneb): should this be the default?
|
||||
None, // FIXME(electra): should this be the default?
|
||||
None,
|
||||
None, // FIXME(fulu): should this be the default?
|
||||
chain_spec,
|
||||
None,
|
||||
@@ -145,6 +148,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
shanghai_time,
|
||||
cancun_time,
|
||||
prague_time,
|
||||
eip7805_time,
|
||||
osaka_time,
|
||||
} = config;
|
||||
let last_echo_request = Arc::new(RwLock::new(None));
|
||||
@@ -156,6 +160,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
shanghai_time,
|
||||
cancun_time,
|
||||
prague_time,
|
||||
eip7805_time,
|
||||
osaka_time,
|
||||
spec,
|
||||
kzg,
|
||||
@@ -220,6 +225,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
shanghai_time: Option<u64>,
|
||||
cancun_time: Option<u64>,
|
||||
prague_time: Option<u64>,
|
||||
eip7805_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
spec: Arc<ChainSpec>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
@@ -235,6 +241,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
shanghai_time,
|
||||
cancun_time,
|
||||
prague_time,
|
||||
eip7805_time,
|
||||
osaka_time,
|
||||
},
|
||||
spec,
|
||||
|
||||
Reference in New Issue
Block a user