| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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
- class ToTxIdWords blk where
- compareCardanoGenTxId ∷ ∀ (xs ∷ [Type]). All ToTxIdWords xs ⇒ NS WrapGenTxId xs → NS WrapGenTxId xs → Ordering
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.
Instances
| ToTxIdWords ByronBlock Source # | |
Defined in Ouroboros.Consensus.Cardano.CanHardFork.OptimizedTxIdComparison Methods toTxIdWords ∷ GenTxId ByronBlock → (# Word64#, Word64#, Word64#, Word64# #) Source # | |
| ShelleyBasedEra era ⇒ ToTxIdWords (ShelleyBlock proto era) Source # | |
Defined in Ouroboros.Consensus.Cardano.CanHardFork.OptimizedTxIdComparison Methods toTxIdWords ∷ GenTxId (ShelleyBlock proto era) → (# Word64#, Word64#, Word64#, Word64# #) Source # | |
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
txIdWordsforce theAll ToTxIdWords ysdictionary (Zreads its head,Sits 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.