Skip to content

Commit

Permalink
Merge pull request #5974 from ethDreamer/electra-devnet-1
Browse files Browse the repository at this point in the history
Electra: `devnet-1` Rename and Move Stuff
  • Loading branch information
ethDreamer authored Jun 25, 2024
2 parents 48f1f40 + 1e0a3e6 commit 0168124
Show file tree
Hide file tree
Showing 34 changed files with 286 additions and 460 deletions.
2 changes: 0 additions & 2 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5359,8 +5359,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
bls_to_execution_changes: bls_to_execution_changes.into(),
blob_kzg_commitments: kzg_commitments
.ok_or(BlockProductionError::InvalidPayloadFork)?,
// TODO(electra): finish consolidations when they're more spec'd out
consolidations: Vec::new().into(),
},
}),
maybe_blobs_and_proofs,
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ impl<E: EthSpec> Eth1ChainBackend<E> for CachingEth1Backend<E> {

// [New in Electra:EIP6110]
let deposit_index_limit =
if let Ok(deposit_receipts_start_index) = state.deposit_receipts_start_index() {
std::cmp::min(deposit_count, deposit_receipts_start_index)
if let Ok(deposit_requests_start_index) = state.deposit_requests_start_index() {
std::cmp::min(deposit_count, deposit_requests_start_index)
} else {
deposit_count
};
Expand Down
33 changes: 20 additions & 13 deletions beacon_node/execution_layer/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use strum::IntoStaticStr;
use superstruct::superstruct;
use types::execution_payload::{DepositReceipts, WithdrawalRequests};
use types::execution_payload::{ConsolidationRequests, DepositRequests, WithdrawalRequests};
pub use types::{
Address, BeaconBlockRef, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadHeader,
ExecutionPayloadRef, FixedVector, ForkName, Hash256, Transactions, Uint256, VariableList,
Withdrawal, Withdrawals,
Address, BeaconBlockRef, ConsolidationRequest, EthSpec, ExecutionBlockHash, ExecutionPayload,
ExecutionPayloadHeader, ExecutionPayloadRef, FixedVector, ForkName, Hash256, Transactions,
Uint256, VariableList, Withdrawal, Withdrawals,
};
use types::{
ExecutionPayloadBellatrix, ExecutionPayloadCapella, ExecutionPayloadDeneb,
Expand Down Expand Up @@ -67,14 +67,15 @@ pub enum Error {
TransitionConfigurationMismatch,
SszError(ssz_types::Error),
DeserializeWithdrawals(ssz_types::Error),
DeserializeDepositReceipts(ssz_types::Error),
DeserializeDepositRequests(ssz_types::Error),
DeserializeWithdrawalRequests(ssz_types::Error),
BuilderApi(builder_client::Error),
IncorrectStateVariant,
RequiredMethodUnsupported(&'static str),
UnsupportedForkVariant(String),
InvalidClientVersion(String),
RlpDecoderError(rlp::DecoderError),
TooManyConsolidationRequests(usize),
}

impl From<reqwest::Error> for Error {
Expand Down Expand Up @@ -204,9 +205,12 @@ pub struct ExecutionBlockWithTransactions<E: EthSpec> {
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_blob_gas: u64,
#[superstruct(only(Electra))]
pub deposit_receipts: Vec<JsonDepositRequest>,
pub deposit_requests: Vec<JsonDepositRequest>,
#[superstruct(only(Electra))]
pub withdrawal_requests: Vec<JsonWithdrawalRequest>,
#[superstruct(only(Electra))]
// TODO(electra): I don't think we need a JsonConsolidationRequest here because the bytes should be little-endian but we need to confirm
pub consolidation_requests: Vec<ConsolidationRequest>,
}

impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions<E> {
Expand Down Expand Up @@ -314,8 +318,8 @@ impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions
.collect(),
blob_gas_used: block.blob_gas_used,
excess_blob_gas: block.excess_blob_gas,
deposit_receipts: block
.deposit_receipts
deposit_requests: block
.deposit_requests
.into_iter()
.map(|deposit| deposit.into())
.collect(),
Expand All @@ -324,6 +328,7 @@ impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions
.into_iter()
.map(|withdrawal| withdrawal.into())
.collect(),
consolidation_requests: block.consolidation_requests.to_vec(),
})
}
};
Expand Down Expand Up @@ -546,7 +551,7 @@ impl<E: EthSpec> GetPayloadResponse<E> {
pub struct ExecutionPayloadBodyV1<E: EthSpec> {
pub transactions: Transactions<E>,
pub withdrawals: Option<Withdrawals<E>>,
pub deposit_receipts: Option<DepositReceipts<E>>,
pub deposit_requests: Option<DepositRequests<E>>,
pub withdrawal_requests: Option<WithdrawalRequests<E>>,
}

Expand Down Expand Up @@ -635,13 +640,13 @@ impl<E: EthSpec> ExecutionPayloadBodyV1<E> {
}
}
ExecutionPayloadHeader::Electra(header) => {
let (Some(withdrawals), Some(deposit_receipts), Some(withdrawal_requests)) = (
let (Some(withdrawals), Some(deposit_requests), Some(withdrawal_requests)) = (
self.withdrawals,
self.deposit_receipts,
self.deposit_requests,
self.withdrawal_requests,
) else {
return Err(format!(
"block {} is post-electra but payload body doesn't have withdrawals/deposit_receipts/withdrawal_requests \
"block {} is post-electra but payload body doesn't have withdrawals/deposit_requests/withdrawal_requests \
Check that ELs are returning receipts and withdrawal_requests in getPayloadBody requests",
header.block_hash
));
Expand All @@ -664,8 +669,10 @@ impl<E: EthSpec> ExecutionPayloadBodyV1<E> {
withdrawals,
blob_gas_used: header.blob_gas_used,
excess_blob_gas: header.excess_blob_gas,
deposit_receipts,
deposit_requests,
withdrawal_requests,
// TODO(electra): gonna need to superstruct this thing to do it properly..
consolidation_requests: Vec::new().into(),
}))
}
}
Expand Down
39 changes: 22 additions & 17 deletions beacon_node/execution_layer/src/engine_api/json_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use strum::EnumString;
use superstruct::superstruct;
use types::beacon_block_body::KzgCommitments;
use types::blob_sidecar::BlobsList;
use types::{
DepositReceipt, ExecutionLayerWithdrawalRequest, FixedVector, PublicKeyBytes, Signature,
Unsigned,
};
use types::{DepositRequest, FixedVector, PublicKeyBytes, Signature, Unsigned, WithdrawalRequest};

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -105,11 +102,13 @@ pub struct JsonExecutionPayload<E: EthSpec> {
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_blob_gas: u64,
#[superstruct(only(V4))]
// TODO(electra): Field name should be changed post devnet-0. See https://github.com/ethereum/execution-apis/pull/544
pub deposit_requests: VariableList<JsonDepositRequest, E::MaxDepositReceiptsPerPayload>,
pub deposit_requests: VariableList<JsonDepositRequest, E::MaxDepositRequestsPerPayload>,
#[superstruct(only(V4))]
pub withdrawal_requests:
VariableList<JsonWithdrawalRequest, E::MaxWithdrawalRequestsPerPayload>,
#[superstruct(only(V4))]
pub consolidation_requests:
VariableList<ConsolidationRequest, E::MaxConsolidationRequestsPerPayload>,
}

impl<E: EthSpec> From<ExecutionPayloadBellatrix<E>> for JsonExecutionPayloadV1<E> {
Expand Down Expand Up @@ -213,7 +212,7 @@ impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E>
blob_gas_used: payload.blob_gas_used,
excess_blob_gas: payload.excess_blob_gas,
deposit_requests: payload
.deposit_receipts
.deposit_requests
.into_iter()
.map(Into::into)
.collect::<Vec<_>>()
Expand All @@ -224,6 +223,11 @@ impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E>
.map(Into::into)
.collect::<Vec<_>>()
.into(),
consolidation_requests: payload
.consolidation_requests
.into_iter()
.collect::<Vec<_>>()
.into(),
}
}
}
Expand Down Expand Up @@ -340,7 +344,7 @@ impl<E: EthSpec> From<JsonExecutionPayloadV4<E>> for ExecutionPayloadElectra<E>
.into(),
blob_gas_used: payload.blob_gas_used,
excess_blob_gas: payload.excess_blob_gas,
deposit_receipts: payload
deposit_requests: payload
.deposit_requests
.into_iter()
.map(Into::into)
Expand All @@ -352,6 +356,7 @@ impl<E: EthSpec> From<JsonExecutionPayloadV4<E>> for ExecutionPayloadElectra<E>
.map(Into::into)
.collect::<Vec<_>>()
.into(),
consolidation_requests: payload.consolidation_requests.into(),
}
}
}
Expand Down Expand Up @@ -725,7 +730,7 @@ pub struct JsonExecutionPayloadBodyV1<E: EthSpec> {
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
pub transactions: Transactions<E>,
pub withdrawals: Option<VariableList<JsonWithdrawal, E::MaxWithdrawalsPerPayload>>,
pub deposit_receipts: Option<VariableList<JsonDepositRequest, E::MaxDepositReceiptsPerPayload>>,
pub deposit_requests: Option<VariableList<JsonDepositRequest, E::MaxDepositRequestsPerPayload>>,
pub withdrawal_requests:
Option<VariableList<JsonWithdrawalRequest, E::MaxWithdrawalRequestsPerPayload>>,
}
Expand All @@ -742,8 +747,8 @@ impl<E: EthSpec> From<JsonExecutionPayloadBodyV1<E>> for ExecutionPayloadBodyV1<
.collect::<Vec<_>>(),
)
}),
deposit_receipts: value.deposit_receipts.map(|json_receipts| {
DepositReceipts::<E>::from(
deposit_requests: value.deposit_requests.map(|json_receipts| {
DepositRequests::<E>::from(
json_receipts
.into_iter()
.map(Into::into)
Expand Down Expand Up @@ -849,8 +854,8 @@ pub struct JsonDepositRequest {
pub index: u64,
}

impl From<DepositReceipt> for JsonDepositRequest {
fn from(deposit: DepositReceipt) -> Self {
impl From<DepositRequest> for JsonDepositRequest {
fn from(deposit: DepositRequest) -> Self {
Self {
pubkey: deposit.pubkey,
withdrawal_credentials: deposit.withdrawal_credentials,
Expand All @@ -861,7 +866,7 @@ impl From<DepositReceipt> for JsonDepositRequest {
}
}

impl From<JsonDepositRequest> for DepositReceipt {
impl From<JsonDepositRequest> for DepositRequest {
fn from(json_deposit: JsonDepositRequest) -> Self {
Self {
pubkey: json_deposit.pubkey,
Expand All @@ -882,8 +887,8 @@ pub struct JsonWithdrawalRequest {
pub amount: u64,
}

impl From<ExecutionLayerWithdrawalRequest> for JsonWithdrawalRequest {
fn from(withdrawal_request: ExecutionLayerWithdrawalRequest) -> Self {
impl From<WithdrawalRequest> for JsonWithdrawalRequest {
fn from(withdrawal_request: WithdrawalRequest) -> Self {
Self {
source_address: withdrawal_request.source_address,
validator_public_key: withdrawal_request.validator_pubkey,
Expand All @@ -892,7 +897,7 @@ impl From<ExecutionLayerWithdrawalRequest> for JsonWithdrawalRequest {
}
}

impl From<JsonWithdrawalRequest> for ExecutionLayerWithdrawalRequest {
impl From<JsonWithdrawalRequest> for WithdrawalRequest {
fn from(json_withdrawal_request: JsonWithdrawalRequest) -> Self {
Self {
source_address: json_withdrawal_request.source_address,
Expand Down
13 changes: 9 additions & 4 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,14 +1994,14 @@ impl<E: EthSpec> ExecutionLayer<E> {
.collect(),
)
.map_err(ApiError::DeserializeWithdrawals)?;
let deposit_receipts = VariableList::new(
let deposit_requests = VariableList::new(
electra_block
.deposit_receipts
.deposit_requests
.into_iter()
.map(Into::into)
.collect(),
)
.map_err(ApiError::DeserializeDepositReceipts)?;
.map_err(ApiError::DeserializeDepositRequests)?;
let withdrawal_requests = VariableList::new(
electra_block
.withdrawal_requests
Expand All @@ -2010,6 +2010,10 @@ impl<E: EthSpec> ExecutionLayer<E> {
.collect(),
)
.map_err(ApiError::DeserializeWithdrawalRequests)?;
let n_consolidations = electra_block.consolidation_requests.len();
let consolidation_requests =
VariableList::new(electra_block.consolidation_requests)
.map_err(|_| ApiError::TooManyConsolidationRequests(n_consolidations))?;
ExecutionPayload::Electra(ExecutionPayloadElectra {
parent_hash: electra_block.parent_hash,
fee_recipient: electra_block.fee_recipient,
Expand All @@ -2028,8 +2032,9 @@ impl<E: EthSpec> ExecutionLayer<E> {
withdrawals,
blob_gas_used: electra_block.blob_gas_used,
excess_blob_gas: electra_block.excess_blob_gas,
deposit_receipts,
deposit_requests,
withdrawal_requests,
consolidation_requests: consolidation_requests,
})
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,10 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
withdrawals: pa.withdrawals.clone().into(),
blob_gas_used: 0,
excess_blob_gas: 0,
deposit_receipts: vec![].into(),
// TODO(electra): consider how to test these fields below
deposit_requests: vec![].into(),
withdrawal_requests: vec![].into(),
consolidation_requests: vec![].into(),
}),
_ => unreachable!(),
},
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/execution_layer/src/test_utils/handle_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ pub async fn handle_rpc<E: EthSpec>(
.withdrawals()
.ok()
.map(|withdrawals| VariableList::from(withdrawals.clone())),
deposit_receipts: block.deposit_receipts().ok().map(
|deposit_receipts| VariableList::from(deposit_receipts.clone()),
deposit_requests: block.deposit_requests().ok().map(
|deposit_requests| VariableList::from(deposit_requests.clone()),
),
withdrawal_requests: block.withdrawal_requests().ok().map(
|withdrawal_requests| {
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/store/src/partial_beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where

// Electra
#[superstruct(only(Electra))]
pub deposit_receipts_start_index: u64,
pub deposit_requests_start_index: u64,
#[superstruct(only(Electra))]
pub deposit_balance_to_consume: u64,
#[superstruct(only(Electra))]
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<E: EthSpec> PartialBeaconState<E> {
latest_execution_payload_header,
next_withdrawal_index,
next_withdrawal_validator_index,
deposit_receipts_start_index,
deposit_requests_start_index,
deposit_balance_to_consume,
exit_balance_to_consume,
earliest_exit_epoch,
Expand Down Expand Up @@ -557,7 +557,7 @@ impl<E: EthSpec> TryInto<BeaconState<E>> for PartialBeaconState<E> {
latest_execution_payload_header,
next_withdrawal_index,
next_withdrawal_validator_index,
deposit_receipts_start_index,
deposit_requests_start_index,
deposit_balance_to_consume,
exit_balance_to_consume,
earliest_exit_epoch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ where
self.include_exits(block)?;
self.include_sync_aggregate(block)?;
self.include_bls_to_execution_changes(block)?;
self.include_consolidations(block)?;

Ok(())
}
Expand Down Expand Up @@ -360,27 +359,6 @@ where
Ok(())
}

/// Includes all signatures in `self.block.body.consolidations` for verification.
pub fn include_consolidations<Payload: AbstractExecPayload<E>>(
&mut self,
block: &'a SignedBeaconBlock<E, Payload>,
) -> Result<()> {
if let Ok(consolidations) = block.message().body().consolidations() {
self.sets.sets.reserve(consolidations.len());
for consolidation in consolidations {
let set = consolidation_signature_set(
self.state,
self.get_pubkey.clone(),
consolidation,
self.spec,
)?;

self.sets.push(set);
}
}
Ok(())
}

/// Verify all the signatures that have been included in `self`, returning `true` if and only if
/// all the signatures are valid.
///
Expand Down
Loading

0 comments on commit 0168124

Please sign in to comment.