Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This unifies v1 and v2 block headers and promotes
BlockHeader
fromgateway
totypes
. It also changes how V2 block IDs are computed.I had previously omitted the
ParentID
from the v2 block "header," because it is incorporated into theCommitment
field (via the hash of the parentconsensus.State
). This left the first 32 bytes of the 80-byte hash preimage unused, so I filled them with a distinguisher string.However, after reflecting on how headers are actually used in the Syncer, I think it's better to include the
ParentID
after all, even if it's slightly redundant and not strictly necessary. Here's my reasoning, in the form of a dialogue:ParentID
, you could check that it matched your current block before abandoning it.ParentID
doesn't prevent this class of attack, because the purported block could be invalid for other reasons that aren't detectable from the header alone. For example, it could have missing signatures. Moreover, this attack requires the attacker to expend a lot of hashrate; why wouldn't they use that hashrate to mine a valid block instead?ParentID
is different! You don't need to expend a lot of hashrate mining a purposefully-invalid block; instead, you can reuse the header of a recently-mined block. That header will (probably) still have sufficient proof-of-work to meet the current target, so it will pass the initial validation check.ParentID
anyway. We weren't using that space anyway (but we need to preserve it, for miner compatibility), it's occasionally useful, and you don't need to twist your brain into knots convincing yourself that the system is still secure without it.