-
Notifications
You must be signed in to change notification settings - Fork 721
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
Make TxBodyContent an instance of Monoid #4458
Conversation
4ecda34
to
9977a6d
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.
Looking good but with one comment
instance Semigroup (TxValidityLowerBound era) where | ||
TxValidityNoLowerBound <> x = x | ||
x <> TxValidityNoLowerBound = x | ||
(TxValidityLowerBound wit l) <> (TxValidityLowerBound _ r) = TxValidityLowerBound wit (max l r) |
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 disagree with using max
here. SlotNo
has a Num
instance, I think we should add the values together with (+)
. That way a user can adjust the validity lower bound as they see fit, with positive or negative values.
This PR is stale because it has been open 45 days with no activity. |
@LudvikGalois Is @Jimbo4350's comment the only thing preventing from merging this PR? |
@koslambrou I think so? I haven't come back to this because the reason I wanted it disappeared. |
@LudvikGalois Do you want to continue the PR or should I take over? |
TxBodyContent is now an instance of Monoid, allowing things like ```haskell foo :: TxBodyContent BuildTx BabbageEra foo = mempty { txValidityRange = someValidityRange } bar :: TxBodyContent BuildTx BabbageEra bar = mempty { txIns = someTxIns, txOuts = someTxOuts } baz :: TxBodyContent BuildTx BabbageEra baz = mempty { txOuts = someMoreTxOuts } transaction :: TxBodyContent BuildTx BabbageEra transaction = mconcat [foo, bar, baz] ```
instance Semigroup (TxValidityLowerBound era) where | ||
TxValidityNoLowerBound <> x = x | ||
x <> TxValidityNoLowerBound = x | ||
(TxValidityLowerBound wit l) <> (TxValidityLowerBound _ r) = TxValidityLowerBound wit (max l r) |
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.
The thing that bothers me is we throw away the witness on the RHS of <>
. Is this safe to do?
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.
Oh it's a type witness. Maybe it's okay?
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.
It is safe to do for all the "feature supported in era" type witnesses. For any given era, they have at most one non-bottom value, so it doesn't matter "which one" you pick.
…pperBoundSupportedInEra and ValidityLowerBoundSupportedInEra
9977a6d
to
28f43b0
Compare
@@ -13,6 +13,7 @@ | |||
{-# LANGUAGE StandaloneDeriving #-} | |||
{-# LANGUAGE TypeApplications #-} | |||
{-# LANGUAGE TypeFamilies #-} | |||
{-# LANGUAGE UndecidableInstances #-} |
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 can remove the UndecidableInstances pragma with:
instance IsCardanoEra era => Monoid (TxBodyContent ViewTx era) where
mempty = TxBodyContent
{ txIns = mempty
, txInsCollateral = mempty
, txInsReference = mempty
, txOuts = mempty
, txTotalCollateral = mempty
, txReturnCollateral = TxReturnCollateralNone
, txFee = mempty
, txValidityRange = (mempty, mempty)
, txMetadata = mempty
, txAuxScripts = mempty
, txExtraKeyWits = mempty
, txProtocolParams = Nothing <$ (mempty :: BuildTxWith ViewTx ())
, txWithdrawals = mempty
, txCertificates = mempty
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = mempty
, txScriptValidity = mempty
}
instance IsCardanoEra era => Monoid (TxBodyContent BuildTx era) where
mempty = TxBodyContent
{ txIns = mempty
, txInsCollateral = mempty
, txInsReference = mempty
, txOuts = mempty
, txTotalCollateral = mempty
, txReturnCollateral = TxReturnCollateralNone
, txFee = mempty
, txValidityRange = (mempty, mempty)
, txMetadata = mempty
, txAuxScripts = mempty
, txExtraKeyWits = mempty
, txProtocolParams = Nothing <$ (mempty :: BuildTxWith BuildTx ())
, txWithdrawals = mempty
, txCertificates = mempty
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = mempty
, txScriptValidity = mempty
}
Hmm, this actually doesn't work. For example when I try to rewrite
I get the error:
|
Closing this PR in favour of some other strategy. Ongoing work will be tracked by #4941 |
instance IsCardanoEra era => Monoid (TxValidityUpperBound era) where | ||
mempty = case cardanoEra @era of | ||
ByronEra -> TxValidityNoUpperBound ValidityNoUpperBoundInByronEra | ||
ShelleyEra -> TxValidityUpperBound ValidityUpperBoundInShelleyEra maxBound |
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.
ShelleyEra -> TxValidityUpperBound ValidityUpperBoundInShelleyEra maxBound
Was this how it was in the original code?
Why is Shelly era special that it should use maxBound
?
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.
-- Note that the 'ShelleyEra' /does not support/ omitting a validity upper
-- bound. It was introduced as a /required/ field in Shelley and then made
-- optional in Allegra and subsequent eras.
--
-- The Byron era supports this by virtue of the fact that it does not support
-- validity ranges at all.
TxBodyContent is now an instance of Monoid, allowing things like