@@ -793,19 +793,38 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
793793 var waitBaseFeeToDrop atomic.Bool
794794 waitBaseFeeToDrop .Store (false )
795795 if mustCheckMaxBaseFee {
796+ log .Info ().
797+ Msg ("max base fee monitoring enabled" )
796798 go func (ctx context.Context , c * ethclient.Client ) {
797799 for {
798- gasPrice , _ := getSuggestedGasPrices (ctx , c )
799- if gasPrice .Uint64 () > * ltp .MaxBaseFeeGwei {
800- waitBaseFeeToDrop .Store (true )
801- log .Warn ().
802- Uint64 ("currentBaseFeeGwei" , gasPrice .Uint64 ()).
803- Uint64 ("maxBaseFeeGwei" , * ltp .MaxBaseFeeGwei ).
804- Msg ("Current base fee exceeds configured max base fee, waiting base fee to drop to continue" )
800+ header , err := c .HeaderByNumber (ctx , nil )
801+ if err != nil {
802+ log .Error ().Err (err ).Msg ("Unable to get latest block header for base fee check" )
803+ continue
804+ }
805+
806+ if header .BaseFee != nil {
807+ baseFeeGwei := new (big.Int ).Div (header .BaseFee , big .NewInt (1e9 )) // Convert wei to gwei
808+ if baseFeeGwei .Uint64 () > * ltp .MaxBaseFeeGwei {
809+ waitBaseFeeToDrop .Store (true )
810+ log .Warn ().
811+ Msgf ("PAUSE: base fee %d Gwei > limit %d Gwei" , baseFeeGwei .Uint64 (), * ltp .MaxBaseFeeGwei )
812+ } else {
813+ if waitBaseFeeToDrop .Load () {
814+ waitBaseFeeToDrop .Store (false )
815+ log .Info ().
816+ Msgf ("RESUME: base fee %d Gwei ≤ limit %d Gwei" , baseFeeGwei .Uint64 (), * ltp .MaxBaseFeeGwei )
817+ }
818+ }
805819 } else {
806820 waitBaseFeeToDrop .Store (false )
807821 }
808- time .Sleep (500 * time .Millisecond )
822+ select {
823+ case <- ctx .Done ():
824+ return
825+ default :
826+ time .Sleep (time .Second )
827+ }
809828 }
810829 }(maxBaseFeeCtx , c )
811830 }
0 commit comments