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>
This commit is contained in:
parent
b21ba668e6
commit
8a78a4f79f
@ -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)
|
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
|
||||||
}
|
}
|
||||||
if chain.Config().IsShanghai(header.Number, header.Time) {
|
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) {
|
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
|
// All basic checks passed, verify cascading fields
|
||||||
return c.verifyCascadingFields(chain, header, parents)
|
return c.verifyCascadingFields(chain, header, parents)
|
||||||
|
@ -263,10 +263,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
|
|||||||
return consensus.ErrInvalidNumber
|
return consensus.ErrInvalidNumber
|
||||||
}
|
}
|
||||||
if chain.Config().IsShanghai(header.Number, header.Time) {
|
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) {
|
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
|
// Add some fake checks for tests
|
||||||
if ethash.fakeDelay != nil {
|
if ethash.fakeDelay != nil {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package misc
|
package misc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade
|
|||||||
}
|
}
|
||||||
// Verify the header is not malformed
|
// Verify the header is not malformed
|
||||||
if header.BaseFee == nil {
|
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.
|
// Verify the baseFee is correct based on the parent header.
|
||||||
expectedBaseFee := CalcBaseFee(config, parent)
|
expectedBaseFee := CalcBaseFee(config, parent)
|
||||||
|
@ -554,7 +554,7 @@ func (api *DebugAPI) GetAccessibleState(from, to rpc.BlockNumber) (uint64, error
|
|||||||
if num.Int64() < 0 {
|
if num.Int64() < 0 {
|
||||||
block := api.eth.blockchain.CurrentBlock()
|
block := api.eth.blockchain.CurrentBlock()
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return 0, fmt.Errorf("current block missing")
|
return 0, errors.New("current block missing")
|
||||||
}
|
}
|
||||||
return block.Number.Uint64(), nil
|
return block.Number.Uint64(), nil
|
||||||
}
|
}
|
||||||
@ -574,7 +574,7 @@ func (api *DebugAPI) GetAccessibleState(from, to rpc.BlockNumber) (uint64, error
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if start == end {
|
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 {
|
if start > end {
|
||||||
delta = -1
|
delta = -1
|
||||||
|
@ -323,7 +323,7 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
|
|||||||
if etherbase != (common.Address{}) {
|
if etherbase != (common.Address{}) {
|
||||||
return etherbase, nil
|
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
|
// 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) {
|
func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
|
||||||
if payloadAttributes != nil {
|
if payloadAttributes != nil {
|
||||||
if payloadAttributes.Withdrawals != 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) {
|
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)
|
return api.forkchoiceUpdated(update, payloadAttributes)
|
||||||
@ -386,7 +386,7 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.Transit
|
|||||||
TerminalBlockNumber: config.TerminalBlockNumber,
|
TerminalBlockNumber: config.TerminalBlockNumber,
|
||||||
}, nil
|
}, 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
|
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.
|
// 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) {
|
func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
|
||||||
if params.Withdrawals != nil {
|
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)
|
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) {
|
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 api.eth.BlockChain().Config().IsShanghai(new(big.Int).SetUint64(params.Number), params.Timestamp) {
|
||||||
if params.Withdrawals == nil {
|
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 {
|
} 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)
|
return api.newPayload(params)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/rpc"
|
"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
|
// filter is a helper struct that holds meta information over the filter type
|
||||||
// and associated subscription in the event system.
|
// and associated subscription in the event system.
|
||||||
type filter struct {
|
type filter struct {
|
||||||
@ -376,7 +381,7 @@ func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Lo
|
|||||||
api.filtersMu.Unlock()
|
api.filtersMu.Unlock()
|
||||||
|
|
||||||
if !found || f.typ != LogsSubscription {
|
if !found || f.typ != LogsSubscription {
|
||||||
return nil, fmt.Errorf("filter not found")
|
return nil, errFilterNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
var filter *Filter
|
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,
|
// 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.BlockHash != nil {
|
||||||
if raw.FromBlock != nil || raw.ToBlock != nil {
|
if raw.FromBlock != nil || raw.ToBlock != nil {
|
||||||
// BlockHash is mutually exclusive with FromBlock/ToBlock criteria
|
// 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
|
args.BlockHash = raw.BlockHash
|
||||||
} else {
|
} else {
|
||||||
@ -564,11 +569,11 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
args.Topics[i] = append(args.Topics[i], parsed)
|
args.Topics[i] = append(args.Topics[i], parsed)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("invalid topic(s)")
|
return errInvalidTopic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid topic(s)")
|
return errInvalidTopic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package filters
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -331,7 +332,7 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ
|
|||||||
if from >= 0 && to == rpc.LatestBlockNumber {
|
if from >= 0 && to == rpc.LatestBlockNumber {
|
||||||
return es.subscribeLogs(crit, logs), nil
|
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
|
// 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()
|
b := obj.Get("buffer").Export().(goja.ArrayBuffer).Bytes()
|
||||||
return b, nil
|
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
|
// jsTracer is an implementation of the Tracer interface which evaluates
|
||||||
|
@ -18,7 +18,7 @@ package logger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ func TestStructLogMarshalingOmitEmpty(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"empty err and no fields", &StructLog{},
|
{"empty err and no fields", &StructLog{},
|
||||||
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
|
`{"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"}`},
|
`{"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},
|
{"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"}`},
|
`{"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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ const (
|
|||||||
// It zero-pads the slice if it extends beyond memory bounds.
|
// It zero-pads the slice if it extends beyond memory bounds.
|
||||||
func GetMemoryCopyPadded(m *vm.Memory, offset, size int64) ([]byte, error) {
|
func GetMemoryCopyPadded(m *vm.Memory, offset, size int64) ([]byte, error) {
|
||||||
if offset < 0 || size < 0 {
|
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
|
if int(offset+size) < m.Len() { // slice fully inside memory
|
||||||
return m.GetCopy(offset, size), nil
|
return m.GetCopy(offset, size), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user