Address more review feedback

Use `errors.Is` instead of `errors.As` since we don't need to access special
fields in the custom error type.

Rather than generating a new error to wrap, just capture the exisitng error.
This commit is contained in:
Pepper Lebeck-Jobe 2025-03-10 12:48:32 +01:00
parent 45dce9d3e1
commit e191e9f66d
No known key found for this signature in database
2 changed files with 3 additions and 4 deletions

View file

@ -88,7 +88,7 @@ type errTxPoolTerminated struct {
// Error returns the message from the wrapped error. // Error returns the message from the wrapped error.
func (t *errTxPoolTerminated) Error() string { func (t *errTxPoolTerminated) Error() string {
return t.error.Error() return fmt.Errorf("failed to sync txpool: %w", t.error).Error()
} }
// SimulatedBeacon drives an Ethereum instance as if it were a real beacon // SimulatedBeacon drives an Ethereum instance as if it were a real beacon
@ -192,7 +192,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
// behavior, the pool will be explicitly blocked on its reset before // behavior, the pool will be explicitly blocked on its reset before
// continuing to the block production below. // continuing to the block production below.
if err := c.eth.APIBackend.TxPool().Sync(); err != nil { if err := c.eth.APIBackend.TxPool().Sync(); err != nil {
return &errTxPoolTerminated{fmt.Errorf("failed to sync txpool: %w", err)} return &errTxPoolTerminated{err}
} }
version := payloadVersion(c.eth.BlockChain().Config(), timestamp) version := payloadVersion(c.eth.BlockChain().Config(), timestamp)

View file

@ -73,8 +73,7 @@ func (a *simulatedBeaconAPI) loop() {
} }
// Avoids spinlooping if the txPool is alredy terminated. // Avoids spinlooping if the txPool is alredy terminated.
if _, err := a.sim.commit(); err != nil { if _, err := a.sim.commit(); err != nil {
var txpTermErr *errTxPoolTerminated if errors.Is(err, &errTxPoolTerminated{}) {
if errors.As(err, &txpTermErr) {
break break
} }
} }