-
Notifications
You must be signed in to change notification settings - Fork 156
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
Babbage: TxBody + TxOut #2560
Conversation
1ef8d19
to
e912f6b
Compare
There was a problem hiding this 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.
There was a problem hiding this 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?
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 |
there is still a maintainership burden but it seems small, I don't really have any strong opinions either way |
afc66c2
to
80e73e4
Compare
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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?
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
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 |
18d2239
to
615e9ce
Compare
615e9ce
to
066c16c
Compare
work for me |
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. |
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 |
…ecs into zachc/babbage
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 |
a128e6f
to
1a6b48b
Compare
toCBOR (TxOutCompactDatum addr cv d) = | ||
encodeListLen 4 | ||
<> toCBOR True | ||
<> toCBOR addr | ||
<> toCBOR cv | ||
<> toCBOR d |
There was a problem hiding this comment.
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
1a6b48b
to
4d2e1d1
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
Co-authored-by: Alexey Kuleshevich <[email protected]>
* 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]>
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