IntersectMBO / IntersectMBO/ouroboros-network

Enrich `GetImmutableBlockPointError` with an error variant for invalid hash size, so `ouroboros-consensus` can properly validate `RawBlockHash` size

Open Beginner friendly
#5,396 0 comments 0 reactions 0 assignees View on GitHub
cardano-diffusion
Dominant language
Haskell
Stars
296
Forks
104
Avg merge
2d 10h
Merged PRs (30d)
4

Description

The `getImmutableBlockPoint` callback in `Cardano.Network.LedgerPeerConsensusInterface.LedgerPeersConsensusInterface` receives a `Point RawBlockHash`, where `RawBlockHash` wraps a `ShortByteString` of arbitrary length apparently.

On the consensus side, in `ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs`, when we use `getImmutableBlockPoint`, we have to convert that raw hash into a block-specific `HeaderHash blk`. Previously `ConvertRawHash` was very lax about hash length, and `hashSize` value was not enforced by conversion methods from/to `HeaderHash`.

With [[Peras 25.5]](https://github.com/IntersectMBO/ouroboros-consensus/pull/2033) PR we are improving the `ConvertRawHash` class to be more explicit about expected hash length, and ensure the hash length invariant is respected during conversions (FTR, the old functions are still available but have been prefixed by `unsafe` to indicate that they do not enforce the invariant).

So, ideally, in `getImmutableBlockPoint`, when the `RawBlockHash` size doesn't match the expected one for `HeaderHash blk`, we would like to be able to return a proper error value instead of a fatal `error`.

### Suggestion

Add a constructor `ImmutableBlockInvalidHashSize Int Int` to `GetImmutableBlockPointError` type in `Cardano.Network.LedgerPeerConsensusInterface`

Contributor guide

Open the contributing guide

Research direction

Start in Cardano.Network.LedgerPeerConsensusInterface by reading GetImmutableBlockPointError and the getImmutableBlockPoint callback, then inspect its use in ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs. Add the suggested invalid-hash-size error variant so a RawBlockHash size mismatch can be returned as an error rather than a fatal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
networking
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.