eth,consensus: replace noarg fmt.Errorf with errors.New (#27330)

* eth: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

* consensus: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

---------

Signed-off-by: jsvisa <delweng@gmail.com>
pull/27445/head
Delweng 2 years ago committed by GitHub
parent b21ba668e6
commit 8a78a4f79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      consensus/clique/clique.go
  2. 4
      consensus/ethash/consensus.go
  3. 3
      consensus/misc/eip1559.go
  4. 4
      eth/api.go
  5. 2
      eth/backend.go
  6. 12
      eth/catalyst/api.go
  7. 15
      eth/filters/api.go
  8. 3
      eth/filters/filter_system.go
  9. 2
      eth/tracers/js/goja.go
  10. 4
      eth/tracers/logger/logger_test.go
  11. 3
      eth/tracers/tracers.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)

@ -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 {

@ -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)

@ -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

@ -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

@ -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)
}

@ -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
}
}
}

@ -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

@ -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

@ -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"}`},

@ -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

Loading…
Cancel
Save