Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug on engine api with consolidations #6101

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions beacon_node/execution_layer/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -210,8 +210,7 @@ pub struct ExecutionBlockWithTransactions<E: EthSpec> {
#[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>,
pub consolidation_requests: Vec<JsonConsolidationRequest>,
}

impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions<E> {
Expand Down Expand Up @@ -329,7 +328,11 @@ impl<E: EthSpec> TryFrom<ExecutionPayload<E>> 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(),
})
}
};
Expand Down
44 changes: 41 additions & 3 deletions beacon_node/execution_layer/src/engine_api/json_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub struct JsonExecutionPayload<E: EthSpec> {
VariableList<JsonWithdrawalRequest, E::MaxWithdrawalRequestsPerPayload>,
#[superstruct(only(V4))]
pub consolidation_requests:
VariableList<ConsolidationRequest, E::MaxConsolidationRequestsPerPayload>,
VariableList<JsonConsolidationRequest, E::MaxConsolidationRequestsPerPayload>,
}

impl<E: EthSpec> From<ExecutionPayloadBellatrix<E>> for JsonExecutionPayloadV1<E> {
Expand Down Expand Up @@ -223,7 +223,12 @@ impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E>
.map(Into::into)
.collect::<Vec<_>>()
.into(),
consolidation_requests: payload.consolidation_requests,
consolidation_requests: payload
.consolidation_requests
.into_iter()
.map(Into::into)
.collect::<Vec<_>>()
.into(),
}
}
}
Expand Down Expand Up @@ -352,7 +357,12 @@ impl<E: EthSpec> From<JsonExecutionPayloadV4<E>> for ExecutionPayloadElectra<E>
.map(Into::into)
.collect::<Vec<_>>()
.into(),
consolidation_requests: payload.consolidation_requests,
consolidation_requests: payload
.consolidation_requests
.into_iter()
.map(Into::into)
.collect::<Vec<_>>()
.into(),
}
}
}
Expand Down Expand Up @@ -927,3 +937,31 @@ impl From<JsonWithdrawalRequest> 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<ConsolidationRequest> 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<JsonConsolidationRequest> 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,
}
}
}
11 changes: 8 additions & 3 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2011,9 +2011,14 @@ impl<E: EthSpec> ExecutionLayer<E> {
)
.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::<Vec<_>>(),
)
.map_err(|_| ApiError::TooManyConsolidationRequests(n_consolidations))?;
ExecutionPayload::Electra(ExecutionPayloadElectra {
parent_hash: electra_block.parent_hash,
fee_recipient: electra_block.fee_recipient,
Expand Down
8 changes: 7 additions & 1 deletion beacon_node/execution_layer/src/test_utils/handle_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,13 @@ pub async fn handle_rpc<E: EthSpec>(
),
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::<Vec<_>>(),
)
},
),
}));
Expand Down
Loading