diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index 286757054e..df8963b1ed 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -80,6 +80,17 @@ func (w *withdrawalQueue) subscribe(ch chan<- newWithdrawalsEvent) event.Subscri return w.subs.Track(sub) } +// txPoolTerminatedError is returned when the txpool is already terminated when +// trying to seal a block. +type txPoolTerminatedError struct { + error +} + +// Error returns the message from the wrapped error. +func (t *txPoolTerminatedError) Error() string { + return t.error.Error() +} + // SimulatedBeacon drives an Ethereum instance as if it were a real beacon // client. It can run in period mode where it mines a new block every period // (seconds) or on every transaction via Commit, Fork and AdjustTime. @@ -181,7 +192,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u // behavior, the pool will be explicitly blocked on its reset before // continuing to the block production below. if err := c.eth.APIBackend.TxPool().Sync(); err != nil { - return fmt.Errorf("failed to sync txpool: %w", err) + return &txPoolTerminatedError{fmt.Errorf("failed to sync txpool: %w", err)} } version := payloadVersion(c.eth.BlockChain().Config(), timestamp) @@ -302,12 +313,12 @@ func (c *SimulatedBeacon) setCurrentState(headHash, finalizedHash common.Hash) { // Commit seals a block on demand. func (c *SimulatedBeacon) Commit() common.Hash { - hash, _ := c.fallibleCommit() + hash, _ := c.commit() return hash } // fallibleCommit attempts to seal a block on demand, but may return an error. -func (c *SimulatedBeacon) fallibleCommit() (common.Hash, error) { +func (c *SimulatedBeacon) commit() (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) diff --git a/eth/catalyst/simulated_beacon_api.go b/eth/catalyst/simulated_beacon_api.go index 9e5888dfa7..ea490e6df5 100644 --- a/eth/catalyst/simulated_beacon_api.go +++ b/eth/catalyst/simulated_beacon_api.go @@ -18,6 +18,7 @@ package catalyst import ( "context" + "errors" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -71,8 +72,11 @@ func (a *simulatedBeaconAPI) loop() { break } // Avoids spinlooping if the txPool is alredy terminated. - if _, err := a.sim.fallibleCommit(); err != nil { - break + if _, err := a.sim.commit(); err != nil { + var txpTermErr *txPoolTerminatedError + if errors.As(err, &txpTermErr) { + break + } } } }