0

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.

2
  • I don't know if it was a reason or not, but the introduction of the ice age or difficulty bomb artificially increase the difficulty required to mine blocks.
    – Ismael
    Commented Mar 19 at 15:12
  • OK, you remind me now. The difficulty of previous block also has to be known, so that means it has to be compared with its parent too, if Td is stored. Why I asked is I'm building my own consensus engine (already did), and have something similar to difficulty. But, I don't have to calculate two blocks back. So perhaps it makes more sense in my consensus engine to store equivalent of Td.
    – BipedalJoe
    Commented Mar 19 at 18:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.