diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index c71add93bc..286757054e 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -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. diff --git a/eth/catalyst/simulated_beacon_api.go b/eth/catalyst/simulated_beacon_api.go index 515908f86c..5955b033bd 100644 --- a/eth/catalyst/simulated_beacon_api.go +++ b/eth/catalyst/simulated_beacon_api.go @@ -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() } } }()