Skip to content

Commit 0a3fe42

Browse files
authored
Use payload id optimism function from reth (#368)
1 parent 7caffb9 commit 0a3fe42

File tree

5 files changed

+7
-71
lines changed

5 files changed

+7
-71
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ eyre = "0.6.12"
2424
url = "2.2.0"
2525
sha2 = { version = "0.10", default-features = false }
2626

27+
# Reth deps
28+
reth-optimism-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.5.0" }
29+
2730
# Alloy libraries
2831
alloy-rpc-types-engine = "1.0.13"
2932
alloy-rpc-types-eth = "1.0.13"

crates/rollup-boost/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ eyre.workspace = true
1818
url.workspace = true
1919
sha2.workspace = true
2020

21+
reth-optimism-payload-builder.workspace = true
2122
op-alloy-rpc-types-engine.workspace = true
2223
alloy-rpc-types-engine.workspace = true
2324
alloy-rpc-types-eth.workspace = true

crates/rollup-boost/src/flashblocks/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::RpcClientError;
66
use crate::flashblocks::metrics::FlashblocksServiceMetrics;
77
use crate::{
88
ClientResult, EngineApiExt, NewPayload, OpExecutionPayloadEnvelope, PayloadVersion, RpcClient,
9-
payload_id_optimism,
109
};
1110
use alloy_primitives::U256;
1211
use alloy_rpc_types_engine::{
@@ -20,6 +19,7 @@ use op_alloy_rpc_types_engine::{
2019
OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4, OpExecutionPayloadV4,
2120
OpPayloadAttributes,
2221
};
22+
use reth_optimism_payload_builder::payload_id_optimism;
2323
use serde::{Deserialize, Serialize};
2424
use std::sync::Arc;
2525
use thiserror::Error;

crates/rollup-boost/src/payload.rs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use alloy_primitives::private::alloy_rlp::Encodable;
2-
use alloy_primitives::{B256, Bytes, keccak256};
1+
use alloy_primitives::{B256, Bytes};
32
use futures::{StreamExt as _, stream};
43
use moka::future::Cache;
54

65
use alloy_rpc_types_engine::{ExecutionPayload, ExecutionPayloadV3, PayloadId};
76
use op_alloy_rpc_types_engine::{
87
OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4, OpExecutionPayloadV4,
9-
OpPayloadAttributes,
108
};
119

1210
const CACHE_SIZE: u64 = 100;
@@ -268,70 +266,3 @@ impl PayloadTraceContext {
268266
}
269267
}
270268
}
271-
272-
/// Generates the payload id for the configured payload from the [`OpPayloadAttributes`].
273-
///
274-
/// Returns an 8-byte identifier by hashing the payload components with sha256 hash.
275-
pub(crate) fn payload_id_optimism(
276-
parent: &B256,
277-
attributes: &OpPayloadAttributes,
278-
payload_version: u8,
279-
) -> PayloadId {
280-
use sha2::Digest;
281-
let mut hasher = sha2::Sha256::new();
282-
hasher.update(parent.as_slice());
283-
hasher.update(&attributes.payload_attributes.timestamp.to_be_bytes()[..]);
284-
hasher.update(attributes.payload_attributes.prev_randao.as_slice());
285-
hasher.update(
286-
attributes
287-
.payload_attributes
288-
.suggested_fee_recipient
289-
.as_slice(),
290-
);
291-
if let Some(withdrawals) = &attributes.payload_attributes.withdrawals {
292-
let mut buf = Vec::new();
293-
withdrawals.encode(&mut buf);
294-
hasher.update(buf);
295-
}
296-
297-
if let Some(parent_beacon_block) = attributes.payload_attributes.parent_beacon_block_root {
298-
hasher.update(parent_beacon_block);
299-
}
300-
301-
let no_tx_pool = attributes.no_tx_pool.unwrap_or_default();
302-
if no_tx_pool
303-
|| attributes
304-
.transactions
305-
.as_ref()
306-
.is_some_and(|txs| !txs.is_empty())
307-
{
308-
hasher.update([no_tx_pool as u8]);
309-
let txs_len = attributes
310-
.transactions
311-
.as_ref()
312-
.map(|txs| txs.len())
313-
.unwrap_or_default();
314-
hasher.update(&txs_len.to_be_bytes()[..]);
315-
if let Some(txs) = &attributes.transactions {
316-
for tx in txs {
317-
// we have to just hash the bytes here because otherwise we would need to decode
318-
// the transactions here which really isn't ideal
319-
let tx_hash = keccak256(tx);
320-
// maybe we can try just taking the hash and not decoding
321-
hasher.update(tx_hash)
322-
}
323-
}
324-
}
325-
326-
if let Some(gas_limit) = attributes.gas_limit {
327-
hasher.update(gas_limit.to_be_bytes());
328-
}
329-
330-
if let Some(eip_1559_params) = attributes.eip_1559_params {
331-
hasher.update(eip_1559_params.as_slice());
332-
}
333-
334-
let mut out = hasher.finalize();
335-
out[0] = payload_version;
336-
PayloadId::new(out.as_slice()[..8].try_into().expect("sufficient length"))
337-
}

0 commit comments

Comments
 (0)