@@ -115,14 +115,12 @@ func fixNonceGap(cmd *cobra.Command, args []string) error {
115115 var maxNonce uint64
116116 if inputFixNonceGapArgs .maxNonce != 0 {
117117 maxNonce = inputFixNonceGapArgs .maxNonce
118+ log .Info ().Uint64 ("maxNonce" , maxNonce ).Msg ("maxNonce loaded from --max-nonce flag" )
118119 } else {
119- maxNonce , err = getMaxNonceFromTxPool (addr )
120+ log .Info ().Msg ("--max-nonce flag not set" )
121+ maxNonce , err = getMaxNonce (addr )
120122 if err != nil {
121- if strings .Contains (err .Error (), "the method txpool_content does not exist/is not available" ) {
122- log .Error ().Err (err ).Msg ("The RPC doesn't provide access to txpool_content, please check --help for more information about --max-nonce" )
123- return nil
124- }
125- log .Error ().Err (err ).Msg ("Unable to get max nonce from txpool" )
123+ log .Error ().Err (err ).Msg ("Unable to get max nonce, please check --help for more information about --max-nonce" )
126124 return err
127125 }
128126 }
@@ -132,7 +130,11 @@ func fixNonceGap(cmd *cobra.Command, args []string) error {
132130 log .Info ().Stringer ("addr" , addr ).Msg ("There is no nonce gap." )
133131 return nil
134132 }
135- log .Info ().Stringer ("addr" , addr ).Msgf ("Nonce gap found. Max nonce: %d" , maxNonce )
133+ log .Info ().
134+ Stringer ("addr" , addr ).
135+ Uint64 ("currentNonce" , currentNonce ).
136+ Uint64 ("maxNonce" , maxNonce ).
137+ Msg ("Nonce gap found" )
136138
137139 gasPrice , err := rpcClient .SuggestGasPrice (cmd .Context ())
138140 if err != nil {
@@ -273,6 +275,26 @@ func WaitMineTransaction(ctx context.Context, client *ethclient.Client, tx *type
273275 }
274276}
275277
278+ func getMaxNonce (addr common.Address ) (uint64 , error ) {
279+ log .Info ().Msg ("getting max nonce from txpool_content" )
280+ maxNonce , err := getMaxNonceFromTxPool (addr )
281+ if err == nil {
282+ log .Info ().Uint64 ("maxNonce" , maxNonce ).Msg ("maxNonce loaded from txpool_content" )
283+ return maxNonce , nil
284+ }
285+ log .Warn ().Err (err ).Msg ("unable to get max nonce from txpool_content" )
286+
287+ log .Info ().Msg ("getting max nonce from pending nonce" )
288+ // if the error is not about txpool_content, falls back to PendingNonceAt
289+ maxNonce , err = rpcClient .PendingNonceAt (context .Background (), addr )
290+ if err != nil {
291+ return 0 , err
292+ }
293+
294+ log .Info ().Uint64 ("maxNonce" , maxNonce ).Msg ("maxNonce loaded from pending nonce" )
295+ return maxNonce , nil
296+ }
297+
276298func getMaxNonceFromTxPool (addr common.Address ) (uint64 , error ) {
277299 var result PoolContent
278300 err := rpcClient .Client ().Call (& result , "txpool_content" )
@@ -299,6 +321,7 @@ func getMaxNonceFromTxPool(addr common.Address) (uint64, error) {
299321 nonceInt , ok := new (big.Int ).SetString (nonce , 10 )
300322 if ! ok {
301323 err = fmt .Errorf ("invalid nonce found: %s" , nonce )
324+ log .Warn ().Err (err ).Msg ("unable to get txpool_content" )
302325 return 0 , err
303326 }
304327
0 commit comments