From dd25a4f5ab18703121d70589151f4fc450f99678 Mon Sep 17 00:00:00 2001 From: Delweng Date: Thu, 25 May 2023 14:51:13 +0800 Subject: [PATCH] les, signer, light: replace noarg fmt.Errorf with errors.New (#27336) Signed-off-by: jsvisa --- les/benchmark.go | 8 ++++---- les/catalyst/api.go | 2 +- les/client.go | 6 +++--- les/retrieve.go | 4 ++-- light/trie_test.go | 5 +++-- signer/core/signed_data.go | 4 ++-- signer/core/uiapi.go | 2 +- signer/rules/rules.go | 3 ++- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/les/benchmark.go b/les/benchmark.go index 95563a21aa..c63a2564d5 100644 --- a/les/benchmark.go +++ b/les/benchmark.go @@ -19,7 +19,7 @@ package les import ( crand "crypto/rand" "encoding/binary" - "fmt" + "errors" "math/big" "math/rand" "sync" @@ -59,7 +59,7 @@ func (b *benchmarkBlockHeaders) init(h *serverHandler, count int) error { b.offset = 0 b.randMax = h.blockchain.CurrentHeader().Number.Int64() + 1 - d if b.randMax < 0 { - return fmt.Errorf("chain is too short") + return errors.New("chain is too short") } if b.reverse { b.offset = d @@ -137,7 +137,7 @@ func (b *benchmarkHelperTrie) init(h *serverHandler, count int) error { b.headNum = b.sectionCount*params.CHTFrequency - 1 } if b.sectionCount == 0 { - return fmt.Errorf("no processed sections available") + return errors.New("no processed sections available") } return nil } @@ -338,7 +338,7 @@ func (h *serverHandler) measure(setup *benchmarkSetup, count int) error { case <-h.closeCh: clientPipe.Close() serverPipe.Close() - return fmt.Errorf("Benchmark cancelled") + return errors.New("Benchmark cancelled") } setup.totalTime += time.Duration(mclock.Now() - start) diff --git a/les/catalyst/api.go b/les/catalyst/api.go index c9db514fcc..30b41101db 100644 --- a/les/catalyst/api.go +++ b/les/catalyst/api.go @@ -213,7 +213,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 diff --git a/les/client.go b/les/client.go index 9561ba777e..bd6667429e 100644 --- a/les/client.go +++ b/les/client.go @@ -18,7 +18,7 @@ package les import ( - "fmt" + "errors" "strings" "time" @@ -268,12 +268,12 @@ type LightDummyAPI struct{} // Etherbase is the address that mining rewards will be send to func (s *LightDummyAPI) Etherbase() (common.Address, error) { - return common.Address{}, fmt.Errorf("mining is not supported in light mode") + return common.Address{}, errors.New("mining is not supported in light mode") } // Coinbase is the address that mining rewards will be send to (alias for Etherbase) func (s *LightDummyAPI) Coinbase() (common.Address, error) { - return common.Address{}, fmt.Errorf("mining is not supported in light mode") + return common.Address{}, errors.New("mining is not supported in light mode") } // Hashrate returns the POW hashrate diff --git a/les/retrieve.go b/les/retrieve.go index 307af04212..2b9e239e9a 100644 --- a/les/retrieve.go +++ b/les/retrieve.go @@ -18,7 +18,7 @@ package les import ( "context" - "fmt" + "errors" "sync" "time" @@ -110,7 +110,7 @@ func (rm *retrieveManager) retrieve(ctx context.Context, reqID uint64, req *dist case <-ctx.Done(): sentReq.stop(ctx.Err()) case <-shutdown: - sentReq.stop(fmt.Errorf("client is shutting down")) + sentReq.stop(errors.New("client is shutting down")) } return sentReq.getError() } diff --git a/light/trie_test.go b/light/trie_test.go index 0ab3eb02a0..0a24609cbd 100644 --- a/light/trie_test.go +++ b/light/trie_test.go @@ -19,6 +19,7 @@ package light import ( "bytes" "context" + "errors" "fmt" "math/big" "testing" @@ -78,9 +79,9 @@ func diffTries(t1, t2 state.Trie) error { case i2.Err != nil: return fmt.Errorf("light trie iterator error: %v", i2.Err) case i1.Next(): - return fmt.Errorf("full trie iterator has more k/v pairs") + return errors.New("full trie iterator has more k/v pairs") case i2.Next(): - return fmt.Errorf("light trie iterator has more k/v pairs") + return errors.New("light trie iterator has more k/v pairs") } return nil } diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index 8ee572f53e..3c2b6f5d45 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -304,10 +304,10 @@ func (api *SignerAPI) EcRecover(ctx context.Context, data hexutil.Bytes, sig hex // // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover if len(sig) != 65 { - return common.Address{}, fmt.Errorf("signature must be 65 bytes long") + return common.Address{}, errors.New("signature must be 65 bytes long") } if sig[64] != 27 && sig[64] != 28 { - return common.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)") + return common.Address{}, errors.New("invalid Ethereum signature (V is not 27 or 28)") } sig[64] -= 27 // Transform yellow paper V from 27/28 to 0/1 hash := accounts.TextHash(data) diff --git a/signer/core/uiapi.go b/signer/core/uiapi.go index 924203a139..4a060147a6 100644 --- a/signer/core/uiapi.go +++ b/signer/core/uiapi.go @@ -177,7 +177,7 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw return nil, err } if wallet.URL().Scheme != keystore.KeyStoreScheme { - return nil, fmt.Errorf("account is not a keystore-account") + return nil, errors.New("account is not a keystore-account") } return os.ReadFile(wallet.URL().Path) } diff --git a/signer/rules/rules.go b/signer/rules/rules.go index 5ed4514e02..c9921e57a9 100644 --- a/signer/rules/rules.go +++ b/signer/rules/rules.go @@ -18,6 +18,7 @@ package rules import ( "encoding/json" + "errors" "fmt" "os" "strings" @@ -146,7 +147,7 @@ func (r *rulesetUI) checkApproval(jsfunc string, jsarg []byte, err error) (bool, log.Info("Op rejected") return false, nil } - return false, fmt.Errorf("unknown response") + return false, errors.New("unknown response") } func (r *rulesetUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) {