mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-07 10:41:43 +00:00
Electra updates for v1.5.0-alpha.6 (#6445)
* Update process_slashing * Update test vectors version * Delete Domain::Consolidation * Rename to get_max_effective_balance * Fix unused; lint * Add the pre-electra slashing processing * lint * Change request json types * Move requests from payload to beacon block body * Refactor engine api * Fix warnings * Update engine api to latest * engine api changed..again * yet again * Merge branch 'engine-requests' into electra-updates * Fix tests * Store reference instead of bytes in NewPayloadRequest * Merge branch 'unstable' into electra-updates * Update beacon_node/execution_layer/src/engine_api/json_structures.rs Co-authored-by: Michael Sproul <micsproul@gmail.com> * Update beacon_node/execution_layer/src/lib.rs Co-authored-by: Michael Sproul <micsproul@gmail.com> * Update beacon_node/execution_layer/src/test_utils/handle_rpc.rs Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
@@ -50,8 +50,6 @@ pub const ENGINE_FORKCHOICE_UPDATED_TIMEOUT: Duration = Duration::from_secs(8);
|
||||
|
||||
pub const ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1: &str = "engine_getPayloadBodiesByHashV1";
|
||||
pub const ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1: &str = "engine_getPayloadBodiesByRangeV1";
|
||||
pub const ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V2: &str = "engine_getPayloadBodiesByHashV2";
|
||||
pub const ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V2: &str = "engine_getPayloadBodiesByRangeV2";
|
||||
pub const ENGINE_GET_PAYLOAD_BODIES_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
pub const ENGINE_EXCHANGE_CAPABILITIES: &str = "engine_exchangeCapabilities";
|
||||
@@ -80,8 +78,6 @@ pub static LIGHTHOUSE_CAPABILITIES: &[&str] = &[
|
||||
ENGINE_FORKCHOICE_UPDATED_V3,
|
||||
ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1,
|
||||
ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1,
|
||||
ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V2,
|
||||
ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V2,
|
||||
ENGINE_GET_CLIENT_VERSION_V1,
|
||||
];
|
||||
|
||||
@@ -797,6 +793,9 @@ impl HttpJsonRpc {
|
||||
JsonExecutionPayload::V4(new_payload_request_electra.execution_payload.clone().into()),
|
||||
new_payload_request_electra.versioned_hashes,
|
||||
new_payload_request_electra.parent_beacon_block_root,
|
||||
new_payload_request_electra
|
||||
.execution_requests_list
|
||||
.get_execution_requests_list(),
|
||||
]);
|
||||
|
||||
let response: JsonPayloadStatusV1 = self
|
||||
@@ -849,7 +848,9 @@ impl HttpJsonRpc {
|
||||
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
|
||||
)
|
||||
.await?;
|
||||
Ok(JsonGetPayloadResponse::V1(response).into())
|
||||
JsonGetPayloadResponse::V1(response)
|
||||
.try_into()
|
||||
.map_err(Error::BadResponse)
|
||||
}
|
||||
ForkName::Capella => {
|
||||
let response: JsonGetPayloadResponseV2<E> = self
|
||||
@@ -859,7 +860,9 @@ impl HttpJsonRpc {
|
||||
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
|
||||
)
|
||||
.await?;
|
||||
Ok(JsonGetPayloadResponse::V2(response).into())
|
||||
JsonGetPayloadResponse::V2(response)
|
||||
.try_into()
|
||||
.map_err(Error::BadResponse)
|
||||
}
|
||||
ForkName::Base | ForkName::Altair | ForkName::Deneb | ForkName::Electra => Err(
|
||||
Error::UnsupportedForkVariant(format!("called get_payload_v2 with {}", fork_name)),
|
||||
@@ -883,7 +886,9 @@ impl HttpJsonRpc {
|
||||
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
|
||||
)
|
||||
.await?;
|
||||
Ok(JsonGetPayloadResponse::V3(response).into())
|
||||
JsonGetPayloadResponse::V3(response)
|
||||
.try_into()
|
||||
.map_err(Error::BadResponse)
|
||||
}
|
||||
ForkName::Base
|
||||
| ForkName::Altair
|
||||
@@ -912,7 +917,9 @@ impl HttpJsonRpc {
|
||||
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
|
||||
)
|
||||
.await?;
|
||||
Ok(JsonGetPayloadResponse::V4(response).into())
|
||||
JsonGetPayloadResponse::V4(response)
|
||||
.try_into()
|
||||
.map_err(Error::BadResponse)
|
||||
}
|
||||
ForkName::Base
|
||||
| ForkName::Altair
|
||||
@@ -991,7 +998,7 @@ impl HttpJsonRpc {
|
||||
pub async fn get_payload_bodies_by_hash_v1<E: EthSpec>(
|
||||
&self,
|
||||
block_hashes: Vec<ExecutionBlockHash>,
|
||||
) -> Result<Vec<Option<ExecutionPayloadBody<E>>>, Error> {
|
||||
) -> Result<Vec<Option<ExecutionPayloadBodyV1<E>>>, Error> {
|
||||
let params = json!([block_hashes]);
|
||||
|
||||
let response: Vec<Option<JsonExecutionPayloadBodyV1<E>>> = self
|
||||
@@ -1004,27 +1011,7 @@ impl HttpJsonRpc {
|
||||
|
||||
Ok(response
|
||||
.into_iter()
|
||||
.map(|opt_json| opt_json.map(|v1| JsonExecutionPayloadBody::V1(v1).into()))
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn get_payload_bodies_by_hash_v2<E: EthSpec>(
|
||||
&self,
|
||||
block_hashes: Vec<ExecutionBlockHash>,
|
||||
) -> Result<Vec<Option<ExecutionPayloadBody<E>>>, Error> {
|
||||
let params = json!([block_hashes]);
|
||||
|
||||
let response: Vec<Option<JsonExecutionPayloadBodyV2<E>>> = self
|
||||
.rpc_request(
|
||||
ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V2,
|
||||
params,
|
||||
ENGINE_GET_PAYLOAD_BODIES_TIMEOUT * self.execution_timeout_multiplier,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(response
|
||||
.into_iter()
|
||||
.map(|opt_json| opt_json.map(|v2| JsonExecutionPayloadBody::V2(v2).into()))
|
||||
.map(|opt_json| opt_json.map(From::from))
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -1032,7 +1019,7 @@ impl HttpJsonRpc {
|
||||
&self,
|
||||
start: u64,
|
||||
count: u64,
|
||||
) -> Result<Vec<Option<ExecutionPayloadBody<E>>>, Error> {
|
||||
) -> Result<Vec<Option<ExecutionPayloadBodyV1<E>>>, Error> {
|
||||
#[derive(Serialize)]
|
||||
#[serde(transparent)]
|
||||
struct Quantity(#[serde(with = "serde_utils::u64_hex_be")] u64);
|
||||
@@ -1048,31 +1035,7 @@ impl HttpJsonRpc {
|
||||
|
||||
Ok(response
|
||||
.into_iter()
|
||||
.map(|opt_json| opt_json.map(|v1| JsonExecutionPayloadBody::V1(v1).into()))
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn get_payload_bodies_by_range_v2<E: EthSpec>(
|
||||
&self,
|
||||
start: u64,
|
||||
count: u64,
|
||||
) -> Result<Vec<Option<ExecutionPayloadBody<E>>>, Error> {
|
||||
#[derive(Serialize)]
|
||||
#[serde(transparent)]
|
||||
struct Quantity(#[serde(with = "serde_utils::u64_hex_be")] u64);
|
||||
|
||||
let params = json!([Quantity(start), Quantity(count)]);
|
||||
let response: Vec<Option<JsonExecutionPayloadBodyV2<E>>> = self
|
||||
.rpc_request(
|
||||
ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V2,
|
||||
params,
|
||||
ENGINE_GET_PAYLOAD_BODIES_TIMEOUT * self.execution_timeout_multiplier,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(response
|
||||
.into_iter()
|
||||
.map(|opt_json| opt_json.map(|v2| JsonExecutionPayloadBody::V2(v2).into()))
|
||||
.map(|opt_json| opt_json.map(From::from))
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -1099,10 +1062,6 @@ impl HttpJsonRpc {
|
||||
.contains(ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1),
|
||||
get_payload_bodies_by_range_v1: capabilities
|
||||
.contains(ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1),
|
||||
get_payload_bodies_by_hash_v2: capabilities
|
||||
.contains(ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V2),
|
||||
get_payload_bodies_by_range_v2: capabilities
|
||||
.contains(ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V2),
|
||||
get_payload_v1: capabilities.contains(ENGINE_GET_PAYLOAD_V1),
|
||||
get_payload_v2: capabilities.contains(ENGINE_GET_PAYLOAD_V2),
|
||||
get_payload_v3: capabilities.contains(ENGINE_GET_PAYLOAD_V3),
|
||||
@@ -1278,39 +1237,6 @@ impl HttpJsonRpc {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_payload_bodies_by_hash<E: EthSpec>(
|
||||
&self,
|
||||
block_hashes: Vec<ExecutionBlockHash>,
|
||||
) -> Result<Vec<Option<ExecutionPayloadBody<E>>>, Error> {
|
||||
let engine_capabilities = self.get_engine_capabilities(None).await?;
|
||||
if engine_capabilities.get_payload_bodies_by_hash_v2 {
|
||||
self.get_payload_bodies_by_hash_v2(block_hashes).await
|
||||
} else if engine_capabilities.get_payload_bodies_by_hash_v1 {
|
||||
self.get_payload_bodies_by_hash_v1(block_hashes).await
|
||||
} else {
|
||||
Err(Error::RequiredMethodUnsupported(
|
||||
"engine_getPayloadBodiesByHash",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_payload_bodies_by_range<E: EthSpec>(
|
||||
&self,
|
||||
start: u64,
|
||||
count: u64,
|
||||
) -> Result<Vec<Option<ExecutionPayloadBody<E>>>, Error> {
|
||||
let engine_capabilities = self.get_engine_capabilities(None).await?;
|
||||
if engine_capabilities.get_payload_bodies_by_range_v2 {
|
||||
self.get_payload_bodies_by_range_v2(start, count).await
|
||||
} else if engine_capabilities.get_payload_bodies_by_range_v1 {
|
||||
self.get_payload_bodies_by_range_v1(start, count).await
|
||||
} else {
|
||||
Err(Error::RequiredMethodUnsupported(
|
||||
"engine_getPayloadBodiesByRange",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// automatically selects the latest version of
|
||||
// forkchoice_updated that the execution engine supports
|
||||
pub async fn forkchoice_updated(
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use super::*;
|
||||
use alloy_rlp::RlpEncodable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Decode;
|
||||
use strum::EnumString;
|
||||
use superstruct::superstruct;
|
||||
use types::beacon_block_body::KzgCommitments;
|
||||
use types::blob_sidecar::BlobsList;
|
||||
use types::{DepositRequest, FixedVector, PublicKeyBytes, Signature, Unsigned, WithdrawalRequest};
|
||||
use types::execution_requests::{ConsolidationRequests, DepositRequests, WithdrawalRequests};
|
||||
use types::{FixedVector, Unsigned};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -104,14 +106,6 @@ pub struct JsonExecutionPayload<E: EthSpec> {
|
||||
#[superstruct(only(V3, V4))]
|
||||
#[serde(with = "serde_utils::u64_hex_be")]
|
||||
pub excess_blob_gas: u64,
|
||||
#[superstruct(only(V4))]
|
||||
pub deposit_requests: VariableList<JsonDepositRequest, E::MaxDepositRequestsPerPayload>,
|
||||
#[superstruct(only(V4))]
|
||||
pub withdrawal_requests:
|
||||
VariableList<JsonWithdrawalRequest, E::MaxWithdrawalRequestsPerPayload>,
|
||||
#[superstruct(only(V4))]
|
||||
pub consolidation_requests:
|
||||
VariableList<JsonConsolidationRequest, E::MaxConsolidationRequestsPerPayload>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayloadBellatrix<E>> for JsonExecutionPayloadV1<E> {
|
||||
@@ -214,24 +208,6 @@ impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E>
|
||||
.into(),
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
deposit_requests: payload
|
||||
.deposit_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawal_requests: payload
|
||||
.withdrawal_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
consolidation_requests: payload
|
||||
.consolidation_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -348,24 +324,6 @@ 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_requests: payload
|
||||
.deposit_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawal_requests: payload
|
||||
.withdrawal_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
consolidation_requests: payload
|
||||
.consolidation_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -381,6 +339,71 @@ impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// This is used to index into the `execution_requests` array.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
enum RequestPrefix {
|
||||
Deposit,
|
||||
Withdrawal,
|
||||
Consolidation,
|
||||
}
|
||||
|
||||
impl RequestPrefix {
|
||||
pub fn from_prefix(prefix: u8) -> Option<Self> {
|
||||
match prefix {
|
||||
0 => Some(Self::Deposit),
|
||||
1 => Some(Self::Withdrawal),
|
||||
2 => Some(Self::Consolidation),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Format of `ExecutionRequests` received over the engine api.
|
||||
///
|
||||
/// Array of ssz-encoded requests list encoded as hex bytes.
|
||||
/// The prefix of the request type is used to index into the array.
|
||||
///
|
||||
/// For e.g. [0xab, 0xcd, 0xef]
|
||||
/// Here, 0xab are the deposits bytes (prefix and index == 0)
|
||||
/// 0xcd are the withdrawals bytes (prefix and index == 1)
|
||||
/// 0xef are the consolidations bytes (prefix and index == 2)
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct JsonExecutionRequests(pub Vec<String>);
|
||||
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(value: JsonExecutionRequests) -> Result<Self, Self::Error> {
|
||||
let mut requests = ExecutionRequests::default();
|
||||
|
||||
for (i, request) in value.0.into_iter().enumerate() {
|
||||
// hex string
|
||||
let decoded_bytes = hex::decode(request).map_err(|e| format!("Invalid hex {:?}", e))?;
|
||||
match RequestPrefix::from_prefix(i as u8) {
|
||||
Some(RequestPrefix::Deposit) => {
|
||||
requests.deposits = DepositRequests::<E>::from_ssz_bytes(&decoded_bytes)
|
||||
.map_err(|e| format!("Failed to decode DepositRequest from EL: {:?}", e))?;
|
||||
}
|
||||
Some(RequestPrefix::Withdrawal) => {
|
||||
requests.withdrawals = WithdrawalRequests::<E>::from_ssz_bytes(&decoded_bytes)
|
||||
.map_err(|e| {
|
||||
format!("Failed to decode WithdrawalRequest from EL: {:?}", e)
|
||||
})?;
|
||||
}
|
||||
Some(RequestPrefix::Consolidation) => {
|
||||
requests.consolidations =
|
||||
ConsolidationRequests::<E>::from_ssz_bytes(&decoded_bytes).map_err(
|
||||
|e| format!("Failed to decode ConsolidationRequest from EL: {:?}", e),
|
||||
)?;
|
||||
}
|
||||
None => return Err("Empty requests string".to_string()),
|
||||
}
|
||||
}
|
||||
Ok(requests)
|
||||
}
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(V1, V2, V3, V4),
|
||||
variant_attributes(
|
||||
@@ -407,38 +430,42 @@ pub struct JsonGetPayloadResponse<E: EthSpec> {
|
||||
pub blobs_bundle: JsonBlobsBundleV1<E>,
|
||||
#[superstruct(only(V3, V4))]
|
||||
pub should_override_builder: bool,
|
||||
#[superstruct(only(V4))]
|
||||
pub requests: JsonExecutionRequests,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
|
||||
fn from(json_get_payload_response: JsonGetPayloadResponse<E>) -> Self {
|
||||
impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
|
||||
type Error = String;
|
||||
fn try_from(json_get_payload_response: JsonGetPayloadResponse<E>) -> Result<Self, Self::Error> {
|
||||
match json_get_payload_response {
|
||||
JsonGetPayloadResponse::V1(response) => {
|
||||
GetPayloadResponse::Bellatrix(GetPayloadResponseBellatrix {
|
||||
Ok(GetPayloadResponse::Bellatrix(GetPayloadResponseBellatrix {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
block_value: response.block_value,
|
||||
})
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V2(response) => {
|
||||
GetPayloadResponse::Capella(GetPayloadResponseCapella {
|
||||
Ok(GetPayloadResponse::Capella(GetPayloadResponseCapella {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
block_value: response.block_value,
|
||||
})
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V3(response) => {
|
||||
GetPayloadResponse::Deneb(GetPayloadResponseDeneb {
|
||||
Ok(GetPayloadResponse::Deneb(GetPayloadResponseDeneb {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
})
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V4(response) => {
|
||||
GetPayloadResponse::Electra(GetPayloadResponseElectra {
|
||||
Ok(GetPayloadResponse::Electra(GetPayloadResponseElectra {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
})
|
||||
requests: response.requests.try_into()?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -754,122 +781,36 @@ impl From<ForkchoiceUpdatedResponse> for JsonForkchoiceUpdatedV1Response {
|
||||
}
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(V1, V2),
|
||||
variant_attributes(
|
||||
derive(Clone, Debug, Serialize, Deserialize),
|
||||
serde(bound = "E: EthSpec", rename_all = "camelCase"),
|
||||
),
|
||||
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
|
||||
)]
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(bound = "E: EthSpec", rename_all = "camelCase", untagged)]
|
||||
pub struct JsonExecutionPayloadBody<E: EthSpec> {
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
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>>,
|
||||
#[superstruct(only(V2))]
|
||||
pub deposit_requests: Option<VariableList<JsonDepositRequest, E::MaxDepositRequestsPerPayload>>,
|
||||
#[superstruct(only(V2))]
|
||||
pub withdrawal_requests:
|
||||
Option<VariableList<JsonWithdrawalRequest, E::MaxWithdrawalRequestsPerPayload>>,
|
||||
#[superstruct(only(V2))]
|
||||
pub consolidation_requests:
|
||||
Option<VariableList<ConsolidationRequest, E::MaxConsolidationRequestsPerPayload>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadBodyV1<E>> for ExecutionPayloadBodyV1<E> {
|
||||
fn from(value: JsonExecutionPayloadBodyV1<E>) -> Self {
|
||||
Self {
|
||||
transactions: value.transactions,
|
||||
withdrawals: value.withdrawals.map(|json_withdrawals| {
|
||||
Withdrawals::<E>::from(
|
||||
json_withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
JsonExecutionPayloadBody::V1(body_v1) => Self::V1(ExecutionPayloadBodyV1 {
|
||||
transactions: body_v1.transactions,
|
||||
withdrawals: body_v1.withdrawals.map(|json_withdrawals| {
|
||||
Withdrawals::<E>::from(
|
||||
json_withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}),
|
||||
}),
|
||||
JsonExecutionPayloadBody::V2(body_v2) => Self::V2(ExecutionPayloadBodyV2 {
|
||||
transactions: body_v2.transactions,
|
||||
withdrawals: body_v2.withdrawals.map(|json_withdrawals| {
|
||||
Withdrawals::<E>::from(
|
||||
json_withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}),
|
||||
deposit_requests: body_v2.deposit_requests.map(|json_receipts| {
|
||||
DepositRequests::<E>::from(
|
||||
json_receipts
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}),
|
||||
withdrawal_requests: body_v2.withdrawal_requests.map(|json_withdrawal_requests| {
|
||||
WithdrawalRequests::<E>::from(
|
||||
json_withdrawal_requests
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}),
|
||||
consolidation_requests: body_v2.consolidation_requests,
|
||||
withdrawals: value.withdrawals.map(|withdrawals| {
|
||||
VariableList::from(withdrawals.into_iter().map(Into::into).collect::<Vec<_>>())
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -950,96 +891,3 @@ impl TryFrom<JsonClientVersionV1> for ClientVersionV1 {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct JsonDepositRequest {
|
||||
pub pubkey: PublicKeyBytes,
|
||||
pub withdrawal_credentials: Hash256,
|
||||
#[serde(with = "serde_utils::u64_hex_be")]
|
||||
pub amount: u64,
|
||||
pub signature: Signature,
|
||||
#[serde(with = "serde_utils::u64_hex_be")]
|
||||
pub index: u64,
|
||||
}
|
||||
|
||||
impl From<DepositRequest> for JsonDepositRequest {
|
||||
fn from(deposit: DepositRequest) -> Self {
|
||||
Self {
|
||||
pubkey: deposit.pubkey,
|
||||
withdrawal_credentials: deposit.withdrawal_credentials,
|
||||
amount: deposit.amount,
|
||||
signature: deposit.signature,
|
||||
index: deposit.index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonDepositRequest> for DepositRequest {
|
||||
fn from(json_deposit: JsonDepositRequest) -> Self {
|
||||
Self {
|
||||
pubkey: json_deposit.pubkey,
|
||||
withdrawal_credentials: json_deposit.withdrawal_credentials,
|
||||
amount: json_deposit.amount,
|
||||
signature: json_deposit.signature,
|
||||
index: json_deposit.index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct JsonWithdrawalRequest {
|
||||
pub source_address: Address,
|
||||
pub validator_pubkey: PublicKeyBytes,
|
||||
#[serde(with = "serde_utils::u64_hex_be")]
|
||||
pub amount: u64,
|
||||
}
|
||||
|
||||
impl From<WithdrawalRequest> for JsonWithdrawalRequest {
|
||||
fn from(withdrawal_request: WithdrawalRequest) -> Self {
|
||||
Self {
|
||||
source_address: withdrawal_request.source_address,
|
||||
validator_pubkey: withdrawal_request.validator_pubkey,
|
||||
amount: withdrawal_request.amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonWithdrawalRequest> for WithdrawalRequest {
|
||||
fn from(json_withdrawal_request: JsonWithdrawalRequest) -> Self {
|
||||
Self {
|
||||
source_address: json_withdrawal_request.source_address,
|
||||
validator_pubkey: json_withdrawal_request.validator_pubkey,
|
||||
amount: json_withdrawal_request.amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use types::{
|
||||
};
|
||||
use types::{
|
||||
ExecutionPayloadBellatrix, ExecutionPayloadCapella, ExecutionPayloadDeneb,
|
||||
ExecutionPayloadElectra,
|
||||
ExecutionPayloadElectra, ExecutionRequests,
|
||||
};
|
||||
|
||||
#[superstruct(
|
||||
@@ -43,6 +43,8 @@ pub struct NewPayloadRequest<'block, E: EthSpec> {
|
||||
pub versioned_hashes: Vec<VersionedHash>,
|
||||
#[superstruct(only(Deneb, Electra))]
|
||||
pub parent_beacon_block_root: Hash256,
|
||||
#[superstruct(only(Electra))]
|
||||
pub execution_requests_list: &'block ExecutionRequests<E>,
|
||||
}
|
||||
|
||||
impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
|
||||
@@ -183,6 +185,7 @@ impl<'a, E: EthSpec> TryFrom<BeaconBlockRef<'a, E>> for NewPayloadRequest<'a, E>
|
||||
.map(kzg_commitment_to_versioned_hash)
|
||||
.collect(),
|
||||
parent_beacon_block_root: block_ref.parent_root,
|
||||
execution_requests_list: &block_ref.body.execution_requests,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user