Skip to content
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

feat: scroll l1 message transaction #41

Merged
merged 11 commits into from
Nov 28, 2024
10 changes: 10 additions & 0 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions crates/optimism/bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

/// Re-exported from `reth_optimism_cli`.
pub mod cli {
Expand Down
6 changes: 2 additions & 4 deletions crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![allow(missing_docs, rustdoc::missing_crate_level_docs)]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

use clap::Parser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
Expand Down
6 changes: 2 additions & 4 deletions crates/optimism/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
)]
#![cfg_attr(all(not(test), feature = "optimism"), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

/// Optimism chain specification parser.
pub mod chainspec;
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ reth-optimism-chainspec.workspace = true

[features]
optimism = ["reth-primitives/optimism"]
scroll = []
3 changes: 2 additions & 1 deletion crates/optimism/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH};
use alloy_primitives::{B64, U256};
Expand Down
6 changes: 2 additions & 4 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

extern crate alloc;

Expand Down
6 changes: 2 additions & 4 deletions crates/optimism/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

/// CLI argument parsing for the optimism node.
pub mod args;
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/node/tests/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]

#[cfg(feature = "optimism")]
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
mod p2p;

const fn main() {}
4 changes: 2 additions & 2 deletions crates/optimism/node/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]

#[cfg(feature = "optimism")]
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
mod builder;

#[cfg(feature = "optimism")]
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
mod priority;

const fn main() {}
2 changes: 1 addition & 1 deletion crates/optimism/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ optimism = [
"reth-execution-types/optimism",
"reth-optimism-consensus/optimism"
]
scroll = []
scroll = []
6 changes: 2 additions & 4 deletions crates/optimism/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
#![cfg_attr(all(not(test), feature = "optimism"), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![allow(clippy::useless_let_if_seq)]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

pub mod builder;
pub use builder::OpPayloadBuilder;
Expand Down
6 changes: 2 additions & 4 deletions crates/optimism/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
)]
#![cfg_attr(all(not(test), feature = "optimism"), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
// Don't use the crate if `scroll` feature is used.
#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))]
#![cfg(not(feature = "scroll"))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(all(feature = "optimism", not(feature = "scroll")))]

pub mod error;
pub mod eth;
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ serde = [
"bytes/serde",
"rand/serde",
"reth-codecs?/serde",
"revm-primitives/serde",
"roaring/serde",
"revm-primitives/serde",
"reth-scroll-primitives?/serde"
]
reth-codec = [
"dep:reth-codecs",
Expand Down
7 changes: 5 additions & 2 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ alloy-trie = { workspace = true, features = ["serde"] }

# scroll
revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["serde"] }
reth-scroll-primitives = { workspace = true, optional = true, features = ["serde"] }

# optimism
op-alloy-rpc-types = { workspace = true, optional = true }
Expand Down Expand Up @@ -132,7 +133,8 @@ arbitrary = [
"op-alloy-rpc-types?/arbitrary",
"reth-codecs?/arbitrary",
"alloy-trie/arbitrary",
"reth-trie-common/arbitrary"
"reth-trie-common/arbitrary",
"reth-scroll-primitives?/arbitrary"
]
secp256k1 = ["dep:secp256k1"]
c-kzg = [
Expand Down Expand Up @@ -170,7 +172,8 @@ serde-bincode-compat = [
scroll = [
"reth-trie-common/scroll",
"reth-primitives-traits/scroll",
"reth-testing-utils/scroll"
"reth-testing-utils/scroll",
"reth-scroll-primitives"
]

[[bench]]
Expand Down
129 changes: 102 additions & 27 deletions crates/primitives/src/alloy_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,34 +123,64 @@ impl TryFrom<AnyRpcTransaction> for TransactionSigned {
let (tx, signature, hash) = tx.into_parts();
(Transaction::Eip7702(tx), signature, hash)
}
#[cfg(feature = "optimism")]
AnyTxEnvelope::Unknown(alloy_network::UnknownTxEnvelope { hash, inner }) => {
#[cfg(any(feature = "optimism", feature = "scroll"))]
AnyTxEnvelope::Unknown(alloy_network::UnknownTxEnvelope { hash: _hash, inner }) => {
use alloy_consensus::Transaction as _;

if inner.ty() == crate::TxType::Deposit {
let fields: op_alloy_rpc_types::OpTransactionFields = inner
.fields
.clone()
.deserialize_into::<op_alloy_rpc_types::OpTransactionFields>()
.map_err(|e| ConversionError::Custom(e.to_string()))?;
(
Transaction::Deposit(op_alloy_consensus::TxDeposit {
source_hash: fields.source_hash.ok_or_else(|| {
ConversionError::Custom("MissingSourceHash".to_string())
})?,
from: tx.from,
to: revm_primitives::TxKind::from(inner.to()),
mint: fields.mint.filter(|n| *n != 0),
value: inner.value(),
gas_limit: inner.gas_limit(),
is_system_transaction: fields.is_system_tx.unwrap_or(false),
input: inner.input().clone(),
}),
op_alloy_consensus::TxDeposit::signature(),
hash,
)
} else {
return Err(ConversionError::Custom("unknown transaction type".to_string()))
match TryInto::<crate::TxType>::try_into(inner.ty())
.map_err(|e| ConversionError::Custom(e.to_string()))?
frisitano marked this conversation as resolved.
Show resolved Hide resolved
{
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
crate::TxType::Deposit => {
let fields: op_alloy_rpc_types::OpTransactionFields = inner
.fields
.clone()
.deserialize_into::<op_alloy_rpc_types::OpTransactionFields>()
.map_err(|e| ConversionError::Custom(e.to_string()))?;
(
Transaction::Deposit(op_alloy_consensus::TxDeposit {
source_hash: fields.source_hash.ok_or_else(|| {
ConversionError::Custom("MissingSourceHash".to_string())
})?,
from: tx.from,
to: revm_primitives::TxKind::from(inner.to()),
mint: fields.mint.filter(|n| *n != 0),
value: inner.value(),
gas_limit: inner.gas_limit(),
is_system_transaction: fields.is_system_tx.unwrap_or(false),
input: inner.input().clone(),
}),
op_alloy_consensus::TxDeposit::signature(),
_hash,
)
}
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
crate::TxType::L1Message => {
let fields =
inner
.fields
.clone()
.deserialize_into::<reth_scroll_primitives::ScrollL1MessageTransactionFields>()
.map_err(|e| ConversionError::Custom(e.to_string()))?;
(
Transaction::L1Message(reth_scroll_primitives::TxL1Message {
queue_index: fields.queue_index,
gas_limit: inner.gas_limit(),
to: inner.to().ok_or(ConversionError::Custom(
"Scroll L1 message transaction do not support create transaction"
.to_string(),
))?,
value: inner.value(),
sender: fields.sender,
input: inner.input().clone(),
}),
reth_scroll_primitives::TxL1Message::signature(),
_hash,
)
}
_ => {
return Err(ConversionError::Custom("unknown transaction type".to_string()))
}
}
}
_ => return Err(ConversionError::Custom("unknown transaction type".to_string())),
Expand All @@ -161,7 +191,7 @@ impl TryFrom<AnyRpcTransaction> for TransactionSigned {
}

#[cfg(test)]
#[cfg(feature = "optimism")]
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
mod tests {
use super::*;
use alloy_primitives::{address, Address, B256, U256};
Expand Down Expand Up @@ -270,3 +300,48 @@ mod tests {
}
}
}

#[cfg(test)]
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
mod tests {
use super::*;
use alloy_primitives::{address, U256};

#[test]
fn test_scroll_l1_message_tx() {
// https://scrollscan.com/tx/0x36199419dbdb7823235de4b73e3d90a61c7b1f343b7a682a271c3055249e81f9
let input = r#"{
"hash":"0x36199419dbdb7823235de4b73e3d90a61c7b1f343b7a682a271c3055249e81f9",
"nonce":"0x0",
"blockHash":"0x4aca26460c31be3948e8466681ad87891326a964422c9370d4c1913f3bed4b10",
"blockNumber":"0xabf06f",
"transactionIndex":"0x0",
"from":"0x7885bcbd5cecef1336b5300fb5186a12ddd8c478",
"to":"0x781e90f1c8fc4611c9b7497c3b47f99ef6969cbc",
"value":"0x0",
"gasPrice":"0x0",
"gas":"0x1e8480",
"input":"0x8ef1332e000000000000000000000000c186fa914353c44b2e33ebe05f21846f1048beda0000000000000000000000003bad7ad0728f9917d1bf08af5782dcbd516cdd96000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e76ab00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000044493a4f84f464e58d4bfa93bcc57abfb14dbe1b8ff46cd132b5709aab227f269727943d2f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"r":"0x0",
"s":"0x0",
"v":"0x0",
"type":"0x7e",
"queueIndex":"0xe76ab",
"sender":"0x7885bcbd5cecef1336b5300fb5186a12ddd8c478"
}"#;
let alloy_tx: WithOtherFields<alloy_rpc_types::Transaction<AnyTxEnvelope>> =
serde_json::from_str(input).expect("failed to deserialize");

let TransactionSigned { transaction: reth_tx, .. } =
alloy_tx.try_into().expect("failed to convert");
if let Transaction::L1Message(l1_message_tx) = reth_tx {
assert_eq!(l1_message_tx.queue_index, 0xe76ab);
assert_eq!(l1_message_tx.gas_limit, 0x1e8480);
assert_eq!(l1_message_tx.to, address!("781e90f1c8fc4611c9b7497c3b47f99ef6969cbc"));
assert_eq!(l1_message_tx.value, U256::ZERO);
assert_eq!(l1_message_tx.sender, address!("7885bcbd5cecef1336b5300fb5186a12ddd8c478"));
} else {
panic!("Expected L1 message transaction");
}
}
}
5 changes: 5 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "optimism")]
use op_alloy_consensus as _;
#[cfg(feature = "scroll")]
use reth_scroll_primitives as _;

extern crate alloc;

#[cfg(feature = "alloy-compat")]
Expand Down
Loading
Loading