mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
feat: replace duplicate Withdrawal type with alloy (#7931)
This commit is contained in:
@@ -13,8 +13,8 @@ use reth_rpc_types::engine::{
|
||||
ExecutionPayload, ExecutionPayloadBodyV1, ExecutionPayloadV1, PayloadError,
|
||||
};
|
||||
use reth_rpc_types_compat::engine::payload::{
|
||||
convert_standalone_withdraw_to_withdrawal, convert_to_payload_body_v1, try_block_to_payload,
|
||||
try_block_to_payload_v1, try_into_sealed_block, try_payload_v1_to_block,
|
||||
convert_to_payload_body_v1, try_block_to_payload, try_block_to_payload_v1,
|
||||
try_into_sealed_block, try_payload_v1_to_block,
|
||||
};
|
||||
|
||||
fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> ExecutionPayload {
|
||||
@@ -46,11 +46,7 @@ fn payload_body_roundtrip() {
|
||||
.map(|x| TransactionSigned::decode(&mut &x[..]))
|
||||
.collect::<Result<Vec<_>, _>>(),
|
||||
);
|
||||
let withdraw = payload_body.withdrawals.map(|withdrawals| {
|
||||
Withdrawals::new(
|
||||
withdrawals.into_iter().map(convert_standalone_withdraw_to_withdrawal).collect(),
|
||||
)
|
||||
});
|
||||
let withdraw = payload_body.withdrawals.map(Withdrawals::new);
|
||||
assert_eq!(block.withdrawals, withdraw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
//! Standalone functions for engine specific rpc type conversions
|
||||
pub mod payload;
|
||||
pub use payload::{
|
||||
convert_standalone_withdraw_to_withdrawal, convert_withdrawal_to_standalone_withdraw,
|
||||
try_block_to_payload_v1, try_into_sealed_block, try_payload_v1_to_block,
|
||||
};
|
||||
pub use payload::{try_block_to_payload_v1, try_into_sealed_block, try_payload_v1_to_block};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use reth_primitives::{
|
||||
constants::{EMPTY_OMMER_ROOT_HASH, MAXIMUM_EXTRA_DATA_SIZE, MIN_PROTOCOL_BASE_FEE_U256},
|
||||
proofs::{self},
|
||||
Block, Header, SealedBlock, TransactionSigned, UintTryTo, Withdrawal, Withdrawals, B256, U256,
|
||||
Block, Header, SealedBlock, TransactionSigned, UintTryTo, Withdrawals, B256, U256,
|
||||
};
|
||||
use reth_rpc_types::engine::{
|
||||
payload::{ExecutionPayloadBodyV1, ExecutionPayloadFieldV2, ExecutionPayloadInputV2},
|
||||
@@ -65,11 +65,8 @@ pub fn try_payload_v2_to_block(payload: ExecutionPayloadV2) -> Result<Block, Pay
|
||||
// this performs the same conversion as the underlying V1 payload, but calculates the
|
||||
// withdrawals root and adds withdrawals
|
||||
let mut base_sealed_block = try_payload_v1_to_block(payload.payload_inner)?;
|
||||
let withdrawals = Withdrawals::new(
|
||||
payload.withdrawals.iter().map(|w| convert_standalone_withdraw_to_withdrawal(*w)).collect(),
|
||||
);
|
||||
let withdrawals_root = proofs::calculate_withdrawals_root(&withdrawals);
|
||||
base_sealed_block.withdrawals = Some(withdrawals);
|
||||
let withdrawals_root = proofs::calculate_withdrawals_root(&payload.withdrawals);
|
||||
base_sealed_block.withdrawals = Some(payload.withdrawals.into());
|
||||
base_sealed_block.header.withdrawals_root = Some(withdrawals_root);
|
||||
Ok(base_sealed_block)
|
||||
}
|
||||
@@ -124,13 +121,6 @@ pub fn try_block_to_payload_v1(value: SealedBlock) -> ExecutionPayloadV1 {
|
||||
/// Converts [SealedBlock] to [ExecutionPayloadV2]
|
||||
pub fn try_block_to_payload_v2(value: SealedBlock) -> ExecutionPayloadV2 {
|
||||
let transactions = value.raw_transactions();
|
||||
let standalone_withdrawals: Vec<reth_rpc_types::Withdrawal> = value
|
||||
.withdrawals
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(convert_withdrawal_to_standalone_withdraw)
|
||||
.collect();
|
||||
|
||||
ExecutionPayloadV2 {
|
||||
payload_inner: ExecutionPayloadV1 {
|
||||
@@ -149,7 +139,7 @@ pub fn try_block_to_payload_v2(value: SealedBlock) -> ExecutionPayloadV2 {
|
||||
block_hash: value.hash(),
|
||||
transactions,
|
||||
},
|
||||
withdrawals: standalone_withdrawals,
|
||||
withdrawals: value.withdrawals.unwrap_or_default().into_inner(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,15 +147,9 @@ pub fn try_block_to_payload_v2(value: SealedBlock) -> ExecutionPayloadV2 {
|
||||
pub fn block_to_payload_v3(value: SealedBlock) -> ExecutionPayloadV3 {
|
||||
let transactions = value.raw_transactions();
|
||||
|
||||
let withdrawals: Vec<reth_rpc_types::Withdrawal> = value
|
||||
.withdrawals
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(convert_withdrawal_to_standalone_withdraw)
|
||||
.collect();
|
||||
|
||||
ExecutionPayloadV3 {
|
||||
blob_gas_used: value.blob_gas_used.unwrap_or_default(),
|
||||
excess_blob_gas: value.excess_blob_gas.unwrap_or_default(),
|
||||
payload_inner: ExecutionPayloadV2 {
|
||||
payload_inner: ExecutionPayloadV1 {
|
||||
parent_hash: value.parent_hash,
|
||||
@@ -183,11 +167,8 @@ pub fn block_to_payload_v3(value: SealedBlock) -> ExecutionPayloadV3 {
|
||||
block_hash: value.hash(),
|
||||
transactions,
|
||||
},
|
||||
withdrawals,
|
||||
withdrawals: value.withdrawals.unwrap_or_default().into_inner(),
|
||||
},
|
||||
|
||||
blob_gas_used: value.blob_gas_used.unwrap_or_default(),
|
||||
excess_blob_gas: value.excess_blob_gas.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,11 +203,8 @@ pub fn convert_payload_input_v2_to_payload(value: ExecutionPayloadInputV2) -> Ex
|
||||
|
||||
/// Converts [SealedBlock] to [ExecutionPayloadInputV2]
|
||||
pub fn convert_block_to_payload_input_v2(value: SealedBlock) -> ExecutionPayloadInputV2 {
|
||||
let withdraw = value.withdrawals.clone().map(|withdrawals| {
|
||||
withdrawals.into_iter().map(convert_withdrawal_to_standalone_withdraw).collect::<Vec<_>>()
|
||||
});
|
||||
ExecutionPayloadInputV2 {
|
||||
withdrawals: withdraw,
|
||||
withdrawals: value.withdrawals.clone().map(Withdrawals::into_inner),
|
||||
execution_payload: try_block_to_payload_v1(value),
|
||||
}
|
||||
}
|
||||
@@ -295,30 +273,6 @@ pub fn validate_block_hash(
|
||||
Ok(sealed_block)
|
||||
}
|
||||
|
||||
/// Converts [Withdrawal] to [reth_rpc_types::Withdrawal]
|
||||
pub fn convert_withdrawal_to_standalone_withdraw(
|
||||
withdrawal: Withdrawal,
|
||||
) -> reth_rpc_types::Withdrawal {
|
||||
reth_rpc_types::Withdrawal {
|
||||
index: withdrawal.index,
|
||||
validator_index: withdrawal.validator_index,
|
||||
address: withdrawal.address,
|
||||
amount: withdrawal.amount,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [reth_rpc_types::Withdrawal] to [Withdrawal]
|
||||
pub fn convert_standalone_withdraw_to_withdrawal(
|
||||
standalone: reth_rpc_types::Withdrawal,
|
||||
) -> Withdrawal {
|
||||
Withdrawal {
|
||||
index: standalone.index,
|
||||
validator_index: standalone.validator_index,
|
||||
address: standalone.address,
|
||||
amount: standalone.amount,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [Block] to [ExecutionPayloadBodyV1]
|
||||
pub fn convert_to_payload_body_v1(value: Block) -> ExecutionPayloadBodyV1 {
|
||||
let transactions = value.body.into_iter().map(|tx| {
|
||||
@@ -326,10 +280,10 @@ pub fn convert_to_payload_body_v1(value: Block) -> ExecutionPayloadBodyV1 {
|
||||
tx.encode_enveloped(&mut out);
|
||||
out.into()
|
||||
});
|
||||
let withdraw: Option<Vec<reth_rpc_types::Withdrawal>> = value.withdrawals.map(|withdrawals| {
|
||||
withdrawals.into_iter().map(convert_withdrawal_to_standalone_withdraw).collect::<Vec<_>>()
|
||||
});
|
||||
ExecutionPayloadBodyV1 { transactions: transactions.collect(), withdrawals: withdraw }
|
||||
ExecutionPayloadBodyV1 {
|
||||
transactions: transactions.collect(),
|
||||
withdrawals: value.withdrawals.map(Withdrawals::into_inner),
|
||||
}
|
||||
}
|
||||
|
||||
/// Transforms a [SealedBlock] into a [ExecutionPayloadV1]
|
||||
|
||||
Reference in New Issue
Block a user