Skip to content

Conversation

@f-f
Copy link
Contributor

@f-f f-f commented Jan 21, 2026

Description

First part of #5513: we remove the default implementation for DecCBOR through FromCBOR, so that types that contain Bytestrings are more easily routed to the version-aware decoding

Checklist

  • Commits in meaningful sequence and with useful messages.
  • Tests added or updated when needed.
  • CHANGELOG.md files updated for packages with externally visible changes.
    NOTE: New section is never added with the code changes. (See RELEASING.md).
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary.
    NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
  • Code formatted (use scripts/fourmolize.sh).
  • Cabal files formatted (use scripts/cabal-format.sh).
  • CDDL files are up to date (use scripts/gen-cddl.sh)
  • hie.yaml updated (use scripts/gen-hie.sh).
  • Self-reviewed the diff.

@f-f f-f requested a review from lehins January 21, 2026 22:41
@f-f f-f requested a review from a team as a code owner January 21, 2026 22:41
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is really no need for all of those extra top level definitions for reusability in both types of decoders, they only bring noise.
It is better to use special helper fromEraCBOR (see my suggestion)

We could even potentially add a newtype like this to Cardano.Ledger.Core.Era:

newtype EraDecoder era a = EraDecoder a

instance (Era era, DecCBOR a) => FromCBOR (EraDecoder era) where
  fromCBOR = fromEraCBOR @era 

which can then be used to do deriving via.

Comment on lines 476 to 479
decCBOR = do
sbs <- decCBOR @ShortByteString
maybe (fail "Invalid hash size") pure $ hashFromBytesShort sbs
{-# INLINE decCBOR #-}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually need to create a DecCBOR instance for PackedBytes. For now that instance will simply biggy back on FromCBOR instance, but then we will need to export some functionality for safe construction of PackedBytes from this module: `https://github.com/IntersectMBO/cardano-base/blob/d78f2f350017f0b3a1c57f483a2c323676756622/cardano-crypto-class/src/Cardano/Crypto/PackedBytes.hs

Suggested change
decCBOR = do
sbs <- decCBOR @ShortByteString
maybe (fail "Invalid hash size") pure $ hashFromBytesShort sbs
{-# INLINE decCBOR #-}
decCBOR = hashFromPackedBytes <$> decCBOR
{-# INLINE decCBOR #-}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see - that's a hidden module so even the FromCBOR instance is not exported. I guess this is blocked on exposing at least that from base?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants