Skip to content

Commit ff7b58e

Browse files
committed
Submit single-tx EOAs during the request/response lifecycle instead of the channel-based approach
1 parent d284776 commit ff7b58e

1 file changed

Lines changed: 4 additions & 39 deletions

File tree

services/requester/batch_tx_pool.go

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package requester
33
import (
44
"context"
55
"encoding/hex"
6-
"fmt"
76
"sort"
87
"sync"
98
"time"
@@ -23,13 +22,7 @@ import (
2322

2423
const (
2524
eoaActivityCacheSize = 10_000
26-
// Buffer capacity of the channel used for individual transaction
27-
// submission. Since `BatchTxPool.Add()` is called quite frequently,
28-
// we don't want sending to the channel to block, until there's a
29-
// receive ready. That's why we set a high buffer capacity, to allow
30-
// `BatchTxPool.Add()` to do its job quickly and release any resources
31-
// held, like locks etc.
32-
txChanBufferSize = 1_000
25+
eoaActivityCacheTTL = 10 * time.Second
3326
)
3427

3528
type pooledEvmTx struct {
@@ -53,13 +46,8 @@ type pooledEvmTx struct {
5346
type BatchTxPool struct {
5447
*SingleTxPool
5548
pooledTxs map[gethCommon.Address][]pooledEvmTx
56-
txChan chan cadence.String
5749
txMux sync.Mutex
5850
eoaActivity *expirable.LRU[gethCommon.Address, time.Time]
59-
60-
// Signal channel used to prevent blocking writes
61-
// on `txChan` when the node is shutting down.
62-
done chan struct{}
6351
}
6452

6553
var _ TxPool = &BatchTxPool{}
@@ -88,19 +76,16 @@ func NewBatchTxPool(
8876
eoaActivity := expirable.NewLRU[gethCommon.Address, time.Time](
8977
eoaActivityCacheSize,
9078
nil,
91-
config.TxBatchInterval,
79+
eoaActivityCacheTTL,
9280
)
9381
batchPool := &BatchTxPool{
9482
SingleTxPool: singleTxPool,
9583
pooledTxs: make(map[gethCommon.Address][]pooledEvmTx),
96-
txChan: make(chan cadence.String, txChanBufferSize),
9784
txMux: sync.Mutex{},
9885
eoaActivity: eoaActivity,
99-
done: make(chan struct{}),
10086
}
10187

10288
go batchPool.processPooledTransactions(ctx)
103-
go batchPool.processIndividualTransactions(ctx)
10489

10590
return batchPool
10691
}
@@ -153,11 +138,8 @@ func (t *BatchTxPool) Add(
153138
// [X] is equal to the configured `TxBatchInterval` duration.
154139
lastActivityTime, found := t.eoaActivity.Get(from)
155140
if !found || time.Since(lastActivityTime) > t.config.TxBatchInterval {
156-
select {
157-
case <-t.done:
158-
return fmt.Errorf("the server is shutting down")
159-
default:
160-
t.txChan <- hexEncodedTx
141+
if err := t.submitSingleTransaction(ctx, hexEncodedTx); err != nil {
142+
return err
161143
}
162144
} else {
163145
userTx := pooledEvmTx{txPayload: hexEncodedTx, nonce: tx.Nonce()}
@@ -213,23 +195,6 @@ func (t *BatchTxPool) processPooledTransactions(ctx context.Context) {
213195
}
214196
}
215197

216-
func (t *BatchTxPool) processIndividualTransactions(ctx context.Context) {
217-
for {
218-
select {
219-
case <-ctx.Done():
220-
close(t.done)
221-
return
222-
case hexEncodedTx := <-t.txChan:
223-
if err := t.submitSingleTransaction(ctx, hexEncodedTx); err != nil {
224-
t.logger.Error().Err(err).Msg(
225-
"failed to submit Flow transaction from BatchTxPool for single EOA tx",
226-
)
227-
continue
228-
}
229-
}
230-
}
231-
}
232-
233198
func (t *BatchTxPool) batchSubmitTransactionsForSameAddress(
234199
ctx context.Context,
235200
latestBlock *flow.Block,

0 commit comments

Comments
 (0)