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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -34,6 +35,7 @@ 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:
|
||||||
|
go func() {
|
||||||
|
commitMu.Lock()
|
||||||
|
defer commitMu.Unlock()
|
||||||
|
|
||||||
withdrawals := append(a.sim.withdrawals.gatherPending(9), w)
|
withdrawals := append(a.sim.withdrawals.gatherPending(9), w)
|
||||||
if err := a.sim.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
|
if err := a.sim.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
|
||||||
log.Warn("Error performing sealing work", "err", err)
|
log.Warn("Error performing sealing work", "err", err)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
case <-newTxs:
|
case <-newTxs:
|
||||||
|
go func() {
|
||||||
|
commitMu.Lock()
|
||||||
|
defer commitMu.Unlock()
|
||||||
|
|
||||||
a.sim.Commit()
|
a.sim.Commit()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue