From e481a1a7d12345c860b63d3be63655b43164b481 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 21 Oct 2025 19:36:50 +0800 Subject: [PATCH] fix json encoding of BAL for debug API: make it human-readable again --- core/state_processor.go | 2 +- core/types/bal/bal_encoding.go | 10 ++++++++++ eth/api_debug.go | 20 ++------------------ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index e7ade93c7a..7bd224ea28 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -137,7 +137,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.chain.Engine().Finalize(p.chain, header, tracingStateDB, block.Body()) - if hooks := cfg.Tracer; hooks != nil { + if hooks := cfg.Tracer; hooks != nil && hooks.OnBlockFinalization != nil { hooks.OnBlockFinalization() } diff --git a/core/types/bal/bal_encoding.go b/core/types/bal/bal_encoding.go index 515033cafb..aedc56f4c5 100644 --- a/core/types/bal/bal_encoding.go +++ b/core/types/bal/bal_encoding.go @@ -67,6 +67,16 @@ func (e *BlockAccessList) DecodeRLP(dec *rlp.Stream) error { return nil } +// StringableRepresentation returns an instance of the block access list +// which can be converted to a human-readable JSON representation. +func (e *BlockAccessList) StringableRepresentation() interface{} { + res := []AccountAccess{} + for _, aa := range *e { + res = append(res, aa) + } + return &res +} + func (e *BlockAccessList) String() string { var res bytes.Buffer enc := json.NewEncoder(&res) diff --git a/eth/api_debug.go b/eth/api_debug.go index 2d1adb20e2..698c0c3bfc 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -17,11 +17,9 @@ package eth import ( - "bytes" "context" "errors" "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" "time" "github.com/ethereum/go-ethereum/common" @@ -537,7 +535,7 @@ func (api *DebugAPI) ExecutionWitnessByHash(hash common.Hash) (*stateless.ExtWit // GetBlockAccessList returns a block access list for the given number/hash // or nil if one does not exist. -func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (*bal.BlockAccessList, error) { +func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (interface{}, error) { var block *types.Block if num := number.BlockNumber; num != nil { block = api.eth.blockchain.GetBlockByNumber(uint64(num.Int64())) @@ -548,19 +546,5 @@ func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (*bal.Bloc if block == nil { return nil, fmt.Errorf("block not found") } - return block.Body().AccessList, nil -} - -// GetEncodedBlockAccessList returns a block access list corresponding to a -// block number/hash in RLP-encoded form. It returns nil if one does not exist. -func (api *DebugAPI) GetEncodedBlockAccessList(number rpc.BlockNumberOrHash) ([]byte, error) { - bal, err := api.GetBlockAccessList(number) - if err != nil { - return nil, err - } - var enc bytes.Buffer - if err = bal.EncodeRLP(&enc); err != nil { - return nil, err - } - return enc.Bytes(), nil + return block.Body().AccessList.StringableRepresentation(), nil }