diff --git a/txpool/pool.go b/txpool/pool.go index 9f00625e2..441ab64ff 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -505,6 +505,7 @@ func (b *ByNonce) replaceOrInsert(mt *metaTx) *metaTx { type TxPool struct { lock *sync.RWMutex + stared atomic.Bool protocolBaseFee atomic.Uint64 currentBaseFee atomic.Uint64 @@ -669,7 +670,7 @@ func (p *TxPool) IsLocal(idHash []byte) bool { return ok } func (p *TxPool) AddNewGoodPeer(peerID PeerID) { p.recentlyConnectedPeers.AddPeer(peerID) } -func (p *TxPool) Started() bool { return p.protocolBaseFee.Load() > 0 } +func (p *TxPool) Started() bool { return p.stared.Load() } // Best - returns top `n` elements of pending queue // id doesn't perform full copy of txs, hovewer underlying elements are immutable @@ -810,11 +811,10 @@ func (p *TxPool) AddLocals(ctx context.Context, newTxs TxSlots, tx kv.Tx) ([]Dis return nil, err } - protocolBaseFee, currentBaseFee := p.protocolBaseFee.Load(), p.currentBaseFee.Load() - if protocolBaseFee == 0 || currentBaseFee == 0 { - return nil, fmt.Errorf("non-zero base fee: %d,%d", protocolBaseFee, currentBaseFee) + if !p.Started() { + return nil, fmt.Errorf("pool not started yet") } - if err := onNewTxs(tx, p.senders, newTxs, protocolBaseFee, currentBaseFee, p.pending, p.baseFee, p.queued, p.byNonce, p.byHash, p.discardLocked); err != nil { + if err := onNewTxs(tx, p.senders, newTxs, p.protocolBaseFee.Load(), p.currentBaseFee.Load(), p.pending, p.baseFee, p.queued, p.byNonce, p.byHash, p.discardLocked); err != nil { return nil, err } @@ -867,11 +867,11 @@ func (p *TxPool) processRemoteTxs(ctx context.Context, tx kv.Tx) error { return err } - protocolBaseFee, currentBaseFee := p.protocolBaseFee.Load(), p.currentBaseFee.Load() - if protocolBaseFee == 0 || currentBaseFee == 0 { - return fmt.Errorf("non-zero base fee: %d,%d", protocolBaseFee, currentBaseFee) + if !p.stared.Load() { + return fmt.Errorf("txpool not started yet") } - if err := onNewTxs(tx, p.senders, newTxs, protocolBaseFee, currentBaseFee, p.pending, p.baseFee, p.queued, p.byNonce, p.byHash, p.discardLocked); err != nil { + + if err := onNewTxs(tx, p.senders, newTxs, p.protocolBaseFee.Load(), p.currentBaseFee.Load(), p.pending, p.baseFee, p.queued, p.byNonce, p.byHash, p.discardLocked); err != nil { return err } @@ -930,6 +930,7 @@ func (p *TxPool) setBaseFee(baseFee uint64) (uint64, uint64) { p.protocolBaseFee.Store(calcProtocolBaseFee(baseFee)) p.currentBaseFee.Store(baseFee) } + p.stared.Store(true) return p.protocolBaseFee.Load(), p.currentBaseFee.Load() }