Skip to content

Commit

Permalink
pool: race in logging, part2 (#13487)
Browse files Browse the repository at this point in the history
```
==================
WARNING: DATA RACE
Write at 0x00c029988f40 by goroutine 322:
  github.com/erigontech/erigon/txnprovider/txpool.(*bestSlice).UnsafeAdd()
      /home/ubuntu/erigon/txnprovider/txpool/queues.go:50 +0x444
  github.com/erigontech/erigon/txnprovider/txpool.(*PendingPool).Add()
      /home/ubuntu/erigon/txnprovider/txpool/pending_pool.go:97 +0x325
  github.com/erigontech/erigon/txnprovider/txpool.(*TxPool).promote()
      /home/ubuntu/erigon/txnprovider/txpool/pool.go:1819 +0x194d
  github.com/erigontech/erigon/txnprovider/txpool.(*TxPool).addTxns()
      /home/ubuntu/erigon/txnprovider/txpool/pool.go:1327 +0xd84
  github.com/erigontech/erigon/txnprovider/txpool.(*TxPool).processRemoteTxns()
      /home/ubuntu/erigon/txnprovider/txpool/pool.go:511 +0x7c7
  github.com/erigontech/erigon/txnprovider/txpool.(*TxPool).Run()
      /home/ubuntu/erigon/txnprovider/txpool/pool.go:1887 +0x9b2
  github.com/erigontech/erigon/eth.(*Ethereum).Start.func3()
      /home/ubuntu/erigon/eth/backend.go:1594 +0x7a
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /home/ubuntu/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x91

Previous read at 0x00c029988f40 by goroutine 324:
  github.com/erigontech/erigon/txnprovider/txpool.(*TxPool).OnNewBlock()
      /home/ubuntu/erigon/txnprovider/txpool/pool.go:310 +0x3c4
  github.com/erigontech/erigon/txnprovider/txpool.(*Fetch).handleStateChangesRequest()
      /home/ubuntu/erigon/txnprovider/txpool/fetch.go:516 +0x47a
  github.com/erigontech/erigon/txnprovider/txpool.(*Fetch).handleStateChanges()
      /home/ubuntu/erigon/txnprovider/txpool/fetch.go:468 +0x2ad
  github.com/erigontech/erigon/txnprovider/txpool.(*Fetch).ConnectCore.func1()
      /home/ubuntu/erigon/txnprovider/txpool/fetch.go:124 +0xa4
```

also renamed `coreDB` to `chainDB`
  • Loading branch information
AskAlexSharov authored Jan 18, 2025
1 parent 03575f4 commit 4497748
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions txnprovider/txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func New(
ctx context.Context,
newTxns chan Announcements,
poolDB kv.RwDB,
coreDB kv.RoDB,
chainDB kv.RoDB,
cfg txpoolcfg.Config,
cache kvcache.Cache,
chainID uint256.Int,
Expand Down Expand Up @@ -217,7 +217,7 @@ func New(
_stateCache: cache,
senders: newSendersBatch(tracedSenders),
poolDB: poolDB,
_chainDB: coreDB,
_chainDB: chainDB,
cfg: cfg,
chainID: chainID,
unprocessedRemoteTxns: &TxnSlots{},
Expand Down Expand Up @@ -273,7 +273,7 @@ func (p *TxPool) start(ctx context.Context) error {
}

return p.poolDB.View(ctx, func(tx kv.Tx) error {
coreDb, _ := p.coreDBWithCache()
coreDb, _ := p.chainDB()
coreTx, err := coreDb.BeginRo(ctx)
if err != nil {
return err
Expand All @@ -296,7 +296,7 @@ func (p *TxPool) start(ctx context.Context) error {
func (p *TxPool) OnNewBlock(ctx context.Context, stateChanges *remote.StateChangeBatch, unwindTxns, unwindBlobTxns, minedTxns TxnSlots) error {
defer newBlockTimer.ObserveDuration(time.Now())

coreDB, cache := p.coreDBWithCache()
coreDB, cache := p.chainDB()
cache.OnNewBlock(stateChanges)
coreTx, err := coreDB.BeginRo(ctx)
if err != nil {
Expand All @@ -307,7 +307,6 @@ func (p *TxPool) OnNewBlock(ctx context.Context, stateChanges *remote.StateChang

block := stateChanges.ChangeBatch[len(stateChanges.ChangeBatch)-1].BlockHeight
baseFee := stateChanges.PendingBlockBaseFee
available := len(p.pending.best.ms)

if err = minedTxns.Valid(); err != nil {
return err
Expand All @@ -329,6 +328,7 @@ func (p *TxPool) OnNewBlock(ctx context.Context, stateChanges *remote.StateChang
}()

defer func() {
available := len(p.pending.best.ms)
p.logger.Debug("[txpool] New block", "block", block, "unwound", len(unwindTxns.Txns), "mined", len(minedTxns.Txns), "baseFee", baseFee, "pending-pre", available, "pending", p.pending.Len(), "baseFee", p.baseFee.Len(), "queued", p.queued.Len(), "err", err)
}()

Expand Down Expand Up @@ -479,7 +479,7 @@ func (p *TxPool) processRemoteTxns(ctx context.Context) (err error) {
}

defer processBatchTxnsTimer.ObserveDuration(time.Now())
coreDB, cache := p.coreDBWithCache()
coreDB, cache := p.chainDB()
coreTx, err := coreDB.BeginRo(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -1209,7 +1209,7 @@ func fillDiscardReasons(reasons []txpoolcfg.DiscardReason, newTxns TxnSlots, dis
}

func (p *TxPool) AddLocalTxns(ctx context.Context, newTxns TxnSlots) ([]txpoolcfg.DiscardReason, error) {
coreDb, cache := p.coreDBWithCache()
coreDb, cache := p.chainDB()
coreTx, err := coreDb.BeginRo(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1266,7 +1266,7 @@ func (p *TxPool) AddLocalTxns(ctx context.Context, newTxns TxnSlots) ([]txpoolcf
return reasons, nil
}

func (p *TxPool) coreDBWithCache() (kv.RoDB, kvcache.Cache) {
func (p *TxPool) chainDB() (kv.RoDB, kvcache.Cache) {
p.lock.Lock()
defer p.lock.Unlock()
return p._chainDB, p._stateCache
Expand Down

0 comments on commit 4497748

Please sign in to comment.