Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create TxIx that is backed by Word16 instead of an Int #2637

Merged
merged 4 commits into from
Feb 3, 2022

Conversation

lehins
Copy link
Collaborator

@lehins lehins commented Jan 27, 2022

Majority of the changes in this PR are to test suites, but the juice of it is in the Cardano.Ledger.Credentials module:

  • Introduction of TxIx for type safety and memory optimization
  • Introduction of CertIx for type safety and memory optimization
  • Collapsing Ptr into a Word64, since we can assume that SlotNo isn't going to reach 2^32 - 1 value any time soon and other members of Ptr were switched to Word16 in the steps above.

Left notes for future generations about the limits, hopefully they won't miss them.

Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -17,7 +17,7 @@ transaction =
, auxiliary_data / null
]

transaction_index = uint
transaction_index = uint .size 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@nc6 nc6 left a comment

Choose a reason for hiding this comment

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

Left some very minor comments, otherwise this looks great!

. C.newStakeCred Cast.aliceSHK (Ptr (SlotNo 10) 0 0)
. C.newStakeCred Cast.bobSHK (Ptr (SlotNo 10) 0 1)
. C.newStakeCred Cast.carlSHK (Ptr (SlotNo 10) 0 2)
. C.newStakeCred Cast.aliceSHK (Ptr (SlotNo 10) minBound (mkCertIxPartial 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

The inconsistent use of minBound vs mkCertIxPartial 0 niggles at me, but is really irrelevant :-D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lol. 😄 I had the same thought when I was writing it, but decided to force myself to ignore it as irrelevant.

libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs Outdated Show resolved Hide resolved
deriving (Show, Eq, Ord, Generic, NFData, NoThunks)
deriving (ToCBOR, FromCBOR) via CBORGroup Ptr

-- | With this pattern synonym we assume that SlotNo increment rate isn't going
-- to speed up in the near future because with current rate we should be fine
-- for a few hundred years.
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be inclined to expand upon this (how you're packing the slot and indices into a Word64, thus leaving only Word32 space for the slot)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Very good suggestion. I expended on the compacting logic

@JaredCorduan
Copy link
Contributor

Still LGTM!

@lehins lehins merged commit 2cd340c into master Feb 3, 2022
@iohk-bors iohk-bors bot deleted the lehins/add-txix branch February 3, 2022 20:17
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