go-ethereum/internal/ethapi
Péter Szilágyi 39638c81c5
all: nuke total difficulty (#30744)
The total difficulty is the sum of all block difficulties from genesis
to a certain block. This value was used in PoW for deciding which chain
is heavier, and thus which chain to select. Since PoS has a different
fork selection algorithm, all blocks since the merge have a difficulty
of 0, and all total difficulties are the same for the past 2 years.

Whilst the TDs are mostly useless nowadays, there was never really a
reason to mess around removing them since they are so tiny. This
reasoning changes when we go down the path of pruned chain history. In
order to reconstruct any TD, we **must** retrieve all the headers from
chain head to genesis and then iterate all the difficulties to compute
the TD.

In a world where we completely prune past chain segments (bodies,
receipts, headers), it is not possible to reconstruct the TD at all. In
a world where we still keep chain headers and prune only the rest,
reconstructing it possible as long as we process (or download) the chain
forward from genesis, but trying to snap sync the head first and
backfill later hits the same issue, the TD becomes impossible to
calculate until genesis is backfilled.

All in all, the TD is a messy out-of-state, out-of-consensus computed
field that is overall useless nowadays, but code relying on it forces
the client into certain modes of operation and prevents other modes or
other optimizations. This PR completely nukes out the TD from the node.
It doesn't compute it, it doesn't operate on it, it's as if it didn't
even exist.

Caveats:

- Whenever we have APIs that return TD (devp2p handshake, tracer, etc.)
we return a TD of 0.
- For era files, we recompute the TD during export time (fairly quick)
to retain the format content.
- It is not possible to "verify" the merge point (i.e. with TD gone, TTD
is useless). Since we're not verifying PoW any more, just blindly trust
it, not verifying but blindly trusting the many year old merge point
seems just the same trust model.
- Our tests still need to be able to generate pre and post merge blocks,
so they need a new way to split the merge without TTD. The PR introduces
a settable ttdBlock field on the consensus object which is used by tests
as the block where originally the TTD happened. This is not needed for
live nodes, we never want to generate old blocks.
- One merge transition consensus test was disabled. With a
non-operational TD, testing how the client reacts to TTD is useless, it
cannot react.

Questions:

- Should we also drop total terminal difficulty from the genesis json?
It's a number we cannot react on any more, so maybe it would be cleaner
to get rid of even more concepts.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-01-28 18:55:41 +01:00
..
override triedb/pathdb: configure different node hasher in pathdb (#31008) 2025-01-10 20:51:19 +08:00
testdata all: exclude empty outputs in requests commitment (#30670) 2024-11-28 11:48:50 +01:00
addrlock.go all: update license information (#16089) 2018-02-14 13:49:11 +01:00
api.go core, core/types: rename AuthList to SetCodeAuthorizations (#30935) 2024-12-19 10:06:33 +01:00
api_test.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
backend.go core, eth, internal, cmd: rework EVM constructor (#30745) 2024-11-20 12:35:52 +01:00
dbapi.go all: remove concept of public/private API definitions (#25053) 2022-06-21 12:05:43 +03:00
errors.go internal/ethapi: eth_multicall (#27720) 2024-09-06 11:31:00 +02:00
logtracer.go internal/ethapi: eth_multicall (#27720) 2024-09-06 11:31:00 +02:00
simulate.go internal/ethapi: update default simulation timestamp increment to 12 (#30981) 2025-01-03 20:15:06 +08:00
simulate_test.go internal/ethapi: update default simulation timestamp increment to 12 (#30981) 2025-01-03 20:15:06 +08:00
transaction_args.go core/types: change SetCodeTx.ChainID to uint256 (#30982) 2025-01-14 06:42:18 -07:00
transaction_args_test.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00