Skip to content

Commit b6e66a5

Browse files
shane-mooremattssegraphite-app[bot]
authored
chore: add minSuggestedPriorityFee check to OpEthapi (#16637)
Co-authored-by: Matthias Seitz <[email protected]> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent 40ebef4 commit b6e66a5

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

crates/optimism/node/src/args.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub struct RollupArgs {
5959
/// Optional headers to use when connecting to the sequencer.
6060
#[arg(long = "rollup.sequencer-headers", requires = "sequencer")]
6161
pub sequencer_headers: Vec<String>,
62+
63+
/// Minimum suggested priority fee (tip) in wei, default `1_000_000`
64+
#[arg(long, default_value_t = 1_000_000)]
65+
pub min_suggested_priority_fee: u64,
6266
}
6367

6468
impl Default for RollupArgs {
@@ -73,6 +77,7 @@ impl Default for RollupArgs {
7377
supervisor_http: DEFAULT_SUPERVISOR_URL.to_string(),
7478
supervisor_safety_level: SafetyLevel::CrossUnsafe,
7579
sequencer_headers: Vec::new(),
80+
min_suggested_priority_fee: 1_000_000,
7681
}
7782
}
7883
}

crates/optimism/node/src/node.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ where
216216
.with_sequencer_headers(self.args.sequencer_headers.clone())
217217
.with_da_config(self.da_config.clone())
218218
.with_enable_tx_conditional(self.args.enable_tx_conditional)
219+
.with_min_suggested_priority_fee(self.args.min_suggested_priority_fee)
219220
.build()
220221
}
221222
}
@@ -254,6 +255,7 @@ pub struct OpAddOns<N: FullNodeComponents, EthB: EthApiBuilder<N>, EV, EB> {
254255
pub sequencer_headers: Vec<String>,
255256
/// Enable transaction conditionals.
256257
enable_tx_conditional: bool,
258+
min_suggested_priority_fee: u64,
257259
}
258260

259261
impl<N, NetworkT> Default
@@ -302,13 +304,15 @@ where
302304
sequencer_url,
303305
sequencer_headers,
304306
enable_tx_conditional,
307+
min_suggested_priority_fee,
305308
} = self;
306309
OpAddOns {
307310
rpc_add_ons: rpc_add_ons.with_engine_api(engine_api_builder),
308311
da_config,
309312
sequencer_url,
310313
sequencer_headers,
311314
enable_tx_conditional,
315+
min_suggested_priority_fee,
312316
}
313317
}
314318

@@ -320,13 +324,15 @@ where
320324
sequencer_url,
321325
sequencer_headers,
322326
enable_tx_conditional,
327+
min_suggested_priority_fee,
323328
} = self;
324329
OpAddOns {
325330
rpc_add_ons: rpc_add_ons.with_engine_validator(engine_validator_builder),
326331
da_config,
327332
sequencer_url,
328333
sequencer_headers,
329334
enable_tx_conditional,
335+
min_suggested_priority_fee,
330336
}
331337
}
332338

@@ -382,6 +388,7 @@ where
382388
sequencer_url,
383389
sequencer_headers,
384390
enable_tx_conditional,
391+
..
385392
} = self;
386393

387394
let builder = reth_optimism_payload_builder::OpPayloadBuilder::new(
@@ -507,6 +514,8 @@ pub struct OpAddOnsBuilder<NetworkT> {
507514
enable_tx_conditional: bool,
508515
/// Marker for network types.
509516
_nt: PhantomData<NetworkT>,
517+
/// Minimum suggested priority fee (tip)
518+
min_suggested_priority_fee: u64,
510519
}
511520

512521
impl<NetworkT> Default for OpAddOnsBuilder<NetworkT> {
@@ -516,6 +525,7 @@ impl<NetworkT> Default for OpAddOnsBuilder<NetworkT> {
516525
sequencer_headers: Vec::new(),
517526
da_config: None,
518527
enable_tx_conditional: false,
528+
min_suggested_priority_fee: 1_000_000,
519529
_nt: PhantomData,
520530
}
521531
}
@@ -545,6 +555,12 @@ impl<NetworkT> OpAddOnsBuilder<NetworkT> {
545555
self.enable_tx_conditional = enable_tx_conditional;
546556
self
547557
}
558+
559+
/// Configure the minimum priority fee (tip)
560+
pub const fn with_min_suggested_priority_fee(mut self, min: u64) -> Self {
561+
self.min_suggested_priority_fee = min;
562+
self
563+
}
548564
}
549565

550566
impl<NetworkT> OpAddOnsBuilder<NetworkT> {
@@ -556,20 +572,29 @@ impl<NetworkT> OpAddOnsBuilder<NetworkT> {
556572
EV: Default,
557573
EB: Default,
558574
{
559-
let Self { sequencer_url, sequencer_headers, da_config, enable_tx_conditional, .. } = self;
575+
let Self {
576+
sequencer_url,
577+
sequencer_headers,
578+
da_config,
579+
enable_tx_conditional,
580+
min_suggested_priority_fee,
581+
..
582+
} = self;
560583

561584
OpAddOns {
562585
rpc_add_ons: RpcAddOns::new(
563586
OpEthApiBuilder::default()
564587
.with_sequencer(sequencer_url.clone())
565-
.with_sequencer_headers(sequencer_headers.clone()),
588+
.with_sequencer_headers(sequencer_headers.clone())
589+
.with_min_suggested_priority_fee(min_suggested_priority_fee),
566590
EV::default(),
567591
EB::default(),
568592
),
569593
da_config: da_config.unwrap_or_default(),
570594
sequencer_url,
571595
sequencer_headers,
572596
enable_tx_conditional,
597+
min_suggested_priority_fee,
573598
}
574599
}
575600
}

crates/optimism/rpc/src/eth/mod.rs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,19 @@ pub struct OpEthApi<N: OpNodeCore, NetworkT = Optimism> {
7272

7373
impl<N: OpNodeCore, NetworkT> OpEthApi<N, NetworkT> {
7474
/// Creates a new `OpEthApi`.
75-
pub fn new(eth_api: EthApiNodeBackend<N>, sequencer_client: Option<SequencerClient>) -> Self {
76-
Self { inner: Arc::new(OpEthApiInner { eth_api, sequencer_client }), _nt: PhantomData }
75+
pub fn new(
76+
eth_api: EthApiNodeBackend<N>,
77+
sequencer_client: Option<SequencerClient>,
78+
min_suggested_priority_fee: U256,
79+
) -> Self {
80+
Self {
81+
inner: Arc::new(OpEthApiInner {
82+
eth_api,
83+
sequencer_client,
84+
min_suggested_priority_fee,
85+
}),
86+
_nt: PhantomData,
87+
}
7788
}
7889
}
7990

@@ -226,6 +237,12 @@ where
226237
fn fee_history_cache(&self) -> &FeeHistoryCache {
227238
self.inner.eth_api.fee_history_cache()
228239
}
240+
241+
async fn suggested_priority_fee(&self) -> Result<U256, Self::Error> {
242+
let base_tip = self.inner.eth_api.gas_oracle().suggest_tip_cap().await?;
243+
let min_tip = U256::from(self.inner.min_suggested_priority_fee);
244+
Ok(base_tip.max(min_tip))
245+
}
229246
}
230247

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

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

323346
impl<NetworkT> Default for OpEthApiBuilder<NetworkT> {
324347
fn default() -> Self {
325-
Self { sequencer_url: None, sequencer_headers: Vec::new(), _nt: PhantomData }
348+
Self {
349+
sequencer_url: None,
350+
sequencer_headers: Vec::new(),
351+
min_suggested_priority_fee: 1_000_000,
352+
_nt: PhantomData,
353+
}
326354
}
327355
}
328356

329357
impl<NetworkT> OpEthApiBuilder<NetworkT> {
330358
/// Creates a [`OpEthApiBuilder`] instance from core components.
331359
pub const fn new() -> Self {
332-
Self { sequencer_url: None, sequencer_headers: Vec::new(), _nt: PhantomData }
360+
Self {
361+
sequencer_url: None,
362+
sequencer_headers: Vec::new(),
363+
min_suggested_priority_fee: 1_000_000,
364+
_nt: PhantomData,
365+
}
333366
}
334367

335368
/// With a [`SequencerClient`].
@@ -343,6 +376,12 @@ impl<NetworkT> OpEthApiBuilder<NetworkT> {
343376
self.sequencer_headers = sequencer_headers;
344377
self
345378
}
379+
380+
/// With minimum suggested priority fee (tip)
381+
pub const fn with_min_suggested_priority_fee(mut self, min: u64) -> Self {
382+
self.min_suggested_priority_fee = min;
383+
self
384+
}
346385
}
347386

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

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

384-
Ok(OpEthApi::new(eth_api, sequencer_client))
423+
Ok(OpEthApi::new(eth_api, sequencer_client, U256::from(min_suggested_priority_fee)))
385424
}
386425
}

0 commit comments

Comments
 (0)