mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-16 17:03:46 +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.
|
// Commit seals a block on demand.
|
||||||
func (c *SimulatedBeacon) Commit() common.Hash {
|
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)
|
withdrawals := c.withdrawals.pop(10)
|
||||||
if err := c.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
|
if err := c.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
|
||||||
log.Warn("Error performing sealing work", "err", err)
|
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.
|
// Rollback un-sends previously added transactions.
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,15 @@ func (a *simulatedBeaconAPI) loop() {
|
||||||
if executable, _ := a.sim.eth.TxPool().Stats(); executable == 0 {
|
if executable, _ := a.sim.eth.TxPool().Stats(); executable == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
a.sim.Commit()
|
// Avoid a race condition where doCommit is closed while in this loop.
|
||||||
// Avoid a race condition where tx pool is terminated during Commit.
|
select {
|
||||||
if err := a.sim.eth.TxPool().Sync(); err != nil {
|
case _, ok := <-doCommit:
|
||||||
break
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
|
a.sim.Commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue