diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index d5c00e4dbe6..5322355ddae 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -43,7 +43,7 @@ pub use new_payload_request::{ NewPayloadRequestDeneb, NewPayloadRequestElectra, }; -use self::json_structures::{JsonDepositRequest, JsonWithdrawalRequest}; +use self::json_structures::{JsonConsolidationRequest, JsonDepositRequest, JsonWithdrawalRequest}; pub const LATEST_TAG: &str = "latest"; @@ -210,8 +210,7 @@ pub struct ExecutionBlockWithTransactions { #[superstruct(only(Electra))] pub withdrawal_requests: Vec, #[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, + pub consolidation_requests: Vec, } impl TryFrom> for ExecutionBlockWithTransactions { @@ -329,7 +328,11 @@ impl TryFrom> for ExecutionBlockWithTransactions .into_iter() .map(|withdrawal| withdrawal.into()) .collect(), - consolidation_requests: block.consolidation_requests.to_vec(), + consolidation_requests: block + .consolidation_requests + .into_iter() + .map(Into::into) + .collect(), }) } }; diff --git a/beacon_node/execution_layer/src/engine_api/json_structures.rs b/beacon_node/execution_layer/src/engine_api/json_structures.rs index bfac5c87dd9..0eb20484141 100644 --- a/beacon_node/execution_layer/src/engine_api/json_structures.rs +++ b/beacon_node/execution_layer/src/engine_api/json_structures.rs @@ -108,7 +108,7 @@ pub struct JsonExecutionPayload { VariableList, #[superstruct(only(V4))] pub consolidation_requests: - VariableList, + VariableList, } impl From> for JsonExecutionPayloadV1 { @@ -223,7 +223,12 @@ impl From> for JsonExecutionPayloadV4 .map(Into::into) .collect::>() .into(), - consolidation_requests: payload.consolidation_requests, + consolidation_requests: payload + .consolidation_requests + .into_iter() + .map(Into::into) + .collect::>() + .into(), } } } @@ -352,7 +357,12 @@ impl From> for ExecutionPayloadElectra .map(Into::into) .collect::>() .into(), - consolidation_requests: payload.consolidation_requests, + consolidation_requests: payload + .consolidation_requests + .into_iter() + .map(Into::into) + .collect::>() + .into(), } } } @@ -927,3 +937,31 @@ impl From for WithdrawalRequest { } } } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct JsonConsolidationRequest { + pub source_address: Address, + pub source_pubkey: PublicKeyBytes, + pub target_pubkey: PublicKeyBytes, +} + +impl From for JsonConsolidationRequest { + fn from(consolidation_request: ConsolidationRequest) -> Self { + Self { + source_address: consolidation_request.source_address, + source_pubkey: consolidation_request.source_pubkey, + target_pubkey: consolidation_request.target_pubkey, + } + } +} + +impl From for ConsolidationRequest { + fn from(json_consolidation_request: JsonConsolidationRequest) -> Self { + Self { + source_address: json_consolidation_request.source_address, + source_pubkey: json_consolidation_request.source_pubkey, + target_pubkey: json_consolidation_request.target_pubkey, + } + } +} diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index e40e948cc6b..371aa94e19b 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -2011,9 +2011,14 @@ impl ExecutionLayer { ) .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))?; + let consolidation_requests = VariableList::new( + electra_block + .consolidation_requests + .into_iter() + .map(Into::into) + .collect::>(), + ) + .map_err(|_| ApiError::TooManyConsolidationRequests(n_consolidations))?; ExecutionPayload::Electra(ExecutionPayloadElectra { parent_hash: electra_block.parent_hash, fee_recipient: electra_block.fee_recipient, diff --git a/beacon_node/execution_layer/src/test_utils/handle_rpc.rs b/beacon_node/execution_layer/src/test_utils/handle_rpc.rs index d86b4439ad7..b1788498424 100644 --- a/beacon_node/execution_layer/src/test_utils/handle_rpc.rs +++ b/beacon_node/execution_layer/src/test_utils/handle_rpc.rs @@ -658,7 +658,13 @@ pub async fn handle_rpc( ), consolidation_requests: block.consolidation_requests().ok().map( |consolidation_requests| { - VariableList::from(consolidation_requests.clone()) + VariableList::from( + consolidation_requests + .clone() + .into_iter() + .map(Into::into) + .collect::>(), + ) }, ), }));