mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Fix deadlock in SimulatedBeacon.loop
This commit is contained in:
parent
7aafad2233
commit
d320d83232
1 changed files with 17 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ package catalyst
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -32,6 +33,7 @@ type api struct {
|
||||||
|
|
||||||
func (a *api) loop() {
|
func (a *api) loop() {
|
||||||
var (
|
var (
|
||||||
|
committing atomic.Bool
|
||||||
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)
|
||||||
)
|
)
|
||||||
|
|
@ -42,12 +44,24 @@ 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:
|
||||||
|
// FIXME: `sealBlock` will block the loop and `newTxs` won't be
|
||||||
|
// read. If new TX will be submitted to the pool while we're
|
||||||
|
// sealing the block, deadlock will occur.
|
||||||
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() {
|
||||||
|
if committing.Swap(true) {
|
||||||
|
return
|
||||||
|
}
|
||||||
a.sim.Commit()
|
a.sim.Commit()
|
||||||
|
// FIXME: This is race-y, if `newTxs` arrive after we
|
||||||
|
// `Commit`ted but before we unset `committing`, `newTxs` will
|
||||||
|
// be skipped. Needs redesign.
|
||||||
|
committing.Store(false)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue