Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pool: race in logging, part2 #13487

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading