[go: up one dir, main page]

Skip to content

Commit

Permalink
chore(rpc): remove parent beacon root from conversion functions (para…
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Aug 5, 2024
1 parent 6f8cba6 commit 5a8a7bc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
3 changes: 2 additions & 1 deletion bin/reth-bench/src/bench/new_payload_fcu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ impl Command {

let versioned_hashes: Vec<B256> =
block.blob_versioned_hashes().into_iter().copied().collect();
let (payload, parent_beacon_block_root) = block_to_payload(block);
let parent_beacon_block_root = block.parent_beacon_block_root;
let payload = block_to_payload(block);

debug!(?block_number, "Sending payload",);

Expand Down
3 changes: 2 additions & 1 deletion bin/reth-bench/src/bench/new_payload_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl Command {

let versioned_hashes: Vec<B256> =
block.blob_versioned_hashes().into_iter().copied().collect();
let (payload, parent_beacon_block_root) = block_to_payload(block);
let parent_beacon_block_root = block.parent_beacon_block_root;
let payload = block_to_payload(block);

let block_number = payload.block_number();

Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/engine-primitives/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV3 {
let EthBuiltPayload { block, fees, sidecars, .. } = value;

Self {
execution_payload: block_to_payload_v3(block).0,
execution_payload: block_to_payload_v3(block),
block_value: fees,
// From the engine API spec:
//
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl From<OptimismBuiltPayload> for OptimismExecutionPayloadEnvelopeV3 {
B256::ZERO
};
Self {
execution_payload: block_to_payload_v3(block).0,
execution_payload: block_to_payload_v3(block),
block_value: fees,
// From the engine API spec:
//
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> Executi
withdrawals: transformed.withdrawals,
requests: transformed.requests,
})
.0
}

#[test]
Expand Down
26 changes: 11 additions & 15 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ pub fn try_payload_v4_to_block(payload: ExecutionPayloadV4) -> Result<Block, Pay
}

/// Converts [`SealedBlock`] to [`ExecutionPayload`]
pub fn block_to_payload(value: SealedBlock) -> (ExecutionPayload, Option<B256>) {
pub fn block_to_payload(value: SealedBlock) -> ExecutionPayload {
if value.header.requests_root.is_some() {
(ExecutionPayload::V4(block_to_payload_v4(value)), None)
// block with requests root: V3
ExecutionPayload::V4(block_to_payload_v4(value))
} else if value.header.parent_beacon_block_root.is_some() {
// block with parent beacon block root: V3
let (payload, beacon_block_root) = block_to_payload_v3(value);
(ExecutionPayload::V3(payload), beacon_block_root)
ExecutionPayload::V3(block_to_payload_v3(value))
} else if value.withdrawals.is_some() {
// block with withdrawals: V2
(ExecutionPayload::V2(block_to_payload_v2(value)), None)
ExecutionPayload::V2(block_to_payload_v2(value))
} else {
// otherwise V1
(ExecutionPayload::V1(block_to_payload_v1(value)), None)
ExecutionPayload::V1(block_to_payload_v1(value))
}
}

Expand Down Expand Up @@ -184,11 +184,9 @@ pub fn block_to_payload_v2(value: SealedBlock) -> ExecutionPayloadV2 {
}

/// Converts [`SealedBlock`] to [`ExecutionPayloadV3`], and returns the parent beacon block root.
pub fn block_to_payload_v3(value: SealedBlock) -> (ExecutionPayloadV3, Option<B256>) {
pub fn block_to_payload_v3(value: SealedBlock) -> ExecutionPayloadV3 {
let transactions = value.raw_transactions();

let parent_beacon_block_root = value.header.parent_beacon_block_root;
let payload = ExecutionPayloadV3 {
ExecutionPayloadV3 {
blob_gas_used: value.blob_gas_used.unwrap_or_default(),
excess_blob_gas: value.excess_blob_gas.unwrap_or_default(),
payload_inner: ExecutionPayloadV2 {
Expand All @@ -210,9 +208,7 @@ pub fn block_to_payload_v3(value: SealedBlock) -> (ExecutionPayloadV3, Option<B2
},
withdrawals: value.withdrawals.unwrap_or_default().into_inner(),
},
};

(payload, parent_beacon_block_root)
}
}

/// Converts [`SealedBlock`] to [`ExecutionPayloadV4`]
Expand Down Expand Up @@ -242,7 +238,7 @@ pub fn block_to_payload_v4(mut value: SealedBlock) -> ExecutionPayloadV4 {
deposit_requests,
withdrawal_requests,
consolidation_requests,
payload_inner: block_to_payload_v3(value).0,
payload_inner: block_to_payload_v3(value),
}
}

Expand Down Expand Up @@ -497,7 +493,7 @@ mod tests {
let converted_payload = block_to_payload_v3(block.seal_slow());

// ensure the payloads are the same
assert_eq!((new_payload, Some(parent_beacon_block_root)), converted_payload);
assert_eq!(new_payload, converted_payload);
}

#[test]
Expand Down

0 comments on commit 5a8a7bc

Please sign in to comment.