The system for managing total difficulty is that it is computed and stored on each node, but not in the block header. The way it has been stored has undergone revisions, back in 2015 (in Go-Ethereum) it was stored as part of the block, then it became its own field in the database (commit cdc2662, although the then private "td" field in "Block" struct remained until 2022... see pull request #25010. ) But, why not just store the total difficulty in the block header? That allows the equivalent of "merkle proofs", as in, anyone can verify it. And, since the difficulty of a block can be calculated from the total difficulty of that block, minus the total difficulty of the previous block, only total difficulty actually has to be stored in the header.
What are the reasons that td
is not stored in header instead of Difficulty
? That it "reduces calculations" yes sure but it adds extra database read and writes... so it probably evens out pretty quickly, or worsens for the one without td
in the block.
Edit:
Best explanation I have is that not just the block difficulty has to be known, but also the parent block difficulty, to validate a block (done in verifyHeader
in Ethhash
class in Go-Ethereum, or ValidateHeader
before the consensus engine interface was added). Thus you need to include the grandparent block to know difficulty if you store Td
instead of Difficulty
in header. This does make it a little more complex to store Td instead.