@@ -72,8 +72,19 @@ pub struct OpEthApi<N: OpNodeCore, NetworkT = Optimism> {
7272
7373impl < 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
231248impl < 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
299320impl < 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
323346impl < 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
329357impl < 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
348387impl < 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