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

Str 829 enable eoa flag #666

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 Cargo.lock

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

19 changes: 18 additions & 1 deletion bin/strata-reth/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
mod db;

use std::{fs, future::Future, path::PathBuf, sync::Arc};
use std::{fs, future::Future, path::PathBuf, str::FromStr, sync::Arc};

use alloy_genesis::Genesis;
use clap::Parser;
use reth::{
args::LogArgs,
builder::{NodeBuilder, WithLaunchContext},
revm::primitives::Address,
CliRunner,
};
use reth_chainspec::ChainSpec;
Expand Down Expand Up @@ -39,8 +40,16 @@
if let Err(err) = run(command, |builder, ext| async move {
let datadir = builder.config().datadir().data_dir().to_path_buf();

let allowed_addrs: Vec<Address> = ext
.allowed_eoa_addrs
.into_iter()
.map(|x| Address::from_str(&x))
.collect::<Result<_, _>>()?; // TODO: better error messaging

Check warning on line 47 in bin/strata-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-reth/src/main.rs#L43-L47

Added lines #L43 - L47 were not covered by tests

let node_args = StrataNodeArgs {
sequencer_http: ext.sequencer_http.clone(),
allowed_eoa_addrs: allowed_addrs,
enable_eoa: ext.enable_eoa,

Check warning on line 52 in bin/strata-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-reth/src/main.rs#L51-L52

Added lines #L51 - L52 were not covered by tests
};

let mut node_builder = builder.node(StrataEthereumNode::new(node_args));
Expand Down Expand Up @@ -102,6 +111,14 @@
/// Rpc of sequener's reth node to forward transactions to.
#[arg(long, required = false)]
pub sequencer_http: Option<String>,

/// To enable EOA txs or not.
#[arg(long, default_value_t = false)]
pub enable_eoa: bool,

Check warning on line 117 in bin/strata-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-reth/src/main.rs#L116-L117

Added lines #L116 - L117 were not covered by tests

/// Allowed EOA addresses, if `enable_eoa` is set to false.
#[arg(long, num_args(1..))]
pub allowed_eoa_addrs: Vec<String>,

Check warning on line 121 in bin/strata-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-reth/src/main.rs#L121

Added line #L121 was not covered by tests
}

#[derive(Debug, Clone, Default)]
Expand Down
4 changes: 4 additions & 0 deletions crates/reth/node/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use revm_primitives::Address;

#[derive(Debug, Clone, Default)]
pub struct StrataNodeArgs {
pub sequencer_http: Option<String>,
pub enable_eoa: bool,
pub allowed_eoa_addrs: Vec<Address>,
}
20 changes: 18 additions & 2 deletions crates/reth/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
};
use reth_transaction_pool::{PoolTransaction, TransactionPool};
use revm_primitives::alloy_primitives;
use strata_reth_rpc::{SequencerClient, StrataEthApi};
use strata_reth_rpc::{EOAMode, SequencerClient, StrataEthApi};

use crate::{
args::StrataNodeArgs,
Expand Down Expand Up @@ -165,6 +165,10 @@
fn add_ons(&self) -> Self::AddOns {
Self::AddOns::builder()
.with_sequencer(self.args.sequencer_http.clone())
.with_eoa_mode(EOAMode::new(
self.args.enable_eoa,
self.args.allowed_eoa_addrs.clone(),
))

Check warning on line 171 in crates/reth/node/src/node.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/node/src/node.rs#L168-L171

Added lines #L168 - L171 were not covered by tests
.build()
}
}
Expand Down Expand Up @@ -257,6 +261,8 @@
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
sequencer_client: Option<SequencerClient>,
/// Whether EOA should be enabled or not.
eoa_mode: EOAMode,
}

impl StrataAddOnsBuilder {
Expand All @@ -265,6 +271,12 @@
self.sequencer_client = sequencer_client.map(SequencerClient::new);
self
}

/// With [`EOAMode`] set to given value.
pub fn with_eoa_mode(mut self, eoa_mode: EOAMode) -> Self {
self.eoa_mode = eoa_mode;
self
}

Check warning on line 279 in crates/reth/node/src/node.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/node/src/node.rs#L276-L279

Added lines #L276 - L279 were not covered by tests
}

impl StrataAddOnsBuilder {
Expand All @@ -273,13 +285,17 @@
where
N: FullNodeComponents<Types: NodeTypes<Primitives = StrataPrimitives>>,
{
let Self { sequencer_client } = self;
let Self {
sequencer_client,
eoa_mode,
} = self;

Check warning on line 291 in crates/reth/node/src/node.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/node/src/node.rs#L288-L291

Added lines #L288 - L291 were not covered by tests

StrataAddOns {
rpc_add_ons: RpcAddOns::new(
move |ctx| {
StrataEthApi::<N>::builder()
.with_sequencer(sequencer_client)
.with_eoa_mode(eoa_mode)

Check warning on line 298 in crates/reth/node/src/node.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/node/src/node.rs#L298

Added line #L298 was not covered by tests
.build(ctx)
},
Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/reth/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ reth-network-api.workspace = true
reth-node-api.workspace = true
reth-node-builder.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-provider.workspace = true
reth-revm.workspace = true
reth-rpc.workspace = true
Expand Down
16 changes: 15 additions & 1 deletion crates/reth/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
};
use reth_transaction_pool::TransactionPool;

use crate::SequencerClient;
use crate::{EOAMode, SequencerClient};

/// Adapter for [`EthApiInner`], which holds all the data required to serve core `eth_` API.
pub type EthApiNodeBackend<N> = EthApiInner<
Expand Down Expand Up @@ -268,20 +268,27 @@
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
sequencer_client: Option<SequencerClient>,
/// Whether EOA should be enabled or not.
eoa_mode: EOAMode,
}

#[derive(Default)]
pub struct StrataEthApiBuilder {
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
sequencer_client: Option<SequencerClient>,
/// Whether EOA should be enabled or not.
eoa_mode: EOAMode,
}

impl StrataEthApiBuilder {
/// Creates a [`StrataEthApiBuilder`] instance.
pub const fn new() -> Self {
Self {
sequencer_client: None,
eoa_mode: EOAMode::Disabled {
allowed_eoa_addrs: Vec::new(),
},

Check warning on line 291 in crates/reth/rpc/src/eth/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/eth/mod.rs#L289-L291

Added lines #L289 - L291 were not covered by tests
}
}

Expand All @@ -290,6 +297,12 @@
self.sequencer_client = sequencer_client;
self
}

/// With [`EOAMode`].
pub fn with_eoa_mode(mut self, eoa_mode: EOAMode) -> Self {
self.eoa_mode = eoa_mode;
self
}

Check warning on line 305 in crates/reth/rpc/src/eth/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/eth/mod.rs#L302-L305

Added lines #L302 - L305 were not covered by tests
}

impl StrataEthApiBuilder {
Expand Down Expand Up @@ -329,6 +342,7 @@
inner: Arc::new(StrataEthApiInner {
eth_api,
sequencer_client: self.sequencer_client,
eoa_mode: self.eoa_mode,

Check warning on line 345 in crates/reth/rpc/src/eth/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/eth/mod.rs#L345

Added line #L345 was not covered by tests
}),
}
}
Expand Down
21 changes: 19 additions & 2 deletions crates/reth/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use alloy_rpc_types_eth::{Transaction, TransactionInfo, TransactionRequest};
use reth_node_api::FullNodeComponents;
use reth_primitives::{RecoveredTx, TransactionSigned};
use reth_primitives_traits::SignedTransaction;
use reth_provider::{
BlockReader, BlockReaderIdExt, ProviderTx, ReceiptProvider, TransactionsProvider,
};
Expand All @@ -15,7 +16,7 @@
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};

use crate::{SequencerClient, StrataEthApi, StrataNodeCore};
use crate::{EOAMode, SequencerClient, StrataEthApi, StrataNodeCore};

impl<N> EthTransactions for StrataEthApi<N>
where
Expand All @@ -30,9 +31,25 @@
///
/// Returns the hash of the transaction.
async fn send_raw_transaction(&self, tx: Bytes) -> Result<B256, Self::Error> {
let recovered = recover_raw_transaction(&tx)?;
let recovered: RecoveredTx<
<<Self::Pool as TransactionPool>::Transaction as PoolTransaction>::Pooled,
> = recover_raw_transaction(&tx)?;
let sender = recovered.recover_signer_unchecked();

Check warning on line 37 in crates/reth/rpc/src/eth/transaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/eth/transaction.rs#L34-L37

Added lines #L34 - L37 were not covered by tests
let pool_transaction = <Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);

// Check if EOA disabled and if so the sender is in the allowed list
match &self.inner.eoa_mode {
EOAMode::Enabled => {}
EOAMode::Disabled { allowed_eoa_addrs } => {
if sender
.map(|x| allowed_eoa_addrs.contains(&x))
.unwrap_or(false)

Check warning on line 46 in crates/reth/rpc/src/eth/transaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/eth/transaction.rs#L40-L46

Added lines #L40 - L46 were not covered by tests
{
return Err(EthApiError::Unsupported("EOA txs are not allowed").into());
}

Check warning on line 49 in crates/reth/rpc/src/eth/transaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/eth/transaction.rs#L48-L49

Added lines #L48 - L49 were not covered by tests
}
}

// On Strata, transactions are forwarded directly to the sequencer to be included in
// blocks that it builds.
if let Some(client) = self.raw_tx_forwarder().as_ref() {
Expand Down
30 changes: 29 additions & 1 deletion crates/reth/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

pub use eth::{StrataEthApi, StrataNodeCore};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use revm_primitives::alloy_primitives::B256;
use revm_primitives::{alloy_primitives::B256, Address};
pub use rpc::StrataRPC;
pub use sequencer::SequencerClient;
use serde::{Deserialize, Serialize};
Expand All @@ -31,3 +31,31 @@
Raw(#[serde(with = "hex::serde")] Vec<u8>),
Json(EvmBlockStfInput),
}

#[derive(Debug, Clone)]
pub enum EOAMode {
Disabled { allowed_eoa_addrs: Vec<Address> }, // TODO: Maybe use NonEmptyVec like struct
// one element
Enabled,
}

impl EOAMode {
pub fn new(enable: bool, allowed_eoa_addrs: Vec<Address>) -> Self {
if enable {
if !allowed_eoa_addrs.is_empty() {
// TODO: possibly warn, but would be better if this happened around the boundary
}
Self::Enabled

Check warning on line 48 in crates/reth/rpc/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/lib.rs#L43-L48

Added lines #L43 - L48 were not covered by tests
} else {
Self::Disabled { allowed_eoa_addrs }

Check warning on line 50 in crates/reth/rpc/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/lib.rs#L50

Added line #L50 was not covered by tests
}
}

Check warning on line 52 in crates/reth/rpc/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/lib.rs#L52

Added line #L52 was not covered by tests
}

impl Default for EOAMode {
fn default() -> Self {
Self::Disabled {
allowed_eoa_addrs: Vec::new(),
}
}

Check warning on line 60 in crates/reth/rpc/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/reth/rpc/src/lib.rs#L56-L60

Added lines #L56 - L60 were not covered by tests
}
Loading