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 (
"context"
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
@ -32,8 +33,9 @@ type api struct {
func (a *api) loop() {
var (
newTxs = make(chan core.NewTxsEvent)
sub = a.sim.eth.TxPool().SubscribeTransactions(newTxs, true)
newTxs = make(chan core.NewTxsEvent)
sub = a.sim.eth.TxPool().SubscribeTransactions(newTxs, true)
commitMu = sync.Mutex{}
)
defer sub.Unsubscribe()
@ -42,12 +44,22 @@ func (a *api) loop() {
case <-a.sim.shutdownCh:
return
case w := <-a.sim.withdrawals.pending:
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)
}
go func() {
commitMu.Lock()
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:
a.sim.Commit()
go func() {
commitMu.Lock()
defer commitMu.Unlock()
a.sim.Commit()
}()
}
}
}