mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 16:51:41 +00:00
Electra alpha8 spec updates (#6496)
* Fix partial withdrawals count * Remove get_active_balance * Remove queue_entire_balance_and_reset_validator * Switch to compounding when consolidating with source==target * Queue deposit requests and apply them during epoch processing * Fix ef tests * Clear todos * Fix engine api formatting issues * Merge branch 'unstable' into electra-alpha7 * Make add_validator_to_registry more in line with the spec * Address some review comments * Cleanup * Update initialize_beacon_state_from_eth1 * Merge branch 'unstable' into electra-alpha7 * Fix rpc decoding for blobs by range/root * Fix block hash computation * Fix process_deposits bug * Merge branch 'unstable' into electra-alpha7 * Fix topup deposit processing bug * Update builder api for electra * Refactor mock builder to separate functionality * Merge branch 'unstable' into electra-alpha7 * Address review comments * Use copied for reference rather than cloned * Optimise and simplify PendingDepositsContext::new * Merge remote-tracking branch 'origin/unstable' into electra-alpha7 * Fix processing of deposits with invalid signatures * Remove redundant code in genesis init * Revert "Refactor mock builder to separate functionality" This reverts commit6d10456912. * Revert "Update builder api for electra" This reverts commitc5c9aca6db. * Simplify pre-activation sorting * Fix stale validators used in upgrade_to_electra * Merge branch 'unstable' into electra-alpha7
This commit is contained in:
@@ -7,7 +7,7 @@ use keccak_hash::KECCAK_EMPTY_LIST_RLP;
|
||||
use triehash::ordered_trie_root;
|
||||
use types::{
|
||||
EncodableExecutionBlockHeader, EthSpec, ExecutionBlockHash, ExecutionBlockHeader,
|
||||
ExecutionPayloadRef, Hash256,
|
||||
ExecutionPayloadRef, ExecutionRequests, Hash256,
|
||||
};
|
||||
|
||||
/// Calculate the block hash of an execution block.
|
||||
@@ -17,6 +17,7 @@ use types::{
|
||||
pub fn calculate_execution_block_hash<E: EthSpec>(
|
||||
payload: ExecutionPayloadRef<E>,
|
||||
parent_beacon_block_root: Option<Hash256>,
|
||||
execution_requests: Option<&ExecutionRequests<E>>,
|
||||
) -> (ExecutionBlockHash, Hash256) {
|
||||
// Calculate the transactions root.
|
||||
// We're currently using a deprecated Parity library for this. We should move to a
|
||||
@@ -38,6 +39,7 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
|
||||
|
||||
let rlp_blob_gas_used = payload.blob_gas_used().ok();
|
||||
let rlp_excess_blob_gas = payload.excess_blob_gas().ok();
|
||||
let requests_root = execution_requests.map(|requests| requests.requests_hash());
|
||||
|
||||
// Construct the block header.
|
||||
let exec_block_header = ExecutionBlockHeader::from_payload(
|
||||
@@ -48,6 +50,7 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
|
||||
rlp_blob_gas_used,
|
||||
rlp_excess_blob_gas,
|
||||
parent_beacon_block_root,
|
||||
requests_root,
|
||||
);
|
||||
|
||||
// Hash the RLP encoding of the block header.
|
||||
@@ -118,6 +121,7 @@ mod test {
|
||||
blob_gas_used: None,
|
||||
excess_blob_gas: None,
|
||||
parent_beacon_block_root: None,
|
||||
requests_root: None,
|
||||
};
|
||||
let expected_rlp = "f90200a0e0a94a7a3c9617401586b1a27025d2d9671332d22d540e0af72b069170380f2aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0ec3c94b18b8a1cff7d60f8d258ec723312932928626b4c9355eb4ab3568ec7f7a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000000000088000000000000000082036b";
|
||||
let expected_hash =
|
||||
@@ -149,6 +153,7 @@ mod test {
|
||||
blob_gas_used: None,
|
||||
excess_blob_gas: None,
|
||||
parent_beacon_block_root: None,
|
||||
requests_root: None,
|
||||
};
|
||||
let expected_rlp = "f901fda0927ca537f06c783a3a2635b8805eef1c8c2124f7444ad4a3389898dd832f2dbea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0e97859b065bd8dbbb4519c7cb935024de2484c2b7f881181b4360492f0b06b82a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000002000088000000000000000082036b";
|
||||
let expected_hash =
|
||||
@@ -181,6 +186,7 @@ mod test {
|
||||
blob_gas_used: None,
|
||||
excess_blob_gas: None,
|
||||
parent_beacon_block_root: None,
|
||||
requests_root: None,
|
||||
};
|
||||
let expected_hash =
|
||||
Hash256::from_str("6da69709cd5a34079b6604d29cd78fc01dacd7c6268980057ad92a2bede87351")
|
||||
@@ -211,6 +217,7 @@ mod test {
|
||||
blob_gas_used: Some(0x0u64),
|
||||
excess_blob_gas: Some(0x0u64),
|
||||
parent_beacon_block_root: Some(Hash256::from_str("f7d327d2c04e4f12e9cdd492e53d39a1d390f8b1571e3b2a22ac6e1e170e5b1a").unwrap()),
|
||||
requests_root: None,
|
||||
};
|
||||
let expected_hash =
|
||||
Hash256::from_str("a7448e600ead0a23d16f96aa46e8dea9eef8a7c5669a5f0a5ff32709afe9c408")
|
||||
@@ -221,29 +228,30 @@ mod test {
|
||||
#[test]
|
||||
fn test_rlp_encode_block_electra() {
|
||||
let header = ExecutionBlockHeader {
|
||||
parent_hash: Hash256::from_str("172864416698b842f4c92f7b476be294b4ef720202779df194cd225f531053ab").unwrap(),
|
||||
parent_hash: Hash256::from_str("a628f146df398a339768bd101f7dc41d828be79aca5dd02cc878a51bdbadd761").unwrap(),
|
||||
ommers_hash: Hash256::from_str("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap(),
|
||||
beneficiary: Address::from_str("878705ba3f8bc32fcf7f4caa1a35e72af65cf766").unwrap(),
|
||||
state_root: Hash256::from_str("c6457d0df85c84c62d1c68f68138b6e796e8a44fb44de221386fb2d5611c41e0").unwrap(),
|
||||
transactions_root: Hash256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap(),
|
||||
receipts_root: Hash256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap(),
|
||||
logs_bloom:<[u8; 256]>::from_hex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap().into(),
|
||||
beneficiary: Address::from_str("f97e180c050e5ab072211ad2c213eb5aee4df134").unwrap(),
|
||||
state_root: Hash256::from_str("fdff009f8280bd113ebb4df8ce4e2dcc9322d43184a0b506e70b7f4823ca1253").unwrap(),
|
||||
transactions_root: Hash256::from_str("452806578b4fa881cafb019c47e767e37e2249accf859159f00cddefb2579bb5").unwrap(),
|
||||
receipts_root: Hash256::from_str("72ceac0f16a32041c881b3220d39ca506a286bef163c01a4d0821cd4027d31c7").unwrap(),
|
||||
logs_bloom:<[u8; 256]>::from_hex("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000").unwrap().into(),
|
||||
difficulty: Uint256::ZERO,
|
||||
number: Uint256::from(97),
|
||||
gas_limit: Uint256::from(27482534),
|
||||
gas_used: Uint256::ZERO,
|
||||
timestamp: 1692132829u64,
|
||||
extra_data: hex::decode("d883010d00846765746888676f312e32302e37856c696e7578").unwrap(),
|
||||
mix_hash: Hash256::from_str("0b493c22d2ad4ca76c77ae6ad916af429b42b1dc98fdcb8e5ddbd049bbc5d623").unwrap(),
|
||||
number: Uint256::from(8230),
|
||||
gas_limit: Uint256::from(30000000),
|
||||
gas_used: Uint256::from(3716848),
|
||||
timestamp: 1730921268,
|
||||
extra_data: hex::decode("d883010e0c846765746888676f312e32332e32856c696e7578").unwrap(),
|
||||
mix_hash: Hash256::from_str("e87ca9a45b2e61bbe9080d897db1d584b5d2367d22e898af901091883b7b96ec").unwrap(),
|
||||
nonce: Hash64::ZERO,
|
||||
base_fee_per_gas: Uint256::from(2374u64),
|
||||
base_fee_per_gas: Uint256::from(7u64),
|
||||
withdrawals_root: Some(Hash256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap()),
|
||||
blob_gas_used: Some(0x0u64),
|
||||
excess_blob_gas: Some(0x0u64),
|
||||
parent_beacon_block_root: Some(Hash256::from_str("f7d327d2c04e4f12e9cdd492e53d39a1d390f8b1571e3b2a22ac6e1e170e5b1a").unwrap()),
|
||||
blob_gas_used: Some(786432),
|
||||
excess_blob_gas: Some(44695552),
|
||||
parent_beacon_block_root: Some(Hash256::from_str("f3a888fee010ebb1ae083547004e96c254b240437823326fdff8354b1fc25629").unwrap()),
|
||||
requests_root: Some(Hash256::from_str("9440d3365f07573919e1e9ac5178c20ec6fe267357ee4baf8b6409901f331b62").unwrap()),
|
||||
};
|
||||
let expected_hash =
|
||||
Hash256::from_str("a7448e600ead0a23d16f96aa46e8dea9eef8a7c5669a5f0a5ff32709afe9c408")
|
||||
Hash256::from_str("61e67afc96bf21be6aab52c1ace1db48de7b83f03119b0644deb4b69e87e09e1")
|
||||
.unwrap();
|
||||
test_rlp_encoding(&header, None, expected_hash);
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ impl HttpJsonRpc {
|
||||
new_payload_request_electra.versioned_hashes,
|
||||
new_payload_request_electra.parent_beacon_block_root,
|
||||
new_payload_request_electra
|
||||
.execution_requests_list
|
||||
.execution_requests
|
||||
.get_execution_requests_list(),
|
||||
]);
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ use strum::EnumString;
|
||||
use superstruct::superstruct;
|
||||
use types::beacon_block_body::KzgCommitments;
|
||||
use types::blob_sidecar::BlobsList;
|
||||
use types::execution_requests::{ConsolidationRequests, DepositRequests, WithdrawalRequests};
|
||||
use types::execution_requests::{
|
||||
ConsolidationRequests, DepositRequests, RequestPrefix, WithdrawalRequests,
|
||||
};
|
||||
use types::{Blob, FixedVector, KzgProof, Unsigned};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -339,25 +341,6 @@ impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// This is used to index into the `execution_requests` array.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
enum RequestPrefix {
|
||||
Deposit,
|
||||
Withdrawal,
|
||||
Consolidation,
|
||||
}
|
||||
|
||||
impl RequestPrefix {
|
||||
pub fn from_prefix(prefix: u8) -> Option<Self> {
|
||||
match prefix {
|
||||
0 => Some(Self::Deposit),
|
||||
1 => Some(Self::Withdrawal),
|
||||
2 => Some(Self::Consolidation),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Format of `ExecutionRequests` received over the engine api.
|
||||
///
|
||||
/// Array of ssz-encoded requests list encoded as hex bytes.
|
||||
@@ -379,7 +362,8 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
|
||||
|
||||
for (i, request) in value.0.into_iter().enumerate() {
|
||||
// hex string
|
||||
let decoded_bytes = hex::decode(request).map_err(|e| format!("Invalid hex {:?}", e))?;
|
||||
let decoded_bytes = hex::decode(request.strip_prefix("0x").unwrap_or(&request))
|
||||
.map_err(|e| format!("Invalid hex {:?}", e))?;
|
||||
match RequestPrefix::from_prefix(i as u8) {
|
||||
Some(RequestPrefix::Deposit) => {
|
||||
requests.deposits = DepositRequests::<E>::from_ssz_bytes(&decoded_bytes)
|
||||
@@ -431,7 +415,7 @@ pub struct JsonGetPayloadResponse<E: EthSpec> {
|
||||
#[superstruct(only(V3, V4))]
|
||||
pub should_override_builder: bool,
|
||||
#[superstruct(only(V4))]
|
||||
pub requests: JsonExecutionRequests,
|
||||
pub execution_requests: JsonExecutionRequests,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
|
||||
@@ -464,7 +448,7 @@ impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
requests: response.requests.try_into()?,
|
||||
requests: response.execution_requests.try_into()?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ pub struct NewPayloadRequest<'block, E: EthSpec> {
|
||||
#[superstruct(only(Deneb, Electra))]
|
||||
pub parent_beacon_block_root: Hash256,
|
||||
#[superstruct(only(Electra))]
|
||||
pub execution_requests_list: &'block ExecutionRequests<E>,
|
||||
pub execution_requests: &'block ExecutionRequests<E>,
|
||||
}
|
||||
|
||||
impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
|
||||
@@ -121,8 +121,11 @@ impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
|
||||
|
||||
let _timer = metrics::start_timer(&metrics::EXECUTION_LAYER_VERIFY_BLOCK_HASH);
|
||||
|
||||
let (header_hash, rlp_transactions_root) =
|
||||
calculate_execution_block_hash(payload, parent_beacon_block_root);
|
||||
let (header_hash, rlp_transactions_root) = calculate_execution_block_hash(
|
||||
payload,
|
||||
parent_beacon_block_root,
|
||||
self.execution_requests().ok().copied(),
|
||||
);
|
||||
|
||||
if header_hash != self.block_hash() {
|
||||
return Err(Error::BlockHashMismatch {
|
||||
@@ -185,7 +188,7 @@ impl<'a, E: EthSpec> TryFrom<BeaconBlockRef<'a, E>> for NewPayloadRequest<'a, E>
|
||||
.map(kzg_commitment_to_versioned_hash)
|
||||
.collect(),
|
||||
parent_beacon_block_root: block_ref.parent_root,
|
||||
execution_requests_list: &block_ref.body.execution_requests,
|
||||
execution_requests: &block_ref.body.execution_requests,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
.into(),
|
||||
should_override_builder: false,
|
||||
// TODO(electra): add EL requests in mock el
|
||||
requests: Default::default(),
|
||||
execution_requests: Default::default(),
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user