mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
Introduce fallibleCommit which can error
This allows the inner loop in the case of "on-demand" commits to bail out if the txPool has been terminated before the doCommit channel is closed. This has been tested with a known-flaky test which, before this commit was spinlooping and logging unfathomable reams of warning messages. Now, when the race occurs, only a single instance of the warning is logged.
This commit is contained in:
parent
8d2920bbc4
commit
7fab62da4d
2 changed files with 16 additions and 5 deletions
|
|
@ -302,11 +302,18 @@ func (c *SimulatedBeacon) setCurrentState(headHash, finalizedHash common.Hash) {
|
|||
|
||||
// Commit seals a block on demand.
|
||||
func (c *SimulatedBeacon) Commit() common.Hash {
|
||||
hash, _ := c.fallibleCommit()
|
||||
return hash
|
||||
}
|
||||
|
||||
// fallibleCommit attempts to seal a block on demand, but may return an error.
|
||||
func (c *SimulatedBeacon) fallibleCommit() (common.Hash, error) {
|
||||
withdrawals := c.withdrawals.pop(10)
|
||||
if err := c.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
|
||||
log.Warn("Error performing sealing work", "err", err)
|
||||
return common.Hash{}, err
|
||||
}
|
||||
return c.eth.BlockChain().CurrentBlock().Hash()
|
||||
return c.eth.BlockChain().CurrentBlock().Hash(), nil
|
||||
}
|
||||
|
||||
// Rollback un-sends previously added transactions.
|
||||
|
|
|
|||
|
|
@ -70,11 +70,15 @@ func (a *simulatedBeaconAPI) loop() {
|
|||
if executable, _ := a.sim.eth.TxPool().Stats(); executable == 0 {
|
||||
break
|
||||
}
|
||||
a.sim.Commit()
|
||||
// Avoid a race condition where tx pool is terminated during Commit.
|
||||
if err := a.sim.eth.TxPool().Sync(); err != nil {
|
||||
break
|
||||
// Avoid a race condition where doCommit is closed while in this loop.
|
||||
select {
|
||||
case _, ok := <-doCommit:
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
default:
|
||||
}
|
||||
a.sim.Commit()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
Loading…
Reference in a new issue