ouroboros-consensus:cardano
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Cardano.CanHardFork.OptimizedTxIdComparison

Description

Allocation-free cross-era comparison of Cardano transaction ids.

Both OneEraGenTxId instances order by the txid hash, ignoring the era. We read each id's 32-byte hash (Blake2b-256) as four big-endian Word64# and compare those in registers. The words are unboxed, so no hash is boxed on the heap on any era's path:

  • Shelley-based eras store the hash as PackedBytes32 (four words already); we unbox its fields.
  • Byron stores it as a ShortByteString; we read four big-endian words out.

The extraction walks the era sum with a single dictionary used on every branch, so it is strict in the dictionary and allocates no per-level thunk.

Synopsis

Documentation

class ToTxIdWords blk where Source #

The four big-endian 64-bit words of an era's 32-byte txid hash (Blake2b-256), unboxed so no hash is materialised on the heap. An era whose txid hash is not four words is rejected by the Shelley instance's PackedBytes32 match rather than miscompared.

compareCardanoGenTxId ∷ ∀ (xs ∷ [Type]). All ToTxIdWords xs ⇒ NS WrapGenTxId xs → NS WrapGenTxId xs → Ordering Source #

Order two Cardano transaction ids by their txid hash, ignoring the era.

txIdWords reads each hash as four unboxed words and compareW64 orders them in registers. Two requirements keep this allocation-free:

  • Both branches of txIdWords force the All ToTxIdWords ys dictionary (Z reads its head, S its tail), so GHC compiles the tail-dictionary read as a strict field access rather than a per-step thunk.
  • The compared words are unboxed (Word64#), so no hash is boxed on the heap.