From 04aa6bbdae9b32cbb1a9ddad275df01bd310fb4a Mon Sep 17 00:00:00 2001 From: Somnath Date: Mon, 28 Oct 2024 20:13:43 +0530 Subject: [PATCH] jsonrpc: Add totalDifficulty back as interim hive fix (#12469) Until hive implements https://github.com/ethereum/execution-apis/pull/570 Partial revert of https://github.com/erigontech/erigon/pull/11809/files The reason this would still work with or without the snapshot files change: - RPC tests don't have to know about this PR, since it's based on a state with assumed nil for the `totalDifficulty` field. - Hive tests don't progress till pruning, nor do they start with any snapshots (unless this changes somehow) --- turbo/jsonrpc/eth_block.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index ed454a3a478..37d1a30f540 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -229,6 +229,16 @@ func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber } additionalFields := make(map[string]interface{}) + // ============================= + // TODO - remove this after https://github.com/ethereum/execution-apis/pull/570 is implemented by Hive and rest of the community + td, err := rawdb.ReadTd(tx, b.Hash(), b.NumberU64()) + if err != nil { + return nil, err + } + if td != nil { + additionalFields["totalDifficulty"] = (*hexutil.Big)(td) + } + // ================================= chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err @@ -282,6 +292,17 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, numberOrHash rpc.BlockNu } number := block.NumberU64() + // ============================= + // TODO - remove this after https://github.com/ethereum/execution-apis/pull/570 is implemented by Hive and rest of the community + td, err := rawdb.ReadTd(tx, hash, number) + if err != nil { + return nil, err + } + if td != nil { + additionalFields["totalDifficulty"] = (*hexutil.Big)(td) + } + // ============================== + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err