Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions crates/optimism/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub struct RollupArgs {
/// Optional headers to use when connecting to the sequencer.
#[arg(long = "rollup.sequencer-headers", requires = "sequencer")]
pub sequencer_headers: Vec<String>,

/// Minimum suggested priority fee (tip), default `1_000_000`
#[arg(long, default_value_t = 1_000_000)]
pub min_suggested_priority_fee: u64,
}

impl Default for RollupArgs {
Expand All @@ -73,6 +77,7 @@ impl Default for RollupArgs {
supervisor_http: DEFAULT_SUPERVISOR_URL.to_string(),
supervisor_safety_level: SafetyLevel::CrossUnsafe,
sequencer_headers: Vec::new(),
min_suggested_priority_fee: 1_000_000,
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ where
.with_sequencer_headers(self.args.sequencer_headers.clone())
.with_da_config(self.da_config.clone())
.with_enable_tx_conditional(self.args.enable_tx_conditional)
.with_min_suggested_priority_fee(self.args.min_suggested_priority_fee)
.build()
}
}
Expand Down Expand Up @@ -254,6 +255,7 @@ pub struct OpAddOns<N: FullNodeComponents, EthB: EthApiBuilder<N>, EV, EB> {
pub sequencer_headers: Vec<String>,
/// Enable transaction conditionals.
enable_tx_conditional: bool,
min_suggested_priority_fee: u64,
}

impl<N, NetworkT> Default
Expand Down Expand Up @@ -302,13 +304,15 @@ where
sequencer_url,
sequencer_headers,
enable_tx_conditional,
min_suggested_priority_fee,
} = self;
OpAddOns {
rpc_add_ons: rpc_add_ons.with_engine_api(engine_api_builder),
da_config,
sequencer_url,
sequencer_headers,
enable_tx_conditional,
min_suggested_priority_fee,
}
}

Expand All @@ -320,13 +324,15 @@ where
sequencer_url,
sequencer_headers,
enable_tx_conditional,
min_suggested_priority_fee,
} = self;
OpAddOns {
rpc_add_ons: rpc_add_ons.with_engine_validator(engine_validator_builder),
da_config,
sequencer_url,
sequencer_headers,
enable_tx_conditional,
min_suggested_priority_fee,
}
}

Expand Down Expand Up @@ -382,6 +388,7 @@ where
sequencer_url,
sequencer_headers,
enable_tx_conditional,
..
} = self;

let builder = reth_optimism_payload_builder::OpPayloadBuilder::new(
Expand Down Expand Up @@ -507,6 +514,8 @@ pub struct OpAddOnsBuilder<NetworkT> {
enable_tx_conditional: bool,
/// Marker for network types.
_nt: PhantomData<NetworkT>,
/// Minimum suggested priority fee (tip)
min_suggested_priority_fee: u64,
}

impl<NetworkT> Default for OpAddOnsBuilder<NetworkT> {
Expand All @@ -516,6 +525,7 @@ impl<NetworkT> Default for OpAddOnsBuilder<NetworkT> {
sequencer_headers: Vec::new(),
da_config: None,
enable_tx_conditional: false,
min_suggested_priority_fee: 1_000_000,
_nt: PhantomData,
}
}
Expand Down Expand Up @@ -545,6 +555,12 @@ impl<NetworkT> OpAddOnsBuilder<NetworkT> {
self.enable_tx_conditional = enable_tx_conditional;
self
}

/// Configure the mininum priority fee (tip)
pub const fn with_min_suggested_priority_fee(mut self, min: u64) -> Self {
self.min_suggested_priority_fee = min;
self
}
}

impl<NetworkT> OpAddOnsBuilder<NetworkT> {
Expand All @@ -556,20 +572,29 @@ impl<NetworkT> OpAddOnsBuilder<NetworkT> {
EV: Default,
EB: Default,
{
let Self { sequencer_url, sequencer_headers, da_config, enable_tx_conditional, .. } = self;
let Self {
sequencer_url,
sequencer_headers,
da_config,
enable_tx_conditional,
min_suggested_priority_fee,
..
} = self;

OpAddOns {
rpc_add_ons: RpcAddOns::new(
OpEthApiBuilder::default()
.with_sequencer(sequencer_url.clone())
.with_sequencer_headers(sequencer_headers.clone()),
.with_sequencer_headers(sequencer_headers.clone())
.with_min_suggested_priority_fee(min_suggested_priority_fee),
EV::default(),
EB::default(),
),
da_config: da_config.unwrap_or_default(),
sequencer_url,
sequencer_headers,
enable_tx_conditional,
min_suggested_priority_fee,
}
}
}
Expand Down
51 changes: 45 additions & 6 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,19 @@ pub struct OpEthApi<N: OpNodeCore, NetworkT = Optimism> {

impl<N: OpNodeCore, NetworkT> OpEthApi<N, NetworkT> {
/// Creates a new `OpEthApi`.
pub fn new(eth_api: EthApiNodeBackend<N>, sequencer_client: Option<SequencerClient>) -> Self {
Self { inner: Arc::new(OpEthApiInner { eth_api, sequencer_client }), _nt: PhantomData }
pub fn new(
eth_api: EthApiNodeBackend<N>,
sequencer_client: Option<SequencerClient>,
min_suggested_priority_fee: U256,
) -> Self {
Self {
inner: Arc::new(OpEthApiInner {
eth_api,
sequencer_client,
min_suggested_priority_fee,
}),
_nt: PhantomData,
}
}
}

Expand Down Expand Up @@ -226,6 +237,12 @@ where
fn fee_history_cache(&self) -> &FeeHistoryCache {
self.inner.eth_api.fee_history_cache()
}

async fn suggested_priority_fee(&self) -> Result<U256, Self::Error> {
let base_tip = self.inner.eth_api.gas_oracle().suggest_tip_cap().await?;
let min_tip = U256::from(self.inner.min_suggested_priority_fee);
Ok(base_tip.max(min_tip))
Comment on lines +243 to +244
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice this should do it, for now,

we can still port the entire logic, but this should address low fees already

}
}

impl<N, NetworkT> LoadState for OpEthApi<N, NetworkT>
Expand Down Expand Up @@ -294,6 +311,10 @@ struct OpEthApiInner<N: OpNodeCore> {
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
sequencer_client: Option<SequencerClient>,
/// Minimum priority fee enforced by OP-specific logic.
///
/// See also <https://github.com/ethereum-optimism/op-geth/blob/d4e0fe9bb0c2075a9bff269fb975464dd8498f75/eth/gasprice/optimism-gasprice.go#L38-L38>
min_suggested_priority_fee: U256,
}

impl<N: OpNodeCore> OpEthApiInner<N> {
Expand All @@ -316,20 +337,32 @@ pub struct OpEthApiBuilder<NetworkT = Optimism> {
sequencer_url: Option<String>,
/// Headers to use for the sequencer client requests.
sequencer_headers: Vec<String>,
/// Minimum suggested priority fee (tip)
min_suggested_priority_fee: u64,
/// Marker for network types.
_nt: PhantomData<NetworkT>,
}

impl<NetworkT> Default for OpEthApiBuilder<NetworkT> {
fn default() -> Self {
Self { sequencer_url: None, sequencer_headers: Vec::new(), _nt: PhantomData }
Self {
sequencer_url: None,
sequencer_headers: Vec::new(),
min_suggested_priority_fee: 1_000_000,
_nt: PhantomData,
}
}
}

impl<NetworkT> OpEthApiBuilder<NetworkT> {
/// Creates a [`OpEthApiBuilder`] instance from core components.
pub const fn new() -> Self {
Self { sequencer_url: None, sequencer_headers: Vec::new(), _nt: PhantomData }
Self {
sequencer_url: None,
sequencer_headers: Vec::new(),
min_suggested_priority_fee: 1_000_000,
_nt: PhantomData,
}
}

/// With a [`SequencerClient`].
Expand All @@ -343,6 +376,12 @@ impl<NetworkT> OpEthApiBuilder<NetworkT> {
self.sequencer_headers = sequencer_headers;
self
}

/// With minimum suggested priority fee (tip)
pub const fn with_min_suggested_priority_fee(mut self, min: u64) -> Self {
self.min_suggested_priority_fee = min;
self
}
}

impl<N, NetworkT> EthApiBuilder<N> for OpEthApiBuilder<NetworkT>
Expand All @@ -354,7 +393,7 @@ where
type EthApi = OpEthApi<N, NetworkT>;

async fn build_eth_api(self, ctx: EthApiCtx<'_, N>) -> eyre::Result<Self::EthApi> {
let Self { sequencer_url, sequencer_headers, .. } = self;
let Self { sequencer_url, sequencer_headers, min_suggested_priority_fee, .. } = self;
let eth_api = reth_rpc::EthApiBuilder::new(
ctx.components.provider().clone(),
ctx.components.pool().clone(),
Expand All @@ -381,6 +420,6 @@ where
None
};

Ok(OpEthApi::new(eth_api, sequencer_client))
Ok(OpEthApi::new(eth_api, sequencer_client, U256::from(min_suggested_priority_fee)))
}
}
Loading