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

Babbage: TxBody + TxOut #2560

Merged
merged 9 commits into from
Jan 4, 2022
Merged

Babbage: TxBody + TxOut #2560

merged 9 commits into from
Jan 4, 2022

Conversation

goolord
Copy link
Contributor

@goolord goolord commented Nov 23, 2021

this is the beginning of the babbage era work so this pr includes all of the necessary changes to build the new era + the TxBody module.

resolves #2465
resolves #2463

nc6
nc6 previously requested changes Nov 24, 2021
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.

Looks reasonable, but I don't see where the burn address has been defined.

@lehins lehins self-requested a review November 24, 2021 18:49
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.

@nc6 I have to disagree with you, it doesn't look reasonable, there is way too much duplicated functionality in this PR.

We need to try and figure out how we can reduce duplication as much as possible. Perfect example why this is important is the fact that definition of TxOut has recently changed as well as many of the helper functions that deal with it. Soon CBOR deserialization will change as well (due to sharing)

Maybe we can approach this problem from a different angle and instead of creating a new TxOut type for babbage we can create a new type family for datums, eg:

type family Datum era :: Type
...
  | TxOutCompactDH
      {-# UNPACK #-} !(CompactAddr (Crypto era))
      !(CompactForm (Core.Value era))
      !(Datum era)

... 
type instance Datum Alonzo = DataHash (Crypto Alonzo)
type instance Datum Babbage = Either (DataHash (Crypto Aonzo)) (Data Babbage)
-- ^ Note that `Either` is just an example, a custom type would be better

or something along those lines. This way we could avoid copying this whole monstrosity.
@goolord , @nc6 , @JaredCorduan Any thoughts on this?

eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
@goolord
Copy link
Contributor Author

goolord commented Nov 24, 2021

more code reuse would be nice. a type family is not like an open union though, don't just end up with the same problem?

we are already reasonably polymorphic over TxOut for each era when destructing using HasField, or in functions like decodeDataHash32 which just accept the parameters of the constructor as arguments. there are other techniques which don't change the semantics of TxOut

@goolord
Copy link
Contributor Author

goolord commented Nov 24, 2021

there is still a maintainership burden but it seems small, I don't really have any strong opinions either way

@goolord goolord force-pushed the zachc/babbage branch 2 times, most recently from afc66c2 to 80e73e4 Compare November 28, 2021 03:23
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.

I think we need a test suite added in this PR that at least checks serialization rountripping. It would have caught most of my comments.

eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
Comment on lines 274 to 322
data TxBodyRaw era = TxBodyRaw
{ _inputs :: !(Set (TxIn (Crypto era))),
_collateral :: !(Set (TxIn (Crypto era))),
_collateralReturn :: !(StrictMaybe (TxOut era)),
_outputs :: !(StrictSeq (TxOut era)),
_certs :: !(StrictSeq (DCert (Crypto era))),
_wdrls :: !(Wdrl (Crypto era)),
_txfee :: !Coin,
_vldt :: !ValidityInterval,
_update :: !(StrictMaybe (Update era)),
_reqSignerHashes :: Set (KeyHash 'Witness (Crypto era)),
_mint :: !(Value (Crypto era)),
-- The spec makes it clear that the mint field is a
-- Cardano.Ledger.Mary.Value.Value, not a Core.Value.
-- Operations on the TxBody in the AlonzoEra depend upon this.
_scriptIntegrityHash :: !(StrictMaybe (ScriptIntegrityHash (Crypto era))),
_adHash :: !(StrictMaybe (AuxiliaryDataHash (Crypto era))),
_txnetworkid :: !(StrictMaybe Network)
}
deriving (Generic, Typeable)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JaredCorduan or @nc6 can you comment on this? I think we could do something like this instead?

Suggested change
data TxBodyRaw era = TxBodyRaw
{ _inputs :: !(Set (TxIn (Crypto era))),
_collateral :: !(Set (TxIn (Crypto era))),
_collateralReturn :: !(StrictMaybe (TxOut era)),
_outputs :: !(StrictSeq (TxOut era)),
_certs :: !(StrictSeq (DCert (Crypto era))),
_wdrls :: !(Wdrl (Crypto era)),
_txfee :: !Coin,
_vldt :: !ValidityInterval,
_update :: !(StrictMaybe (Update era)),
_reqSignerHashes :: Set (KeyHash 'Witness (Crypto era)),
_mint :: !(Value (Crypto era)),
-- The spec makes it clear that the mint field is a
-- Cardano.Ledger.Mary.Value.Value, not a Core.Value.
-- Operations on the TxBody in the AlonzoEra depend upon this.
_scriptIntegrityHash :: !(StrictMaybe (ScriptIntegrityHash (Crypto era))),
_adHash :: !(StrictMaybe (AuxiliaryDataHash (Crypto era))),
_txnetworkid :: !(StrictMaybe Network)
}
deriving (Generic, Typeable)
data TxBodyRaw era = TxBodyRaw
{ txBodyAlonzo :: Alonzo.TxBodyRaw era
, txBodyCollateralReturn :: !(StrictMaybe (TxOut era))
}

This way we could reuse all the serialization/deserialization logic from alonzo. All this copy pasting is hurting my eyes. I will of course not stand in a way if that is how era parameterization was designed to be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm. I like the idea of removing code copy when we can, but it's also weird to switch to this nested format now.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could have the datatype defined like this, and unpack in the patterns.

eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
@goolord
Copy link
Contributor Author

goolord commented Nov 30, 2021

yeah i neglected to introduce the test suite yet since it would be a lot of additional work to do so until the rest of the babbage era stuff is done, but i can add tests gradually

@goolord
Copy link
Contributor Author

goolord commented Dec 1, 2021

ok, adding tests at this point would actually be way more work than i thought. if it's alright i will fix what i can now and revisit the tests / correctness of this module later just to avoid adding way too much to this pr

@JaredCorduan
Copy link
Contributor

ok, adding tests at this point would actually be way more work than i thought. if it's alright i will fix what i can now and revisit the tests / correctness of this module later just to avoid adding way too much to this pr

work for me

@JaredCorduan
Copy link
Contributor

JaredCorduan commented Dec 6, 2021

I think we need a test suite added in this PR that at least checks serialization rountripping. It would have caught most of my comments.

That's a good idea. @goolord I think it would be pretty easy to add a few round trip tests, you can reuse the existing tools, like here in Alonzo: https://github.com/input-output-hk/cardano-ledger/blob/e7b7773655f6f1acc600abd63a3de1c6599c6d98/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Serialisation/Tripping.hs#L70-L104

I'm also fine with adding tests in a follow up PR.

@goolord
Copy link
Contributor Author

goolord commented Dec 22, 2021

ok, i got the whole era working on a branch and the tripping tests passing, i'll push the correct version of this module after I pr some of the related changes i needed to make

@goolord
Copy link
Contributor Author

goolord commented Dec 22, 2021

#2593

@goolord
Copy link
Contributor Author

goolord commented Dec 28, 2021

ok, this is up to date with the latest version of the spec, and has changes from this branch https://github.com/input-output-hk/cardano-ledger/tree/zachc/babbage-big which has the test suite running (+ most of the other babbage changes which i'm goin to port over)

this pr #2593 is necessary for the module to actually be useful

@goolord goolord force-pushed the zachc/babbage branch 3 times, most recently from a128e6f to 1a6b48b Compare December 28, 2021 18:00
Comment on lines +591 to +606
toCBOR (TxOutCompactDatum addr cv d) =
encodeListLen 4
<> toCBOR True
<> toCBOR addr
<> toCBOR cv
<> toCBOR d
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this feels kinda hacky, but putting a break before the encodeListLen makes tests fail

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.

Looks good to me! This has all the new features I was expecting.

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.

LGTM. One minor suggestion.

eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs Outdated Show resolved Hide resolved
@goolord goolord dismissed nc6’s stale review January 4, 2022 18:00

implemented suggestions

@goolord goolord merged commit b37412b into master Jan 4, 2022
@iohk-bors iohk-bors bot deleted the zachc/babbage branch January 4, 2022 18:45
lehins added a commit to lehins/cardano-ledger that referenced this pull request Apr 11, 2022
* add babbage era, TxBody and TxOut

* update collateralReturn

* reuse Alonzo code, update TxOut

* revert pattern synonym change

* WIP

* correct FromCBOR instance

* Update eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs

Co-authored-by: Alexey Kuleshevich <[email protected]>

Co-authored-by: Alexey Kuleshevich <[email protected]>
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.

Babbage TxOut Babbage TxBody
4 participants