Skip to content

Commit d74b2d9

Browse files
authored
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 commit 6d10456. * Revert "Update builder api for electra" This reverts commit c5c9aca. * Simplify pre-activation sorting * Fix stale validators used in upgrade_to_electra * Merge branch 'unstable' into electra-alpha7
1 parent 02cb2d6 commit d74b2d9

File tree

25 files changed

+521
-339
lines changed

25 files changed

+521
-339
lines changed

beacon_node/execution_layer/src/block_hash.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use keccak_hash::KECCAK_EMPTY_LIST_RLP;
77
use triehash::ordered_trie_root;
88
use types::{
99
EncodableExecutionBlockHeader, EthSpec, ExecutionBlockHash, ExecutionBlockHeader,
10-
ExecutionPayloadRef, Hash256,
10+
ExecutionPayloadRef, ExecutionRequests, Hash256,
1111
};
1212

1313
/// Calculate the block hash of an execution block.
@@ -17,6 +17,7 @@ use types::{
1717
pub fn calculate_execution_block_hash<E: EthSpec>(
1818
payload: ExecutionPayloadRef<E>,
1919
parent_beacon_block_root: Option<Hash256>,
20+
execution_requests: Option<&ExecutionRequests<E>>,
2021
) -> (ExecutionBlockHash, Hash256) {
2122
// Calculate the transactions root.
2223
// 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>(
3839

3940
let rlp_blob_gas_used = payload.blob_gas_used().ok();
4041
let rlp_excess_blob_gas = payload.excess_blob_gas().ok();
42+
let requests_root = execution_requests.map(|requests| requests.requests_hash());
4143

4244
// Construct the block header.
4345
let exec_block_header = ExecutionBlockHeader::from_payload(
@@ -48,6 +50,7 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
4850
rlp_blob_gas_used,
4951
rlp_excess_blob_gas,
5052
parent_beacon_block_root,
53+
requests_root,
5154
);
5255

5356
// Hash the RLP encoding of the block header.
@@ -118,6 +121,7 @@ mod test {
118121
blob_gas_used: None,
119122
excess_blob_gas: None,
120123
parent_beacon_block_root: None,
124+
requests_root: None,
121125
};
122126
let expected_rlp = "f90200a0e0a94a7a3c9617401586b1a27025d2d9671332d22d540e0af72b069170380f2aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0ec3c94b18b8a1cff7d60f8d258ec723312932928626b4c9355eb4ab3568ec7f7a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000000000088000000000000000082036b";
123127
let expected_hash =
@@ -149,6 +153,7 @@ mod test {
149153
blob_gas_used: None,
150154
excess_blob_gas: None,
151155
parent_beacon_block_root: None,
156+
requests_root: None,
152157
};
153158
let expected_rlp = "f901fda0927ca537f06c783a3a2635b8805eef1c8c2124f7444ad4a3389898dd832f2dbea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0e97859b065bd8dbbb4519c7cb935024de2484c2b7f881181b4360492f0b06b82a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000002000088000000000000000082036b";
154159
let expected_hash =
@@ -181,6 +186,7 @@ mod test {
181186
blob_gas_used: None,
182187
excess_blob_gas: None,
183188
parent_beacon_block_root: None,
189+
requests_root: None,
184190
};
185191
let expected_hash =
186192
Hash256::from_str("6da69709cd5a34079b6604d29cd78fc01dacd7c6268980057ad92a2bede87351")
@@ -211,6 +217,7 @@ mod test {
211217
blob_gas_used: Some(0x0u64),
212218
excess_blob_gas: Some(0x0u64),
213219
parent_beacon_block_root: Some(Hash256::from_str("f7d327d2c04e4f12e9cdd492e53d39a1d390f8b1571e3b2a22ac6e1e170e5b1a").unwrap()),
220+
requests_root: None,
214221
};
215222
let expected_hash =
216223
Hash256::from_str("a7448e600ead0a23d16f96aa46e8dea9eef8a7c5669a5f0a5ff32709afe9c408")
@@ -221,29 +228,30 @@ mod test {
221228
#[test]
222229
fn test_rlp_encode_block_electra() {
223230
let header = ExecutionBlockHeader {
224-
parent_hash: Hash256::from_str("172864416698b842f4c92f7b476be294b4ef720202779df194cd225f531053ab").unwrap(),
231+
parent_hash: Hash256::from_str("a628f146df398a339768bd101f7dc41d828be79aca5dd02cc878a51bdbadd761").unwrap(),
225232
ommers_hash: Hash256::from_str("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap(),
226-
beneficiary: Address::from_str("878705ba3f8bc32fcf7f4caa1a35e72af65cf766").unwrap(),
227-
state_root: Hash256::from_str("c6457d0df85c84c62d1c68f68138b6e796e8a44fb44de221386fb2d5611c41e0").unwrap(),
228-
transactions_root: Hash256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap(),
229-
receipts_root: Hash256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap(),
230-
logs_bloom:<[u8; 256]>::from_hex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap().into(),
233+
beneficiary: Address::from_str("f97e180c050e5ab072211ad2c213eb5aee4df134").unwrap(),
234+
state_root: Hash256::from_str("fdff009f8280bd113ebb4df8ce4e2dcc9322d43184a0b506e70b7f4823ca1253").unwrap(),
235+
transactions_root: Hash256::from_str("452806578b4fa881cafb019c47e767e37e2249accf859159f00cddefb2579bb5").unwrap(),
236+
receipts_root: Hash256::from_str("72ceac0f16a32041c881b3220d39ca506a286bef163c01a4d0821cd4027d31c7").unwrap(),
237+
logs_bloom:<[u8; 256]>::from_hex("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000").unwrap().into(),
231238
difficulty: Uint256::ZERO,
232-
number: Uint256::from(97),
233-
gas_limit: Uint256::from(27482534),
234-
gas_used: Uint256::ZERO,
235-
timestamp: 1692132829u64,
236-
extra_data: hex::decode("d883010d00846765746888676f312e32302e37856c696e7578").unwrap(),
237-
mix_hash: Hash256::from_str("0b493c22d2ad4ca76c77ae6ad916af429b42b1dc98fdcb8e5ddbd049bbc5d623").unwrap(),
239+
number: Uint256::from(8230),
240+
gas_limit: Uint256::from(30000000),
241+
gas_used: Uint256::from(3716848),
242+
timestamp: 1730921268,
243+
extra_data: hex::decode("d883010e0c846765746888676f312e32332e32856c696e7578").unwrap(),
244+
mix_hash: Hash256::from_str("e87ca9a45b2e61bbe9080d897db1d584b5d2367d22e898af901091883b7b96ec").unwrap(),
238245
nonce: Hash64::ZERO,
239-
base_fee_per_gas: Uint256::from(2374u64),
246+
base_fee_per_gas: Uint256::from(7u64),
240247
withdrawals_root: Some(Hash256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap()),
241-
blob_gas_used: Some(0x0u64),
242-
excess_blob_gas: Some(0x0u64),
243-
parent_beacon_block_root: Some(Hash256::from_str("f7d327d2c04e4f12e9cdd492e53d39a1d390f8b1571e3b2a22ac6e1e170e5b1a").unwrap()),
248+
blob_gas_used: Some(786432),
249+
excess_blob_gas: Some(44695552),
250+
parent_beacon_block_root: Some(Hash256::from_str("f3a888fee010ebb1ae083547004e96c254b240437823326fdff8354b1fc25629").unwrap()),
251+
requests_root: Some(Hash256::from_str("9440d3365f07573919e1e9ac5178c20ec6fe267357ee4baf8b6409901f331b62").unwrap()),
244252
};
245253
let expected_hash =
246-
Hash256::from_str("a7448e600ead0a23d16f96aa46e8dea9eef8a7c5669a5f0a5ff32709afe9c408")
254+
Hash256::from_str("61e67afc96bf21be6aab52c1ace1db48de7b83f03119b0644deb4b69e87e09e1")
247255
.unwrap();
248256
test_rlp_encoding(&header, None, expected_hash);
249257
}

beacon_node/execution_layer/src/engine_api/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ impl HttpJsonRpc {
812812
new_payload_request_electra.versioned_hashes,
813813
new_payload_request_electra.parent_beacon_block_root,
814814
new_payload_request_electra
815-
.execution_requests_list
815+
.execution_requests
816816
.get_execution_requests_list(),
817817
]);
818818

beacon_node/execution_layer/src/engine_api/json_structures.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use strum::EnumString;
66
use superstruct::superstruct;
77
use types::beacon_block_body::KzgCommitments;
88
use types::blob_sidecar::BlobsList;
9-
use types::execution_requests::{ConsolidationRequests, DepositRequests, WithdrawalRequests};
9+
use types::execution_requests::{
10+
ConsolidationRequests, DepositRequests, RequestPrefix, WithdrawalRequests,
11+
};
1012
use types::{Blob, FixedVector, KzgProof, Unsigned};
1113

1214
#[derive(Debug, PartialEq, Serialize, Deserialize)]
@@ -339,25 +341,6 @@ impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
339341
}
340342
}
341343

342-
/// This is used to index into the `execution_requests` array.
343-
#[derive(Debug, Copy, Clone)]
344-
enum RequestPrefix {
345-
Deposit,
346-
Withdrawal,
347-
Consolidation,
348-
}
349-
350-
impl RequestPrefix {
351-
pub fn from_prefix(prefix: u8) -> Option<Self> {
352-
match prefix {
353-
0 => Some(Self::Deposit),
354-
1 => Some(Self::Withdrawal),
355-
2 => Some(Self::Consolidation),
356-
_ => None,
357-
}
358-
}
359-
}
360-
361344
/// Format of `ExecutionRequests` received over the engine api.
362345
///
363346
/// Array of ssz-encoded requests list encoded as hex bytes.
@@ -379,7 +362,8 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
379362

380363
for (i, request) in value.0.into_iter().enumerate() {
381364
// hex string
382-
let decoded_bytes = hex::decode(request).map_err(|e| format!("Invalid hex {:?}", e))?;
365+
let decoded_bytes = hex::decode(request.strip_prefix("0x").unwrap_or(&request))
366+
.map_err(|e| format!("Invalid hex {:?}", e))?;
383367
match RequestPrefix::from_prefix(i as u8) {
384368
Some(RequestPrefix::Deposit) => {
385369
requests.deposits = DepositRequests::<E>::from_ssz_bytes(&decoded_bytes)
@@ -431,7 +415,7 @@ pub struct JsonGetPayloadResponse<E: EthSpec> {
431415
#[superstruct(only(V3, V4))]
432416
pub should_override_builder: bool,
433417
#[superstruct(only(V4))]
434-
pub requests: JsonExecutionRequests,
418+
pub execution_requests: JsonExecutionRequests,
435419
}
436420

437421
impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
@@ -464,7 +448,7 @@ impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
464448
block_value: response.block_value,
465449
blobs_bundle: response.blobs_bundle.into(),
466450
should_override_builder: response.should_override_builder,
467-
requests: response.requests.try_into()?,
451+
requests: response.execution_requests.try_into()?,
468452
}))
469453
}
470454
}

beacon_node/execution_layer/src/engine_api/new_payload_request.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct NewPayloadRequest<'block, E: EthSpec> {
4444
#[superstruct(only(Deneb, Electra))]
4545
pub parent_beacon_block_root: Hash256,
4646
#[superstruct(only(Electra))]
47-
pub execution_requests_list: &'block ExecutionRequests<E>,
47+
pub execution_requests: &'block ExecutionRequests<E>,
4848
}
4949

5050
impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
@@ -121,8 +121,11 @@ impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
121121

122122
let _timer = metrics::start_timer(&metrics::EXECUTION_LAYER_VERIFY_BLOCK_HASH);
123123

124-
let (header_hash, rlp_transactions_root) =
125-
calculate_execution_block_hash(payload, parent_beacon_block_root);
124+
let (header_hash, rlp_transactions_root) = calculate_execution_block_hash(
125+
payload,
126+
parent_beacon_block_root,
127+
self.execution_requests().ok().copied(),
128+
);
126129

127130
if header_hash != self.block_hash() {
128131
return Err(Error::BlockHashMismatch {
@@ -185,7 +188,7 @@ impl<'a, E: EthSpec> TryFrom<BeaconBlockRef<'a, E>> for NewPayloadRequest<'a, E>
185188
.map(kzg_commitment_to_versioned_hash)
186189
.collect(),
187190
parent_beacon_block_root: block_ref.parent_root,
188-
execution_requests_list: &block_ref.body.execution_requests,
191+
execution_requests: &block_ref.body.execution_requests,
189192
})),
190193
}
191194
}

beacon_node/execution_layer/src/test_utils/handle_rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ pub async fn handle_rpc<E: EthSpec>(
374374
.into(),
375375
should_override_builder: false,
376376
// TODO(electra): add EL requests in mock el
377-
requests: Default::default(),
377+
execution_requests: Default::default(),
378378
})
379379
.unwrap()
380380
}

beacon_node/store/src/partial_beacon_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ where
136136
pub earliest_consolidation_epoch: Epoch,
137137

138138
#[superstruct(only(Electra))]
139-
pub pending_balance_deposits: List<PendingBalanceDeposit, E::PendingBalanceDepositsLimit>,
139+
pub pending_deposits: List<PendingDeposit, E::PendingDepositsLimit>,
140140
#[superstruct(only(Electra))]
141141
pub pending_partial_withdrawals:
142142
List<PendingPartialWithdrawal, E::PendingPartialWithdrawalsLimit>,
@@ -403,7 +403,7 @@ impl<E: EthSpec> TryInto<BeaconState<E>> for PartialBeaconState<E> {
403403
earliest_exit_epoch,
404404
consolidation_balance_to_consume,
405405
earliest_consolidation_epoch,
406-
pending_balance_deposits,
406+
pending_deposits,
407407
pending_partial_withdrawals,
408408
pending_consolidations
409409
],

consensus/state_processing/src/per_block_processing.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
514514
// Consume pending partial withdrawals
515515
let partial_withdrawals_count =
516516
if let Ok(partial_withdrawals) = state.pending_partial_withdrawals() {
517+
let mut partial_withdrawals_count = 0;
517518
for withdrawal in partial_withdrawals {
518519
if withdrawal.withdrawable_epoch > epoch
519520
|| withdrawals.len() == spec.max_pending_partials_per_withdrawals_sweep as usize
@@ -546,8 +547,9 @@ pub fn get_expected_withdrawals<E: EthSpec>(
546547
});
547548
withdrawal_index.safe_add_assign(1)?;
548549
}
550+
partial_withdrawals_count.safe_add_assign(1)?;
549551
}
550-
Some(withdrawals.len())
552+
Some(partial_withdrawals_count)
551553
} else {
552554
None
553555
};

0 commit comments

Comments
 (0)