eth/catalyst: fix deadlock by committing blocks in separate go-routines

This commit is contained in:
Jared Wasinger 2024-04-25 17:44:30 -07:00
parent 1f14c9e237
commit d4acec3310

View file

@ -18,6 +18,7 @@ package catalyst
import ( import (
"context" "context"
"sync"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -32,8 +33,9 @@ type api struct {
func (a *api) loop() { func (a *api) loop() {
var ( var (
newTxs = make(chan core.NewTxsEvent) newTxs = make(chan core.NewTxsEvent)
sub = a.sim.eth.TxPool().SubscribeTransactions(newTxs, true) sub = a.sim.eth.TxPool().SubscribeTransactions(newTxs, true)
commitMu = sync.Mutex{}
) )
defer sub.Unsubscribe() defer sub.Unsubscribe()
@ -42,12 +44,22 @@ func (a *api) loop() {
case <-a.sim.shutdownCh: case <-a.sim.shutdownCh:
return return
case w := <-a.sim.withdrawals.pending: case w := <-a.sim.withdrawals.pending:
withdrawals := append(a.sim.withdrawals.gatherPending(9), w) go func() {
if err := a.sim.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil { commitMu.Lock()
log.Warn("Error performing sealing work", "err", err) defer commitMu.Unlock()
}
withdrawals := append(a.sim.withdrawals.gatherPending(9), w)
if err := a.sim.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
log.Warn("Error performing sealing work", "err", err)
}
}()
case <-newTxs: case <-newTxs:
a.sim.Commit() go func() {
commitMu.Lock()
defer commitMu.Unlock()
a.sim.Commit()
}()
} }
} }
} }