Skip to content

Commit 9917917

Browse files
committed
Merge branch 'mpeter/submitted-tx-validations' into mpeter/backport-submitted-tx-validations
2 parents fd15c95 + cc3bad3 commit 9917917

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

services/requester/batch_tx_pool.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,7 @@ func (t *BatchTxPool) Add(
191191
return err
192192
}
193193

194-
t.txMux.Lock()
195-
defer t.txMux.Unlock()
196-
197-
// Update metadata for the last EOA activity only on successful add/submit.
198-
eoaActivity, _ = t.eoaActivityCache.Get(from)
199-
eoaActivity.lastSubmission = time.Now()
200-
eoaActivity.txNonces = append(eoaActivity.txNonces, nonce)
201-
// To avoid the slice of nonces from growing indefinitely,
202-
// keep only the last `maxTrackedTxNoncesPerEOA` nonces.
203-
if len(eoaActivity.txNonces) > maxTrackedTxNoncesPerEOA {
204-
firstKeep := len(eoaActivity.txNonces) - maxTrackedTxNoncesPerEOA
205-
eoaActivity.txNonces = eoaActivity.txNonces[firstKeep:]
206-
}
207-
208-
t.eoaActivityCache.Add(from, eoaActivity)
194+
t.updateEOAActivityMetadata(from, nonce)
209195

210196
return nil
211197
}
@@ -238,7 +224,11 @@ func (t *BatchTxPool) processPooledTransactions(ctx context.Context) {
238224
"failed to submit batch Flow transaction for EOA: %s",
239225
address.Hex(),
240226
)
241-
continue
227+
// In case of any error, add the transactions back to the pool,
228+
// as a retry mechanism.
229+
t.txMux.Lock()
230+
t.pooledTxs[address] = append(t.pooledTxs[address], pooledTxs...)
231+
t.txMux.Unlock()
242232
}
243233
}
244234
}
@@ -324,3 +314,24 @@ func (t *BatchTxPool) submitSingleTransaction(
324314

325315
return nil
326316
}
317+
318+
func (t *BatchTxPool) updateEOAActivityMetadata(
319+
from gethCommon.Address,
320+
nonce uint64,
321+
) {
322+
t.txMux.Lock()
323+
defer t.txMux.Unlock()
324+
325+
// Update metadata for the last EOA activity only on successful add/submit.
326+
eoaActivity, _ := t.eoaActivityCache.Get(from)
327+
eoaActivity.lastSubmission = time.Now()
328+
eoaActivity.txNonces = append(eoaActivity.txNonces, nonce)
329+
// To avoid the slice of nonces from growing indefinitely,
330+
// keep only the last `maxTrackedTxNoncesPerEOA` nonces.
331+
if len(eoaActivity.txNonces) > maxTrackedTxNoncesPerEOA {
332+
firstKeep := len(eoaActivity.txNonces) - maxTrackedTxNoncesPerEOA
333+
eoaActivity.txNonces = eoaActivity.txNonces[firstKeep:]
334+
}
335+
336+
t.eoaActivityCache.Add(from, eoaActivity)
337+
}

0 commit comments

Comments
 (0)