mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
eth/catalyst: fix deadlock by committing blocks in separate go-routines
This commit is contained in:
parent
1f14c9e237
commit
d4acec3310
1 changed files with 19 additions and 7 deletions
|
|
@ -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()
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue