From 2ff9f336ede994f9840baaa60ca7b17b3bd9bf11 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:12 +0800 Subject: [PATCH] core: improve contextual information on core errors (#21869) --- core/blockchain_test.go | 2 +- core/state_processor.go | 2 +- core/state_transition.go | 5 ----- light/lightchain_test.go | 3 ++- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 0ea24c180b..849daac1b8 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -439,7 +439,7 @@ func testBadHashes(t *testing.T, full bool) { _, err = blockchain.InsertHeaderChain(headers, 1) } - if err != ErrBlacklistedHash { + if !errors.Is(err, ErrBlacklistedHash) { t.Errorf("error mismatch: have: %v, want: %v", err, ErrBlacklistedHash) } } diff --git a/core/state_processor.go b/core/state_processor.go index 3a503f1c18..a6ecb8f7ca 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -120,7 +120,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, tra statedb.SetTxContext(tx.Hash(), i) receipt, gas, err, tokenFeeUsed := applyTransaction(p.config, balanceFee, gp, statedb, coinbaseOwner, blockNumber, header.BaseFee, blockHash, tx, usedGas, vmenv) if err != nil { - return nil, nil, 0, err + return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } receipts = append(receipts, receipt) allLogs = append(allLogs, receipt.Logs...) diff --git a/core/state_transition.go b/core/state_transition.go index 24375cf8ff..1bba04e2fa 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -17,7 +17,6 @@ package core import ( - "errors" "fmt" "math" "math/big" @@ -32,10 +31,6 @@ import ( var emptyCodeHash = crypto.Keccak256Hash(nil) -var ( - errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas") -) - /* The State Transitioning Model diff --git a/light/lightchain_test.go b/light/lightchain_test.go index df7808b089..2c710c07d2 100644 --- a/light/lightchain_test.go +++ b/light/lightchain_test.go @@ -18,6 +18,7 @@ package light import ( "context" + "errors" "math/big" "testing" @@ -317,7 +318,7 @@ func TestBadHeaderHashes(t *testing.T) { var err error headers := makeHeaderChainWithDiff(bc.genesisBlock, []int{1, 2, 4}, 10) core.BadHashes[headers[2].Hash()] = true - if _, err = bc.InsertHeaderChain(headers, 1); err != core.ErrBlacklistedHash { + if _, err = bc.InsertHeaderChain(headers, 1); !errors.Is(err, core.ErrBlacklistedHash) { t.Errorf("error mismatch: have: %v, want %v", err, core.ErrBlacklistedHash) } }