Delete legacy payload reconstruction (#6213)

* Delete legacy payload reconstruction

* Delete unneeded failing test

* Merge remote-tracking branch 'origin/unstable' into remove-more-ethers

* Merge remote-tracking branch 'origin/unstable' into remove-more-ethers

* Cleanups
This commit is contained in:
Michael Sproul
2024-09-06 18:10:55 +10:00
committed by GitHub
parent c0b4f01cf3
commit d6861380a2
10 changed files with 110 additions and 755 deletions

View File

@@ -11,9 +11,6 @@ use eth2::types::{
BlobsBundle, SsePayloadAttributes, SsePayloadAttributesV1, SsePayloadAttributesV2,
SsePayloadAttributesV3,
};
use ethers_core::types::Transaction;
use ethers_core::utils::rlp;
use ethers_core::utils::rlp::{Decodable, Rlp};
use http::deposit_methods::RpcError;
pub use json_structures::{JsonWithdrawal, TransitionConfigurationV1};
use pretty_reqwest_error::PrettyReqwestError;
@@ -43,8 +40,6 @@ pub use new_payload_request::{
NewPayloadRequestDeneb, NewPayloadRequestElectra,
};
use self::json_structures::{JsonConsolidationRequest, JsonDepositRequest, JsonWithdrawalRequest};
pub const LATEST_TAG: &str = "latest";
pub type PayloadId = [u8; 8];
@@ -74,7 +69,6 @@ pub enum Error {
RequiredMethodUnsupported(&'static str),
UnsupportedForkVariant(String),
InvalidClientVersion(String),
RlpDecoderError(rlp::DecoderError),
TooManyConsolidationRequests(usize),
}
@@ -109,12 +103,6 @@ impl From<builder_client::Error> for Error {
}
}
impl From<rlp::DecoderError> for Error {
fn from(e: rlp::DecoderError) -> Self {
Error::RlpDecoderError(e)
}
}
impl From<ssz_types::Error> for Error {
fn from(e: ssz_types::Error) -> Self {
Error::SszError(e)
@@ -161,186 +149,6 @@ pub struct ExecutionBlock {
pub timestamp: u64,
}
/// Representation of an execution block with enough detail to reconstruct a payload.
#[superstruct(
variants(Bellatrix, Capella, Deneb, Electra),
variant_attributes(
derive(Clone, Debug, PartialEq, Serialize, Deserialize,),
serde(bound = "E: EthSpec", rename_all = "camelCase"),
),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound = "E: EthSpec", rename_all = "camelCase", untagged)]
pub struct ExecutionBlockWithTransactions<E: EthSpec> {
pub parent_hash: ExecutionBlockHash,
#[serde(alias = "miner")]
#[serde(with = "serde_utils::address_hex")]
pub fee_recipient: Address,
pub state_root: Hash256,
pub receipts_root: Hash256,
#[serde(with = "ssz_types::serde_utils::hex_fixed_vec")]
pub logs_bloom: FixedVector<u8, E::BytesPerLogsBloom>,
#[serde(alias = "mixHash")]
pub prev_randao: Hash256,
#[serde(rename = "number", with = "serde_utils::u64_hex_be")]
pub block_number: u64,
#[serde(with = "serde_utils::u64_hex_be")]
pub gas_limit: u64,
#[serde(with = "serde_utils::u64_hex_be")]
pub gas_used: u64,
#[serde(with = "serde_utils::u64_hex_be")]
pub timestamp: u64,
#[serde(with = "ssz_types::serde_utils::hex_var_list")]
pub extra_data: VariableList<u8, E::MaxExtraDataBytes>,
pub base_fee_per_gas: Uint256,
#[serde(rename = "hash")]
pub block_hash: ExecutionBlockHash,
pub transactions: Vec<Transaction>,
#[superstruct(only(Capella, Deneb, Electra))]
pub withdrawals: Vec<JsonWithdrawal>,
#[superstruct(only(Deneb, Electra))]
#[serde(with = "serde_utils::u64_hex_be")]
pub blob_gas_used: u64,
#[superstruct(only(Deneb, Electra))]
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_blob_gas: u64,
#[superstruct(only(Electra))]
pub deposit_requests: Vec<JsonDepositRequest>,
#[superstruct(only(Electra))]
pub withdrawal_requests: Vec<JsonWithdrawalRequest>,
#[superstruct(only(Electra))]
pub consolidation_requests: Vec<JsonConsolidationRequest>,
}
impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions<E> {
type Error = Error;
fn try_from(payload: ExecutionPayload<E>) -> Result<Self, Error> {
let json_payload = match payload {
ExecutionPayload::Bellatrix(block) => {
Self::Bellatrix(ExecutionBlockWithTransactionsBellatrix {
parent_hash: block.parent_hash,
fee_recipient: block.fee_recipient,
state_root: block.state_root,
receipts_root: block.receipts_root,
logs_bloom: block.logs_bloom,
prev_randao: block.prev_randao,
block_number: block.block_number,
gas_limit: block.gas_limit,
gas_used: block.gas_used,
timestamp: block.timestamp,
extra_data: block.extra_data,
base_fee_per_gas: block.base_fee_per_gas,
block_hash: block.block_hash,
transactions: block
.transactions
.iter()
.map(|tx| Transaction::decode(&Rlp::new(tx)))
.collect::<Result<Vec<_>, _>>()?,
})
}
ExecutionPayload::Capella(block) => {
Self::Capella(ExecutionBlockWithTransactionsCapella {
parent_hash: block.parent_hash,
fee_recipient: block.fee_recipient,
state_root: block.state_root,
receipts_root: block.receipts_root,
logs_bloom: block.logs_bloom,
prev_randao: block.prev_randao,
block_number: block.block_number,
gas_limit: block.gas_limit,
gas_used: block.gas_used,
timestamp: block.timestamp,
extra_data: block.extra_data,
base_fee_per_gas: block.base_fee_per_gas,
block_hash: block.block_hash,
transactions: block
.transactions
.iter()
.map(|tx| Transaction::decode(&Rlp::new(tx)))
.collect::<Result<Vec<_>, _>>()?,
withdrawals: Vec::from(block.withdrawals)
.into_iter()
.map(|withdrawal| withdrawal.into())
.collect(),
})
}
ExecutionPayload::Deneb(block) => Self::Deneb(ExecutionBlockWithTransactionsDeneb {
parent_hash: block.parent_hash,
fee_recipient: block.fee_recipient,
state_root: block.state_root,
receipts_root: block.receipts_root,
logs_bloom: block.logs_bloom,
prev_randao: block.prev_randao,
block_number: block.block_number,
gas_limit: block.gas_limit,
gas_used: block.gas_used,
timestamp: block.timestamp,
extra_data: block.extra_data,
base_fee_per_gas: block.base_fee_per_gas,
block_hash: block.block_hash,
transactions: block
.transactions
.iter()
.map(|tx| Transaction::decode(&Rlp::new(tx)))
.collect::<Result<Vec<_>, _>>()?,
withdrawals: Vec::from(block.withdrawals)
.into_iter()
.map(|withdrawal| withdrawal.into())
.collect(),
blob_gas_used: block.blob_gas_used,
excess_blob_gas: block.excess_blob_gas,
}),
ExecutionPayload::Electra(block) => {
Self::Electra(ExecutionBlockWithTransactionsElectra {
parent_hash: block.parent_hash,
fee_recipient: block.fee_recipient,
state_root: block.state_root,
receipts_root: block.receipts_root,
logs_bloom: block.logs_bloom,
prev_randao: block.prev_randao,
block_number: block.block_number,
gas_limit: block.gas_limit,
gas_used: block.gas_used,
timestamp: block.timestamp,
extra_data: block.extra_data,
base_fee_per_gas: block.base_fee_per_gas,
block_hash: block.block_hash,
transactions: block
.transactions
.iter()
.map(|tx| Transaction::decode(&Rlp::new(tx)))
.collect::<Result<Vec<_>, _>>()?,
withdrawals: Vec::from(block.withdrawals)
.into_iter()
.map(|withdrawal| withdrawal.into())
.collect(),
blob_gas_used: block.blob_gas_used,
excess_blob_gas: block.excess_blob_gas,
deposit_requests: block
.deposit_requests
.into_iter()
.map(|deposit| deposit.into())
.collect(),
withdrawal_requests: block
.withdrawal_requests
.into_iter()
.map(|withdrawal| withdrawal.into())
.collect(),
consolidation_requests: block
.consolidation_requests
.into_iter()
.map(Into::into)
.collect(),
})
}
};
Ok(json_payload)
}
}
#[superstruct(
variants(V1, V2, V3),
variant_attributes(derive(Clone, Debug, Eq, Hash, PartialEq),),

View File

@@ -734,54 +734,6 @@ impl HttpJsonRpc {
.await
}
pub async fn get_block_by_hash_with_txns<E: EthSpec>(
&self,
block_hash: ExecutionBlockHash,
fork: ForkName,
) -> Result<Option<ExecutionBlockWithTransactions<E>>, Error> {
let params = json!([block_hash, true]);
Ok(Some(match fork {
ForkName::Bellatrix => ExecutionBlockWithTransactions::Bellatrix(
self.rpc_request(
ETH_GET_BLOCK_BY_HASH,
params,
ETH_GET_BLOCK_BY_HASH_TIMEOUT * self.execution_timeout_multiplier,
)
.await?,
),
ForkName::Capella => ExecutionBlockWithTransactions::Capella(
self.rpc_request(
ETH_GET_BLOCK_BY_HASH,
params,
ETH_GET_BLOCK_BY_HASH_TIMEOUT * self.execution_timeout_multiplier,
)
.await?,
),
ForkName::Deneb => ExecutionBlockWithTransactions::Deneb(
self.rpc_request(
ETH_GET_BLOCK_BY_HASH,
params,
ETH_GET_BLOCK_BY_HASH_TIMEOUT * self.execution_timeout_multiplier,
)
.await?,
),
ForkName::Electra => ExecutionBlockWithTransactions::Electra(
self.rpc_request(
ETH_GET_BLOCK_BY_HASH,
params,
ETH_GET_BLOCK_BY_HASH_TIMEOUT * self.execution_timeout_multiplier,
)
.await?,
),
ForkName::Base | ForkName::Altair => {
return Err(Error::UnsupportedForkVariant(format!(
"called get_block_by_hash_with_txns with fork {:?}",
fork
)))
}
}))
}
pub async fn new_payload_v1<E: EthSpec>(
&self,
execution_payload: ExecutionPayload<E>,

View File

@@ -778,6 +778,57 @@ pub struct JsonExecutionPayloadBody<E: EthSpec> {
Option<VariableList<ConsolidationRequest, E::MaxConsolidationRequestsPerPayload>>,
}
impl<E: EthSpec> From<ExecutionPayloadBodyV1<E>> for JsonExecutionPayloadBodyV1<E> {
fn from(value: ExecutionPayloadBodyV1<E>) -> Self {
Self {
transactions: value.transactions,
withdrawals: value.withdrawals.map(|json_withdrawals| {
VariableList::from(
json_withdrawals
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)
}),
}
}
}
impl<E: EthSpec> From<ExecutionPayloadBodyV2<E>> for JsonExecutionPayloadBodyV2<E> {
fn from(value: ExecutionPayloadBodyV2<E>) -> Self {
Self {
transactions: value.transactions,
withdrawals: value.withdrawals.map(|json_withdrawals| {
VariableList::from(
json_withdrawals
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)
}),
deposit_requests: value.deposit_requests.map(|receipts| {
VariableList::from(receipts.into_iter().map(Into::into).collect::<Vec<_>>())
}),
withdrawal_requests: value.withdrawal_requests.map(|withdrawal_requests| {
VariableList::from(
withdrawal_requests
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)
}),
consolidation_requests: value.consolidation_requests.map(|consolidation_requests| {
VariableList::from(
consolidation_requests
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)
}),
}
}
}
impl<E: EthSpec> From<JsonExecutionPayloadBody<E>> for ExecutionPayloadBody<E> {
fn from(value: JsonExecutionPayloadBody<E>) -> Self {
match value {

View File

@@ -144,6 +144,7 @@ pub enum Error {
payload: ExecutionBlockHash,
transactions_root: Hash256,
},
PayloadBodiesByRangeNotSupported,
InvalidJWTSecret(String),
InvalidForkForPayload,
InvalidPayloadBody(String),
@@ -1804,7 +1805,6 @@ impl<E: EthSpec> ExecutionLayer<E> {
header: &ExecutionPayloadHeader<E>,
fork: ForkName,
) -> Result<Option<ExecutionPayload<E>>, Error> {
let hash = header.block_hash();
let block_number = header.block_number();
// Handle default payload body.
@@ -1823,7 +1823,9 @@ impl<E: EthSpec> ExecutionLayer<E> {
// Use efficient payload bodies by range method if supported.
let capabilities = self.get_engine_capabilities(None).await?;
if capabilities.get_payload_bodies_by_range_v1 {
if capabilities.get_payload_bodies_by_range_v1
|| capabilities.get_payload_bodies_by_range_v2
{
let mut payload_bodies = self.get_payload_bodies_by_range(block_number, 1).await?;
if payload_bodies.len() != 1 {
@@ -1838,8 +1840,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
})
.transpose()
} else {
// Fall back to eth_blockByHash.
self.get_payload_by_hash_legacy(hash, fork).await
Err(Error::PayloadBodiesByRangeNotSupported)
}
}
@@ -1854,196 +1855,6 @@ impl<E: EthSpec> ExecutionLayer<E> {
.map_err(Error::EngineError)
}
pub async fn get_payload_by_hash_legacy(
&self,
hash: ExecutionBlockHash,
fork: ForkName,
) -> Result<Option<ExecutionPayload<E>>, Error> {
self.engine()
.request(|engine| async move {
self.get_payload_by_hash_from_engine(engine, hash, fork)
.await
})
.await
.map_err(Box::new)
.map_err(Error::EngineError)
}
async fn get_payload_by_hash_from_engine(
&self,
engine: &Engine,
hash: ExecutionBlockHash,
fork: ForkName,
) -> Result<Option<ExecutionPayload<E>>, ApiError> {
let _timer = metrics::start_timer(&metrics::EXECUTION_LAYER_GET_PAYLOAD_BY_BLOCK_HASH);
if hash == ExecutionBlockHash::zero() {
return match fork {
ForkName::Bellatrix => Ok(Some(ExecutionPayloadBellatrix::default().into())),
ForkName::Capella => Ok(Some(ExecutionPayloadCapella::default().into())),
ForkName::Deneb => Ok(Some(ExecutionPayloadDeneb::default().into())),
ForkName::Electra => Ok(Some(ExecutionPayloadElectra::default().into())),
ForkName::Base | ForkName::Altair => Err(ApiError::UnsupportedForkVariant(
format!("called get_payload_by_hash_from_engine with {}", fork),
)),
};
}
let Some(block) = engine
.api
.get_block_by_hash_with_txns::<E>(hash, fork)
.await?
else {
return Ok(None);
};
let convert_transactions = |transactions: Vec<EthersTransaction>| {
VariableList::new(
transactions
.into_iter()
.map(|tx| VariableList::new(tx.rlp().to_vec()))
.collect::<Result<Vec<_>, ssz_types::Error>>()?,
)
.map_err(ApiError::SszError)
};
let payload = match block {
ExecutionBlockWithTransactions::Bellatrix(bellatrix_block) => {
ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
parent_hash: bellatrix_block.parent_hash,
fee_recipient: bellatrix_block.fee_recipient,
state_root: bellatrix_block.state_root,
receipts_root: bellatrix_block.receipts_root,
logs_bloom: bellatrix_block.logs_bloom,
prev_randao: bellatrix_block.prev_randao,
block_number: bellatrix_block.block_number,
gas_limit: bellatrix_block.gas_limit,
gas_used: bellatrix_block.gas_used,
timestamp: bellatrix_block.timestamp,
extra_data: bellatrix_block.extra_data,
base_fee_per_gas: bellatrix_block.base_fee_per_gas,
block_hash: bellatrix_block.block_hash,
transactions: convert_transactions(bellatrix_block.transactions)?,
})
}
ExecutionBlockWithTransactions::Capella(capella_block) => {
let withdrawals = VariableList::new(
capella_block
.withdrawals
.into_iter()
.map(Into::into)
.collect(),
)
.map_err(ApiError::DeserializeWithdrawals)?;
ExecutionPayload::Capella(ExecutionPayloadCapella {
parent_hash: capella_block.parent_hash,
fee_recipient: capella_block.fee_recipient,
state_root: capella_block.state_root,
receipts_root: capella_block.receipts_root,
logs_bloom: capella_block.logs_bloom,
prev_randao: capella_block.prev_randao,
block_number: capella_block.block_number,
gas_limit: capella_block.gas_limit,
gas_used: capella_block.gas_used,
timestamp: capella_block.timestamp,
extra_data: capella_block.extra_data,
base_fee_per_gas: capella_block.base_fee_per_gas,
block_hash: capella_block.block_hash,
transactions: convert_transactions(capella_block.transactions)?,
withdrawals,
})
}
ExecutionBlockWithTransactions::Deneb(deneb_block) => {
let withdrawals = VariableList::new(
deneb_block
.withdrawals
.into_iter()
.map(Into::into)
.collect(),
)
.map_err(ApiError::DeserializeWithdrawals)?;
ExecutionPayload::Deneb(ExecutionPayloadDeneb {
parent_hash: deneb_block.parent_hash,
fee_recipient: deneb_block.fee_recipient,
state_root: deneb_block.state_root,
receipts_root: deneb_block.receipts_root,
logs_bloom: deneb_block.logs_bloom,
prev_randao: deneb_block.prev_randao,
block_number: deneb_block.block_number,
gas_limit: deneb_block.gas_limit,
gas_used: deneb_block.gas_used,
timestamp: deneb_block.timestamp,
extra_data: deneb_block.extra_data,
base_fee_per_gas: deneb_block.base_fee_per_gas,
block_hash: deneb_block.block_hash,
transactions: convert_transactions(deneb_block.transactions)?,
withdrawals,
blob_gas_used: deneb_block.blob_gas_used,
excess_blob_gas: deneb_block.excess_blob_gas,
})
}
ExecutionBlockWithTransactions::Electra(electra_block) => {
let withdrawals = VariableList::new(
electra_block
.withdrawals
.into_iter()
.map(Into::into)
.collect(),
)
.map_err(ApiError::DeserializeWithdrawals)?;
let deposit_requests = VariableList::new(
electra_block
.deposit_requests
.into_iter()
.map(Into::into)
.collect(),
)
.map_err(ApiError::DeserializeDepositRequests)?;
let withdrawal_requests = VariableList::new(
electra_block
.withdrawal_requests
.into_iter()
.map(Into::into)
.collect(),
)
.map_err(ApiError::DeserializeWithdrawalRequests)?;
let n_consolidations = electra_block.consolidation_requests.len();
let consolidation_requests = VariableList::new(
electra_block
.consolidation_requests
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)
.map_err(|_| ApiError::TooManyConsolidationRequests(n_consolidations))?;
ExecutionPayload::Electra(ExecutionPayloadElectra {
parent_hash: electra_block.parent_hash,
fee_recipient: electra_block.fee_recipient,
state_root: electra_block.state_root,
receipts_root: electra_block.receipts_root,
logs_bloom: electra_block.logs_bloom,
prev_randao: electra_block.prev_randao,
block_number: electra_block.block_number,
gas_limit: electra_block.gas_limit,
gas_used: electra_block.gas_used,
timestamp: electra_block.timestamp,
extra_data: electra_block.extra_data,
base_fee_per_gas: electra_block.base_fee_per_gas,
block_hash: electra_block.block_hash,
transactions: convert_transactions(electra_block.transactions)?,
withdrawals,
blob_gas_used: electra_block.blob_gas_used,
excess_blob_gas: electra_block.excess_blob_gas,
deposit_requests,
withdrawal_requests,
consolidation_requests,
})
}
};
Ok(Some(payload))
}
pub async fn propose_blinded_beacon_block(
&self,
block_root: Hash256,

View File

@@ -54,13 +54,6 @@ pub static EXECUTION_LAYER_PRE_PREPARED_PAYLOAD_ID: LazyLock<Result<IntCounterVe
)
},
);
pub static EXECUTION_LAYER_GET_PAYLOAD_BY_BLOCK_HASH: LazyLock<Result<Histogram>> =
LazyLock::new(|| {
try_create_histogram(
"execution_layer_get_payload_by_block_hash_time",
"Time to reconstruct a payload from the EE using eth_getBlockByHash",
)
});
pub static EXECUTION_LAYER_GET_PAYLOAD_BODIES_BY_RANGE: LazyLock<Result<Histogram>> =
LazyLock::new(|| {
try_create_histogram(

View File

@@ -1,14 +1,11 @@
use crate::engine_api::{
json_structures::{
JsonForkchoiceUpdatedV1Response, JsonPayloadStatusV1, JsonPayloadStatusV1Status,
},
ExecutionBlock, PayloadAttributes, PayloadId, PayloadStatusV1, PayloadStatusV1Status,
};
use crate::engines::ForkchoiceState;
use crate::EthersTransaction;
use crate::{
engine_api::{
json_structures::{
JsonForkchoiceUpdatedV1Response, JsonPayloadStatusV1, JsonPayloadStatusV1Status,
},
ExecutionBlock, PayloadAttributes, PayloadId, PayloadStatusV1, PayloadStatusV1Status,
},
ExecutionBlockWithTransactions,
};
use eth2::types::BlobsBundle;
use kzg::{Kzg, KzgCommitment, KzgProof};
use parking_lot::Mutex;
@@ -89,17 +86,13 @@ impl<E: EthSpec> Block<E> {
}
}
pub fn as_execution_block_with_tx(&self) -> Option<ExecutionBlockWithTransactions<E>> {
pub fn as_execution_payload(&self) -> Option<ExecutionPayload<E>> {
match self {
Block::PoS(payload) => Some(payload.clone().try_into().unwrap()),
Block::PoW(block) => Some(
ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
block_hash: block.block_hash,
..Default::default()
})
.try_into()
.unwrap(),
),
Block::PoS(payload) => Some(payload.clone()),
Block::PoW(block) => Some(ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
block_hash: block.block_hash,
..Default::default()
})),
}
}
}
@@ -255,20 +248,17 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
.map(|block| block.as_execution_block(self.terminal_total_difficulty))
}
pub fn execution_block_with_txs_by_hash(
pub fn execution_payload_by_hash(
&self,
hash: ExecutionBlockHash,
) -> Option<ExecutionBlockWithTransactions<E>> {
) -> Option<ExecutionPayload<E>> {
self.block_by_hash(hash)
.and_then(|block| block.as_execution_block_with_tx())
.and_then(|block| block.as_execution_payload())
}
pub fn execution_block_with_txs_by_number(
&self,
number: u64,
) -> Option<ExecutionBlockWithTransactions<E>> {
pub fn execution_payload_by_number(&self, number: u64) -> Option<ExecutionPayload<E>> {
self.block_by_number(number)
.and_then(|block| block.as_execution_block_with_tx())
.and_then(|block| block.as_execution_payload())
}
pub fn move_to_block_prior_to_terminal_block(&mut self) -> Result<(), String> {

View File

@@ -83,12 +83,10 @@ pub async fn handle_rpc<E: EthSpec>(
.ok_or_else(|| "missing/invalid params[1] value".to_string())
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?;
if full_tx {
Ok(serde_json::to_value(
ctx.execution_block_generator
.read()
.execution_block_with_txs_by_hash(hash),
)
.unwrap())
Err((
"full_tx support has been removed".to_string(),
BAD_PARAMS_ERROR_CODE,
))
} else {
Ok(serde_json::to_value(
ctx.execution_block_generator
@@ -556,40 +554,25 @@ pub async fn handle_rpc<E: EthSpec>(
let mut response = vec![];
for block_num in start..(start + count) {
let maybe_block = ctx
let maybe_payload = ctx
.execution_block_generator
.read()
.execution_block_with_txs_by_number(block_num);
.execution_payload_by_number(block_num);
match maybe_block {
Some(block) => {
let transactions = Transactions::<E>::new(
block
.transactions()
.iter()
.map(|transaction| VariableList::new(transaction.rlp().to_vec()))
.collect::<Result<_, _>>()
.map_err(|e| {
(
format!("failed to deserialize transaction: {:?}", e),
GENERIC_ERROR_CODE,
)
})?,
)
.map_err(|e| {
(
format!("failed to deserialize transactions: {:?}", e),
GENERIC_ERROR_CODE,
)
})?;
response.push(Some(JsonExecutionPayloadBodyV1::<E> {
transactions,
withdrawals: block
.withdrawals()
.ok()
.map(|withdrawals| VariableList::from(withdrawals.clone())),
}));
match maybe_payload {
Some(payload) => {
assert!(
!payload.fork_name().electra_enabled(),
"payload bodies V1 is not supported for Electra blocks"
);
let payload_body = ExecutionPayloadBodyV1 {
transactions: payload.transactions().clone(),
withdrawals: payload.withdrawals().ok().cloned(),
};
let json_payload_body = JsonExecutionPayloadBody::V1(
JsonExecutionPayloadBodyV1::<E>::from(payload_body),
);
response.push(Some(json_payload_body));
}
None => response.push(None),
}
@@ -611,63 +594,28 @@ pub async fn handle_rpc<E: EthSpec>(
let mut response = vec![];
for block_num in start..(start + count) {
let maybe_block = ctx
let maybe_payload = ctx
.execution_block_generator
.read()
.execution_block_with_txs_by_number(block_num);
match maybe_block {
Some(block) => {
let transactions = Transactions::<E>::new(
block
.transactions()
.iter()
.map(|transaction| VariableList::new(transaction.rlp().to_vec()))
.collect::<Result<_, _>>()
.map_err(|e| {
(
format!("failed to deserialize transaction: {:?}", e),
GENERIC_ERROR_CODE,
)
})?,
)
.map_err(|e| {
(
format!("failed to deserialize transactions: {:?}", e),
GENERIC_ERROR_CODE,
)
})?;
.execution_payload_by_number(block_num);
match maybe_payload {
Some(payload) => {
// TODO(electra): add testing for:
// deposit_requests
// withdrawal_requests
// consolidation_requests
response.push(Some(JsonExecutionPayloadBodyV2::<E> {
transactions,
withdrawals: block
.withdrawals()
.ok()
.map(|withdrawals| VariableList::from(withdrawals.clone())),
deposit_requests: block.deposit_requests().ok().map(
|deposit_requests| VariableList::from(deposit_requests.clone()),
),
withdrawal_requests: block.withdrawal_requests().ok().map(
|withdrawal_requests| {
VariableList::from(withdrawal_requests.clone())
},
),
consolidation_requests: block.consolidation_requests().ok().map(
|consolidation_requests| {
VariableList::from(
consolidation_requests
.clone()
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)
},
),
}));
let payload_body = ExecutionPayloadBodyV2 {
transactions: payload.transactions().clone(),
withdrawals: payload.withdrawals().ok().cloned(),
deposit_requests: payload.deposit_requests().ok().cloned(),
withdrawal_requests: payload.withdrawal_requests().ok().cloned(),
consolidation_requests: payload.consolidation_requests().ok().cloned(),
};
let json_payload_body = JsonExecutionPayloadBody::V2(
JsonExecutionPayloadBodyV2::<E>::from(payload_body),
);
response.push(Some(json_payload_body));
}
None => response.push(None),
}