Introduce HasBinaryBlockInfo and make it overridable in SerialiseHFC #2435
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.
Fixes #2239.
Instead of having a
RunNode
method to get theBinaryBlockInfo
of ablock (offset and size of the header within the block), create a separate type
class
HasBinaryBlockInfo
for it. This is another step in the clean-up processof
RunNode
that started in the weeks before the HFC was merged.This means we can provide a generic implementation of
HasBinaryBlockInfo
forHardForkBlock
that takes the HFC wrapper into account. This wrapper adds alistlen 2 and a tag indicating the era to the start of each block, so we need to
shift the offset of the header by 2 bytes.
More importantly, we now allow overriding the
getBinaryBlockInfo
method inSerialiseHFC
, just like we allow overriding the disk en/decoder for blocks.This allows us to do the right thing for the Byron era: no era wrapper for
Byron, but start using era wrappers for the eras after it.
This also fixes a bug:
cardano-node
running in pure Shelley mode usesShelleyHFC
, i.e., aShelleyBlock
wrapped in the HFC. Since the genericRunNode
instance forHardForkBlock '[blk]
forwards everything to theinstance for
blk
, we were using theBinaryBlockInfo
implementation forShelley, which didn't account for the era wrapper in the header offset. Since
we were using the era wrapper to serialise
ShelleyHFC
blocks on disk, thismeant we were extracting the header from the on-disk blocks incorrectly,
resulting in deserialisation failures when reading headers from disk.
This refactoring allows us to fix it properly: now the defaults for
SerialiseHFC
do the right thing forShelleyHFC
, and forByronHFC
weforward to
ByronBlock
, just like for all the other methods. This meansShelleyHFC
starts out with an era wrapper around blocks from the first era (toallow for easier transitions to later eras, which is the right thing to do from
the start), but
ByronHFC
's block format is binary compatible withByronBlock
.