@@ -3,7 +3,6 @@ package requester
33import (
44 "context"
55 "encoding/hex"
6- "fmt"
76 "slices"
87 "sort"
98 "sync"
@@ -19,13 +18,12 @@ import (
1918 "github.com/onflow/flow-evm-gateway/config"
2019 "github.com/onflow/flow-evm-gateway/metrics"
2120 "github.com/onflow/flow-evm-gateway/models"
22- errs "github.com/onflow/flow-evm-gateway/models/errors"
2321 "github.com/onflow/flow-evm-gateway/services/requester/keystore"
2422)
2523
2624const (
2725 eoaActivityCacheSize = 10_000
28- maxTrackedTxNoncesPerEOA = 15
26+ maxTrackedTxNoncesPerEOA = 30
2927)
3028
3129type pooledEvmTx struct {
@@ -129,14 +127,15 @@ func (t *BatchTxPool) Add(
129127 eoaActivity , found := t .eoaActivityCache .Get (from )
130128 nonce := tx .Nonce ()
131129
132- // Reject transactions that have already been submitted,
130+ // Skip transactions that have been already submitted,
133131 // as they are *likely* to fail.
134132 if found && slices .Contains (eoaActivity .txNonces , nonce ) {
135- return fmt .Errorf (
136- "%w: a tx with nonce %d has already been submitted" ,
137- errs .ErrInvalid ,
138- nonce ,
139- )
133+ t .logger .Info ().
134+ Str ("evm_tx" , tx .Hash ().Hex ()).
135+ Str ("from" , from .Hex ()).
136+ Uint64 ("nonce" , nonce ).
137+ Msg ("tx with same nonce has been already submitted" )
138+ return nil
140139 }
141140
142141 // Scenarios
@@ -185,16 +184,25 @@ func (t *BatchTxPool) Add(
185184 }
186185
187186 if err != nil {
187+ t .logger .Error ().Err (err ).Msgf (
188+ "failed to submit single Flow transaction for EOA: %s" ,
189+ from .Hex (),
190+ )
188191 return err
189192 }
190193
194+ t .txMux .Lock ()
195+ defer t .txMux .Unlock ()
196+
191197 // Update metadata for the last EOA activity only on successful add/submit.
198+ eoaActivity , _ = t .eoaActivityCache .Get (from )
192199 eoaActivity .lastSubmission = time .Now ()
193200 eoaActivity .txNonces = append (eoaActivity .txNonces , nonce )
194201 // To avoid the slice of nonces from growing indefinitely,
195- // maintain only a handful of the last tx nonces.
202+ // keep only the last `maxTrackedTxNoncesPerEOA` nonces.
196203 if len (eoaActivity .txNonces ) > maxTrackedTxNoncesPerEOA {
197- eoaActivity .txNonces = eoaActivity .txNonces [1 :]
204+ firstKeep := len (eoaActivity .txNonces ) - maxTrackedTxNoncesPerEOA
205+ eoaActivity .txNonces = eoaActivity .txNonces [firstKeep :]
198206 }
199207
200208 t .eoaActivityCache .Add (from , eoaActivity )
@@ -227,7 +235,7 @@ func (t *BatchTxPool) processPooledTransactions(ctx context.Context) {
227235 )
228236 if err != nil {
229237 t .logger .Error ().Err (err ).Msgf (
230- "failed to submit Flow transaction from BatchTxPool for EOA: %s" ,
238+ "failed to submit batch Flow transaction for EOA: %s" ,
231239 address .Hex (),
232240 )
233241 continue
@@ -274,6 +282,9 @@ func (t *BatchTxPool) batchSubmitTransactionsForSameAddress(
274282 }
275283
276284 if err := t .client .SendTransaction (ctx , * flowTx ); err != nil {
285+ // If there was any error while sending the transaction,
286+ // we record all transactions as dropped.
287+ t .collector .TransactionsDropped (len (hexEncodedTxs ))
277288 return err
278289 }
279290
@@ -305,6 +316,9 @@ func (t *BatchTxPool) submitSingleTransaction(
305316 }
306317
307318 if err := t .client .SendTransaction (ctx , * flowTx ); err != nil {
319+ // If there was any error while sending the transaction,
320+ // we record it as a dropped transaction.
321+ t .collector .TransactionsDropped (1 )
308322 return err
309323 }
310324
0 commit comments