feat: Duplicate Withdrawal and move try from impls to rpc-compat (#4186)

This commit is contained in:
Supernovahs.eth
2023-09-19 22:27:32 +05:30
committed by GitHub
parent 57c10e5b65
commit 801294252e
20 changed files with 480 additions and 317 deletions

View File

@ -16,6 +16,7 @@ reth-rlp.workspace = true
reth-transaction-pool.workspace = true
reth-interfaces.workspace = true
reth-revm-primitives = { path = "../../revm/revm-primitives" }
reth-rpc-types-compat.workspace = true
## ethereum
revm-primitives.workspace = true

View File

@ -9,8 +9,11 @@ use reth_rpc_types::engine::{
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadV1, PayloadAttributes,
PayloadId,
};
use reth_rpc_types_compat::engine::payload::{
convert_block_to_payload_field_v2, convert_standalonewithdraw_to_withdrawal,
try_block_to_payload_v1, try_block_to_payload_v3,
};
use revm_primitives::{BlockEnv, CfgEnv};
/// Contains the built payload.
///
/// According to the [engine API specification](https://github.com/ethereum/execution-apis/blob/main/src/engine/README.md) the execution layer should build the initial version of the payload with an empty transaction set and then keep update it in order to maximize the revenue.
@ -76,7 +79,7 @@ impl BuiltPayload {
// V1 engine_getPayloadV1 response
impl From<BuiltPayload> for ExecutionPayloadV1 {
fn from(value: BuiltPayload) -> Self {
value.block.into()
try_block_to_payload_v1(value.block)
}
}
@ -85,7 +88,10 @@ impl From<BuiltPayload> for ExecutionPayloadEnvelopeV2 {
fn from(value: BuiltPayload) -> Self {
let BuiltPayload { block, fees, .. } = value;
ExecutionPayloadEnvelopeV2 { block_value: fees, execution_payload: block.into() }
ExecutionPayloadEnvelopeV2 {
block_value: fees,
execution_payload: convert_block_to_payload_field_v2(block),
}
}
}
@ -94,7 +100,7 @@ impl From<BuiltPayload> for ExecutionPayloadEnvelopeV3 {
let BuiltPayload { block, fees, sidecars, .. } = value;
ExecutionPayloadEnvelopeV3 {
execution_payload: block.into(),
execution_payload: try_block_to_payload_v3(block),
block_value: fees,
// From the engine API spec:
//
@ -137,13 +143,23 @@ impl PayloadBuilderAttributes {
/// Derives the unique [PayloadId] for the given parent and attributes
pub fn new(parent: H256, attributes: PayloadAttributes) -> Self {
let id = payload_id(&parent, &attributes);
let withdraw = attributes.withdrawals.map(
|withdrawals: Vec<reth_rpc_types::engine::payload::Withdrawal>| {
withdrawals
.into_iter()
.map(convert_standalonewithdraw_to_withdrawal) // Removed the parentheses here
.collect::<Vec<_>>()
},
);
Self {
id,
parent,
timestamp: attributes.timestamp.as_u64(),
suggested_fee_recipient: attributes.suggested_fee_recipient,
prev_randao: attributes.prev_randao,
withdrawals: attributes.withdrawals.unwrap_or_default(),
withdrawals: withdraw.unwrap_or_default(),
parent_beacon_block_root: attributes.parent_beacon_block_root,
}
}