diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 01d27482da..dd35e9d28b 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -299,10 +299,10 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit) } if chain.Config().IsShanghai(header.Number, header.Time) { - return fmt.Errorf("clique does not support shanghai fork") + return errors.New("clique does not support shanghai fork") } if chain.Config().IsCancun(header.Number, header.Time) { - return fmt.Errorf("clique does not support cancun fork") + return errors.New("clique does not support cancun fork") } // All basic checks passed, verify cascading fields return c.verifyCascadingFields(chain, header, parents) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index b36637c5b9..acbbdacc3c 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -263,10 +263,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa return consensus.ErrInvalidNumber } if chain.Config().IsShanghai(header.Number, header.Time) { - return fmt.Errorf("ethash does not support shanghai fork") + return errors.New("ethash does not support shanghai fork") } if chain.Config().IsCancun(header.Number, header.Time) { - return fmt.Errorf("ethash does not support cancun fork") + return errors.New("ethash does not support cancun fork") } // Add some fake checks for tests if ethash.fakeDelay != nil { diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index 4521b47b36..fbaf9eec76 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -17,6 +17,7 @@ package misc import ( + "errors" "fmt" "math/big" @@ -40,7 +41,7 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade } // Verify the header is not malformed if header.BaseFee == nil { - return fmt.Errorf("header is missing baseFee") + return errors.New("header is missing baseFee") } // Verify the baseFee is correct based on the parent header. expectedBaseFee := CalcBaseFee(config, parent) diff --git a/eth/api.go b/eth/api.go index 5fdd0117dd..00ad48fbfc 100644 --- a/eth/api.go +++ b/eth/api.go @@ -554,7 +554,7 @@ func (api *DebugAPI) GetAccessibleState(from, to rpc.BlockNumber) (uint64, error if num.Int64() < 0 { block := api.eth.blockchain.CurrentBlock() if block == nil { - return 0, fmt.Errorf("current block missing") + return 0, errors.New("current block missing") } return block.Number.Uint64(), nil } @@ -574,7 +574,7 @@ func (api *DebugAPI) GetAccessibleState(from, to rpc.BlockNumber) (uint64, error return 0, err } if start == end { - return 0, fmt.Errorf("from and to needs to be different") + return 0, errors.New("from and to needs to be different") } if start > end { delta = -1 diff --git a/eth/backend.go b/eth/backend.go index 4caab9bad6..4ba8df951b 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -323,7 +323,7 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) { if etherbase != (common.Address{}) { return etherbase, nil } - return common.Address{}, fmt.Errorf("etherbase must be explicitly specified") + return common.Address{}, errors.New("etherbase must be explicitly specified") } // isLocalBlock checks whether the specified block is mined diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 58681df2ea..456bd77413 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -166,10 +166,10 @@ func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI { func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { if payloadAttributes != nil { if payloadAttributes.Withdrawals != nil { - return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1")) + return engine.STATUS_INVALID, engine.InvalidParams.With(errors.New("withdrawals not supported in V1")) } if api.eth.BlockChain().Config().IsShanghai(api.eth.BlockChain().Config().LondonBlock, payloadAttributes.Timestamp) { - return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("forkChoiceUpdateV1 called post-shanghai")) + return engine.STATUS_INVALID, engine.InvalidParams.With(errors.New("forkChoiceUpdateV1 called post-shanghai")) } } return api.forkchoiceUpdated(update, payloadAttributes) @@ -386,7 +386,7 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.Transit TerminalBlockNumber: config.TerminalBlockNumber, }, nil } - return nil, fmt.Errorf("invalid terminal block hash") + return nil, errors.New("invalid terminal block hash") } return &engine.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil } @@ -417,7 +417,7 @@ func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID) (*engine.Executi // NewPayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain. func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.PayloadStatusV1, error) { if params.Withdrawals != nil { - return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1")) + return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("withdrawals not supported in V1")) } return api.newPayload(params) } @@ -426,10 +426,10 @@ func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.Payl func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) { if api.eth.BlockChain().Config().IsShanghai(new(big.Int).SetUint64(params.Number), params.Timestamp) { if params.Withdrawals == nil { - return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("nil withdrawals post-shanghai")) + return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil withdrawals post-shanghai")) } } else if params.Withdrawals != nil { - return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("non-nil withdrawals pre-shanghai")) + return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("non-nil withdrawals pre-shanghai")) } return api.newPayload(params) } diff --git a/eth/filters/api.go b/eth/filters/api.go index f9ae70eba7..cc08b442e8 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -33,6 +33,11 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +var ( + errInvalidTopic = errors.New("invalid topic(s)") + errFilterNotFound = errors.New("filter not found") +) + // filter is a helper struct that holds meta information over the filter type // and associated subscription in the event system. type filter struct { @@ -376,7 +381,7 @@ func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Lo api.filtersMu.Unlock() if !found || f.typ != LogsSubscription { - return nil, fmt.Errorf("filter not found") + return nil, errFilterNotFound } var filter *Filter @@ -452,7 +457,7 @@ func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) { } } - return []interface{}{}, fmt.Errorf("filter not found") + return []interface{}{}, errFilterNotFound } // returnHashes is a helper that will return an empty hash array case the given hash array is nil, @@ -491,7 +496,7 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { if raw.BlockHash != nil { if raw.FromBlock != nil || raw.ToBlock != nil { // BlockHash is mutually exclusive with FromBlock/ToBlock criteria - return fmt.Errorf("cannot specify both BlockHash and FromBlock/ToBlock, choose one or the other") + return errors.New("cannot specify both BlockHash and FromBlock/ToBlock, choose one or the other") } args.BlockHash = raw.BlockHash } else { @@ -564,11 +569,11 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { } args.Topics[i] = append(args.Topics[i], parsed) } else { - return fmt.Errorf("invalid topic(s)") + return errInvalidTopic } } default: - return fmt.Errorf("invalid topic(s)") + return errInvalidTopic } } } diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 9fc20f335b..1768681c17 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -20,6 +20,7 @@ package filters import ( "context" + "errors" "fmt" "sync" "sync/atomic" @@ -331,7 +332,7 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ if from >= 0 && to == rpc.LatestBlockNumber { return es.subscribeLogs(crit, logs), nil } - return nil, fmt.Errorf("invalid from and to block combination: from > to") + return nil, errors.New("invalid from and to block combination: from > to") } // subscribeMinedPendingLogs creates a subscription that returned mined and diff --git a/eth/tracers/js/goja.go b/eth/tracers/js/goja.go index 2a2789e93d..3fa1613daf 100644 --- a/eth/tracers/js/goja.go +++ b/eth/tracers/js/goja.go @@ -89,7 +89,7 @@ func fromBuf(vm *goja.Runtime, bufType goja.Value, buf goja.Value, allowString b b := obj.Get("buffer").Export().(goja.ArrayBuffer).Bytes() return b, nil } - return nil, fmt.Errorf("invalid buffer type") + return nil, errors.New("invalid buffer type") } // jsTracer is an implementation of the Tracer interface which evaluates diff --git a/eth/tracers/logger/logger_test.go b/eth/tracers/logger/logger_test.go index bde43e5ff7..3192a15cba 100644 --- a/eth/tracers/logger/logger_test.go +++ b/eth/tracers/logger/logger_test.go @@ -18,7 +18,7 @@ package logger import ( "encoding/json" - "fmt" + "errors" "math/big" "testing" @@ -85,7 +85,7 @@ func TestStructLogMarshalingOmitEmpty(t *testing.T) { }{ {"empty err and no fields", &StructLog{}, `{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`}, - {"with err", &StructLog{Err: fmt.Errorf("this failed")}, + {"with err", &StructLog{Err: errors.New("this failed")}, `{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP","error":"this failed"}`}, {"with mem", &StructLog{Memory: make([]byte, 2), MemorySize: 2}, `{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000","memSize":2,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`}, diff --git a/eth/tracers/tracers.go b/eth/tracers/tracers.go index 023f73ef37..7b43b7cf83 100644 --- a/eth/tracers/tracers.go +++ b/eth/tracers/tracers.go @@ -19,6 +19,7 @@ package tracers import ( "encoding/json" + "errors" "fmt" "math/big" @@ -105,7 +106,7 @@ const ( // It zero-pads the slice if it extends beyond memory bounds. func GetMemoryCopyPadded(m *vm.Memory, offset, size int64) ([]byte, error) { if offset < 0 || size < 0 { - return nil, fmt.Errorf("offset or size must not be negative") + return nil, errors.New("offset or size must not be negative") } if int(offset+size) < m.Len() { // slice fully inside memory return m.GetCopy(offset, size), nil