mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-01 05:37:05 +00:00
heze boilerplate
This commit is contained in:
@@ -26,7 +26,8 @@ use tree_hash_derive::TreeHash;
|
||||
use types::{
|
||||
Blob, ChainSpec, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadBellatrix,
|
||||
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra, ExecutionPayloadFulu,
|
||||
ExecutionPayloadGloas, ExecutionPayloadHeader, ExecutionRequests, ForkName, Hash256, KzgProofs,
|
||||
ExecutionPayloadGloas, ExecutionPayloadHeze, ExecutionPayloadHeader, ExecutionRequests,
|
||||
ForkName, Hash256, KzgProofs,
|
||||
Transaction, Transactions, Uint256,
|
||||
};
|
||||
|
||||
@@ -155,6 +156,7 @@ pub struct ExecutionBlockGenerator<E: EthSpec> {
|
||||
pub prague_time: Option<u64>, // electra
|
||||
pub osaka_time: Option<u64>, // fulu
|
||||
pub amsterdam_time: Option<u64>, // gloas
|
||||
pub heze_time: Option<u64>, // heze
|
||||
/*
|
||||
* deneb stuff
|
||||
*/
|
||||
@@ -185,6 +187,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
prague_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
amsterdam_time: Option<u64>,
|
||||
heze_time: Option<u64>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
) -> Self {
|
||||
let mut generator = Self {
|
||||
@@ -204,6 +207,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
heze_time,
|
||||
blobs_bundles: <_>::default(),
|
||||
kzg,
|
||||
rng: make_rng(),
|
||||
@@ -255,6 +259,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
|
||||
pub fn get_fork_at_timestamp(&self, timestamp: u64) -> ForkName {
|
||||
let forks = [
|
||||
(self.heze_time, ForkName::Heze),
|
||||
(self.amsterdam_time, ForkName::Gloas),
|
||||
(self.osaka_time, ForkName::Fulu),
|
||||
(self.prague_time, ForkName::Electra),
|
||||
@@ -778,6 +783,27 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
block_access_list: VariableList::empty(),
|
||||
slot_number: pa.slot_number.into(),
|
||||
}),
|
||||
ForkName::Heze => ExecutionPayload::Heze(ExecutionPayloadHeze {
|
||||
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].try_into().unwrap(),
|
||||
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: "block gen was here".as_bytes().to_vec().try_into().unwrap(),
|
||||
base_fee_per_gas: Uint256::from(1u64),
|
||||
block_hash: ExecutionBlockHash::zero(),
|
||||
transactions: vec![].try_into().unwrap(),
|
||||
withdrawals: pa.withdrawals.clone().try_into().unwrap(),
|
||||
blob_gas_used: 0,
|
||||
excess_blob_gas: 0,
|
||||
block_access_list: VariableList::empty(),
|
||||
slot_number: pa.slot_number.into(),
|
||||
}),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
};
|
||||
@@ -969,6 +995,14 @@ pub fn generate_genesis_header<E: EthSpec>(spec: &ChainSpec) -> Option<Execution
|
||||
*header.transactions_root_mut() = empty_transactions_root;
|
||||
Some(header)
|
||||
}
|
||||
ForkName::Heze => {
|
||||
// TODO(heze): we are using a Fulu header for now, but this gets fixed up by the
|
||||
// genesis builder anyway which translates it to bid/latest_block_hash.
|
||||
let mut header = ExecutionPayloadHeader::Fulu(<_>::default());
|
||||
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
|
||||
*header.transactions_root_mut() = empty_transactions_root;
|
||||
Some(header)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,9 +126,16 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
.map(|jep| JsonExecutionPayload::Electra(jep))
|
||||
})
|
||||
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?,
|
||||
ENGINE_NEW_PAYLOAD_V5 => get_param::<JsonExecutionPayloadGloas<E>>(params, 0)
|
||||
.map(|jep| JsonExecutionPayload::Gloas(jep))
|
||||
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?,
|
||||
ENGINE_NEW_PAYLOAD_V5 => {
|
||||
// Try Heze first, fall back to Gloas
|
||||
get_param::<JsonExecutionPayloadHeze<E>>(params, 0)
|
||||
.map(|jep| JsonExecutionPayload::Heze(jep))
|
||||
.or_else(|_| {
|
||||
get_param::<JsonExecutionPayloadGloas<E>>(params, 0)
|
||||
.map(|jep| JsonExecutionPayload::Gloas(jep))
|
||||
})
|
||||
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
@@ -238,6 +245,14 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
));
|
||||
}
|
||||
}
|
||||
ForkName::Heze => {
|
||||
if method != ENGINE_NEW_PAYLOAD_V5 {
|
||||
return Err((
|
||||
format!("{} called after Heze fork!", method),
|
||||
GENERIC_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
@@ -377,6 +392,24 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
));
|
||||
}
|
||||
|
||||
// validate method called correctly according to heze fork time
|
||||
if ctx
|
||||
.execution_block_generator
|
||||
.read()
|
||||
.get_fork_at_timestamp(response.timestamp())
|
||||
== ForkName::Heze
|
||||
&& (method == ENGINE_GET_PAYLOAD_V1
|
||||
|| method == ENGINE_GET_PAYLOAD_V2
|
||||
|| method == ENGINE_GET_PAYLOAD_V3
|
||||
|| method == ENGINE_GET_PAYLOAD_V4
|
||||
|| method == ENGINE_GET_PAYLOAD_V5)
|
||||
{
|
||||
return Err((
|
||||
format!("{} called after Heze fork!", method),
|
||||
FORK_REQUEST_MISMATCH_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
|
||||
match method {
|
||||
ENGINE_GET_PAYLOAD_V1 => Ok(serde_json::to_value(
|
||||
JsonExecutionPayload::try_from(response).unwrap(),
|
||||
@@ -488,6 +521,23 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
JsonExecutionPayload::Heze(execution_payload) => {
|
||||
serde_json::to_value(JsonGetPayloadResponseHeze {
|
||||
execution_payload,
|
||||
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
|
||||
blobs_bundle: maybe_blobs
|
||||
.ok_or((
|
||||
"No blobs returned despite V6 Payload".to_string(),
|
||||
GENERIC_ERROR_CODE,
|
||||
))?
|
||||
.into(),
|
||||
should_override_builder: false,
|
||||
execution_requests: maybe_execution_requests
|
||||
.unwrap_or_default()
|
||||
.into(),
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
@@ -653,6 +703,14 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
));
|
||||
}
|
||||
}
|
||||
ForkName::Heze => {
|
||||
if method != ENGINE_FORKCHOICE_UPDATED_V4 {
|
||||
return Err((
|
||||
format!("{} called after Heze fork! Use V4.", method),
|
||||
FORK_REQUEST_MISMATCH_ERROR_CODE,
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -475,6 +475,10 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
// TODO(EIP7732) Check if this is how we want to do error handling for gloas
|
||||
return Err("invalid fork".to_string());
|
||||
}
|
||||
SignedBlindedBeaconBlock::Heze(_) => {
|
||||
// TODO(EIP7732) Check if this is how we want to do error handling for heze
|
||||
return Err("invalid fork".to_string());
|
||||
}
|
||||
};
|
||||
let block_hash = block
|
||||
.message()
|
||||
@@ -593,6 +597,10 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
// TODO(EIP7732) Check if this is how we want to do error handling for gloas
|
||||
return Err("invalid fork".to_string());
|
||||
}
|
||||
ForkName::Heze => {
|
||||
// TODO(EIP7732) Check if this is how we want to do error handling for heze
|
||||
return Err("invalid fork".to_string());
|
||||
}
|
||||
ForkName::Fulu => BuilderBid::Fulu(BuilderBidFulu {
|
||||
header: payload
|
||||
.as_fulu()
|
||||
@@ -912,7 +920,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
Some(head_block_root),
|
||||
None,
|
||||
),
|
||||
ForkName::Gloas => PayloadAttributes::new(
|
||||
ForkName::Gloas | ForkName::Heze => PayloadAttributes::new(
|
||||
timestamp,
|
||||
*prev_randao,
|
||||
fee_recipient,
|
||||
|
||||
@@ -24,6 +24,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap()),
|
||||
Arc::new(spec),
|
||||
None,
|
||||
@@ -38,6 +39,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
prague_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
amsterdam_time: Option<u64>,
|
||||
heze_time: Option<u64>,
|
||||
jwt_key: Option<JwtKey>,
|
||||
spec: Arc<ChainSpec>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
@@ -53,6 +55,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
heze_time,
|
||||
kzg,
|
||||
);
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ pub struct MockExecutionConfig {
|
||||
pub prague_time: Option<u64>,
|
||||
pub osaka_time: Option<u64>,
|
||||
pub amsterdam_time: Option<u64>,
|
||||
pub heze_time: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for MockExecutionConfig {
|
||||
@@ -98,6 +99,7 @@ impl Default for MockExecutionConfig {
|
||||
prague_time: None,
|
||||
osaka_time: None,
|
||||
amsterdam_time: None,
|
||||
heze_time: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,6 +121,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
None, // FIXME(electra): should this be the default?
|
||||
None, // FIXME(fulu): should this be the default?
|
||||
None, // FIXME(gloas): should this be the default?
|
||||
None, // FIXME(heze): should this be the default?
|
||||
None,
|
||||
)
|
||||
}
|
||||
@@ -137,6 +140,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
heze_time,
|
||||
} = config;
|
||||
let last_echo_request = Arc::new(RwLock::new(None));
|
||||
let preloaded_responses = Arc::new(Mutex::new(vec![]));
|
||||
@@ -146,6 +150,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
heze_time,
|
||||
kzg,
|
||||
);
|
||||
|
||||
@@ -207,6 +212,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
prague_time: Option<u64>,
|
||||
osaka_time: Option<u64>,
|
||||
amsterdam_time: Option<u64>,
|
||||
heze_time: Option<u64>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
) -> Self {
|
||||
Self::new_with_config(
|
||||
@@ -219,6 +225,7 @@ impl<E: EthSpec> MockServer<E> {
|
||||
prague_time,
|
||||
osaka_time,
|
||||
amsterdam_time,
|
||||
heze_time,
|
||||
},
|
||||
kzg,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user