Skip to content

Introduce TransactionPool and PayloadBuilder #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/assets/check_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exclude_crates=(
reth-scroll-engine-primitives # proptest
reth-scroll-payload # c-kzg
reth-scroll-primitives # c-kzg
reth-scroll-txpool
)

# Array to hold the results
Expand Down
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ members = [
"crates/scroll/node",
"crates/scroll/payload",
"crates/scroll/primitives",
"crates/scroll/txpool",
"crates/scroll/rpc",
"crates/scroll/trie",
"crates/stages/api/",
Expand Down Expand Up @@ -529,6 +530,7 @@ reth-scroll-payload = { path = "crates/scroll/payload" }
reth-scroll-primitives = { path = "crates/scroll/primitives" }
reth-scroll-rpc = { path = "crates/scroll/rpc" }
reth-scroll-trie = { path = "crates/scroll/trie" }
reth-scroll-txpool = { path = "crates/scroll/txpool" }
# TODO (scroll): point to crates.io/tag once the crate is published/a tag is created.
poseidon-bn254 = { git = "https://github.com/scroll-tech/poseidon-bn254", rev = "526a64a", features = ["bn254"] }

Expand Down
11 changes: 11 additions & 0 deletions crates/e2e-test-utils/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ impl TransactionTestContext {
signed.encoded_2718().into()
}

/// Creates a transfer with a nonce and signs it, returning bytes.
pub async fn transfer_tx_nonce_bytes(
chain_id: u64,
wallet: PrivateKeySigner,
nonce: u64,
) -> Bytes {
let tx = tx(chain_id, 21000, None, None, nonce);
let signed = Self::sign_tx(wallet, tx).await;
signed.encoded_2718().into()
}

/// Creates a deployment transaction and signs it, returning an envelope.
pub async fn deploy_tx(
chain_id: u64,
Expand Down
6 changes: 3 additions & 3 deletions crates/scroll/alloy/consensus/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ impl ScrollPooledTransaction {
}
}

/// Converts the transaction into the optimism [`ScrollTxEnvelope`].
pub fn into_op_envelope(self) -> ScrollTxEnvelope {
/// Converts the transaction into the scroll [`ScrollTxEnvelope`].
pub fn into_scroll_envelope(self) -> ScrollTxEnvelope {
match self {
Self::Legacy(tx) => tx.into(),
Self::Eip2930(tx) => tx.into(),
Expand Down Expand Up @@ -394,7 +394,7 @@ impl From<ScrollPooledTransaction> for TxEnvelope {

impl From<ScrollPooledTransaction> for ScrollTxEnvelope {
fn from(tx: ScrollPooledTransaction) -> Self {
tx.into_op_envelope()
tx.into_scroll_envelope()
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/scroll/alloy/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ reth-rpc-engine-api.workspace = true
reth-scroll-engine-primitives.workspace = true
reth-scroll-node.workspace = true
reth-scroll-payload = { workspace = true, features = ["test-utils"] }
reth-scroll-primitives.workspace = true
reth-scroll-chainspec.workspace = true
reth-tasks.workspace = true
reth-tracing.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/scroll/alloy/rpc-types/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod tests {
}

#[test]
fn serialize_empty_optimism_transaction_receipt_fields_struct() {
fn serialize_empty_scroll_transaction_receipt_fields_struct() {
let scroll_fields = ScrollTransactionReceiptFields::default();

let json = serde_json::to_value(scroll_fields).unwrap();
Expand Down
7 changes: 7 additions & 0 deletions crates/scroll/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ impl ScrollHardforks for ScrollChainSpec {
}
}

impl From<ChainSpec> for ScrollChainSpec {
fn from(value: ChainSpec) -> Self {
let genesis = value.genesis;
genesis.into()
}
}

impl From<Genesis> for ScrollChainSpec {
fn from(genesis: Genesis) -> Self {
let scroll_chain_info = ScrollConfigInfo::extract_from(&genesis);
Expand Down
9 changes: 8 additions & 1 deletion crates/scroll/engine-primitives/src/payload/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Payload related types

use alloc::vec::Vec;
use std::fmt::Debug;

use alloy_eips::{eip2718::Decodable2718, eip4895::Withdrawals};
use alloy_primitives::{keccak256, Address, B256};
Expand All @@ -13,7 +14,7 @@ use reth_scroll_primitives::ScrollTransactionSigned;
use scroll_alloy_rpc_types_engine::ScrollPayloadAttributes;

/// Scroll Payload Builder Attributes
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct ScrollPayloadBuilderAttributes {
/// Inner ethereum payload builder attributes
pub payload_attributes: EthPayloadBuilderAttributes,
Expand Down Expand Up @@ -138,6 +139,12 @@ pub(crate) fn payload_id_scroll(
PayloadId::new(out.as_slice()[..8].try_into().expect("sufficient length"))
}

impl From<EthPayloadBuilderAttributes> for ScrollPayloadBuilderAttributes {
fn from(value: EthPayloadBuilderAttributes) -> Self {
Self { payload_attributes: value, ..Default::default() }
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
29 changes: 18 additions & 11 deletions crates/scroll/engine-primitives/src/payload/built.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Outcome of a Scroll block building task with payload attributes provided via the Engine API.

use core::iter;
use std::sync::Arc;

use alloy_eips::eip7685::Requests;
use alloy_primitives::U256;
Expand All @@ -19,8 +20,10 @@ use reth_scroll_primitives::{ScrollBlock, ScrollPrimitives};
pub struct ScrollBuiltPayload {
/// Identifier of the payload
pub(crate) id: PayloadId,
/// Sealed block
pub(crate) block: Arc<SealedBlock<ScrollBlock>>,
/// Block execution data for the payload
pub(crate) block: ExecutedBlockWithTrieUpdates<ScrollPrimitives>,
pub(crate) executed_block: Option<ExecutedBlockWithTrieUpdates<ScrollPrimitives>>,
/// The fees of the block
pub(crate) fees: U256,
}
Expand All @@ -29,10 +32,11 @@ impl ScrollBuiltPayload {
/// Initializes the payload with the given initial block.
pub const fn new(
id: PayloadId,
block: ExecutedBlockWithTrieUpdates<ScrollPrimitives>,
block: Arc<SealedBlock<ScrollBlock>>,
executed_block: Option<ExecutedBlockWithTrieUpdates<ScrollPrimitives>>,
fees: U256,
) -> Self {
Self { id, block, fees }
Self { id, block, executed_block, fees }
}

/// Returns the identifier of the payload.
Expand All @@ -43,13 +47,18 @@ impl ScrollBuiltPayload {
/// Returns the built block(sealed)
#[allow(clippy::missing_const_for_fn)]
pub fn block(&self) -> &SealedBlock<ScrollBlock> {
self.block.sealed_block()
&self.block
}

/// Fees of the block
pub const fn fees(&self) -> U256 {
self.fees
}

/// Converts the value into [`SealedBlock`].
pub fn into_sealed_block(self) -> SealedBlock<ScrollBlock> {
Arc::unwrap_or_clone(self.block)
}
}

impl BuiltPayload for ScrollBuiltPayload {
Expand All @@ -63,8 +72,8 @@ impl BuiltPayload for ScrollBuiltPayload {
self.fees
}

fn executed_block(&self) -> Option<ExecutedBlockWithTrieUpdates<ScrollPrimitives>> {
Some(self.block.clone())
fn executed_block(&self) -> Option<ExecutedBlockWithTrieUpdates<Self::Primitives>> {
self.executed_block.clone()
}

fn requests(&self) -> Option<Requests> {
Expand All @@ -77,7 +86,7 @@ impl From<ScrollBuiltPayload> for ExecutionPayloadV1 {
fn from(value: ScrollBuiltPayload) -> Self {
Self::from_block_unchecked(
value.block().hash(),
&value.block.into_sealed_block().into_block(),
&Arc::unwrap_or_clone(value.block).into_block(),
)
}
}
Expand All @@ -87,12 +96,11 @@ impl From<ScrollBuiltPayload> for ExecutionPayloadEnvelopeV2 {
fn from(value: ScrollBuiltPayload) -> Self {
let ScrollBuiltPayload { block, fees, .. } = value;

let block = block.into_sealed_block();
Self {
block_value: fees,
execution_payload: ExecutionPayloadFieldV2::from_block_unchecked(
block.hash(),
&block.into_block(),
&Arc::unwrap_or_clone(block).into_block(),
),
}
}
Expand All @@ -102,11 +110,10 @@ impl From<ScrollBuiltPayload> for ExecutionPayloadEnvelopeV3 {
fn from(value: ScrollBuiltPayload) -> Self {
let ScrollBuiltPayload { block, fees, .. } = value;

let block = block.into_sealed_block();
Self {
execution_payload: ExecutionPayloadV3::from_block_unchecked(
block.hash(),
&block.into_block(),
&Arc::unwrap_or_clone(block).into_block(),
),
block_value: fees,
// From the engine API spec:
Expand Down
2 changes: 1 addition & 1 deletion crates/scroll/evm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
parent: &SealedHeader<N::BlockHeader>,
_attributes: Self::NextBlockEnvCtx,
) -> ExecutionCtxFor<'_, Self> {
ScrollBlockExecutionCtx { parent_hash: parent.header().parent_hash() }
ScrollBlockExecutionCtx { parent_hash: parent.hash() }
}
}

Expand Down
Loading
Loading