-
Notifications
You must be signed in to change notification settings - Fork 23
Allow providing of actual datum for reference inputs #814
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
Allow providing of actual datum for reference inputs #814
Conversation
65eb490
to
9803983
Compare
1c26f76
to
1bd923a
Compare
ee95c60
to
90f24cb
Compare
90f24cb
to
26567cf
Compare
26567cf
to
0ff447b
Compare
0ff447b
to
481f365
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.
LGTM 👍 . Get input from the ledger team regarding naming and we can finalize that aspect.
TxInsReference | ||
:: BabbageEraOnwards era | ||
-> [TxIn] | ||
-> TxInsReference era | ||
-- ^ A list of reference inputs | ||
-> TxInsReferenceActualDatums build |
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.
TxInsReferenceAdditionalDatums
? Can you run this by the ledger team. We should also get their input, it would be useful.
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.
How about TxInsReferenceResolvedDatums
?
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.
Thanks a lot for implementing this ! I believe this feature, while somewhat a corner case, is very important to have.
In terms of the actual implementation, I have two general comments / remarks on top of the small comments I left here and there
-
I wonder why these additional datums are given as a set directly inside
TxInsReference
instead of input by input. This breaks the link as to which input is supposed to bear which datum hash. In other words, why not couple eachTxIn
with aMaybe HashableScriptData
in a structure (let's call itRefInputWithDatum
) and haveTxInsReference
take a list of those? -
About the need of providing a
UTxO
here and there. I understand the need for this structure. It allows to ensure that the provided datums do indeed correspond to the resolved variants of hashed datums in reference inputs. However, this will be caught later on in the pipeline anyway as the ledger with throw an error when they do not. So is this necessary to ensure this here? Admittedly, I don't have a full picture as to which properties need to be satisfied bycreateTransactionBody
and are expected to hold by the caller. However, it makes the implementation more involved, and also forces the caller to build this UTxO and understand that it corresponds to the corner case of providing resolved datums to reference inputs. Additionally, since the current implementation seems to just ignore datums that do not correspond to hashed datums in ref inputs, there is no clear way to bypass this requirement for testing purposes. And I believe this is dangerous that this process is silent. This makes me wonder if there are other places in the code base where silent discards are performed.
TxInsReference | ||
:: BabbageEraOnwards era | ||
-> [TxIn] | ||
-> TxInsReference era | ||
-- ^ A list of reference inputs | ||
-> TxInsReferenceActualDatums build |
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.
How about TxInsReferenceResolvedDatums
?
:: Applicative (BuildTxWith build) | ||
=> IsBabbageBasedEra era | ||
=> TxIn | ||
-> TxBodyContent build era | ||
-> TxBodyContent build era |
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 seems weird that addTxInsReference
allows to provide the full datums for the given list of TxIn
while addTxInReference
does not for its own TxIn
. I would expect to have an additional argument of type Maybe HashableScriptData
.
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.
Good point, added, thanks.
[ d | ||
| TxInsReference _ txIns datumSet <- [txInsRef] | ||
, let datumMap = getReferenceInputDatumMap datumSet | ||
, txIn <- txIns | ||
, -- resolve only hashes | ||
TxOut _ _ (TxOutDatumHash _ datumHash) _ <- maybeToList $ UTxO.lookup txIn utxo | ||
, d <- maybeToList $ Map.lookup datumHash datumMap |
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 seems that this will silently ignore datums that do not correspond to hashed datums in the reference inputs. Is there any way to make this visible? Are there other places where such elements are ignored under the hood?
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Autobalance.hs
Outdated
Show resolved
Hide resolved
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Autobalance.hs
Outdated
Show resolved
Hide resolved
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Autobalance.hs
Outdated
Show resolved
Hide resolved
@mmontin Good remarks thanks! ad 2. I agree. Passing UTXO around mostly gets in the way, without any real benefit here. I think we could skip it, ditch the filtering and do the validation at transaction submission step (by ledger). ad 1. Assuming we remove the necessity of passing UTXO: tying TxInsReference
:: BabbageEraOnwards era
-> [( TxIn
, BuildTx build (Maybe HashableScriptData)
)
]
-> TxInsReference build era which would complicate handling of the type a bit: the values would have to be |
About location of datums in the body. Your point makes sense, it would be unwise to complicate the type for no valid reason. And to be honest, the current version where the datum are grouped into a set would be suitable enough for my use case and overall satisfactory, in my opinion. However, I see 2 reasons why the other option also makes sense, based on my current understanding of cardano-api and my current biases as to how I use it in
I am definitely not advocating for such a change, just pointing out that the choice was made to have these supplemental datums be handled within each
I feel like this second point is not quite as strong as I thought when I decided to write it, because it's mostly just based on a feeling, and I leave it to you to take it into account or not. Regardless, I hope these points are of help in making the final decision. |
fbe82fd
to
481f365
Compare
What would be the purpose? You would lose the connection as soon as you construct a valid transaction.
I agree with this regarding removing the |
I see your point but the I wouldn't include the "resolved datums' in the |
481f365
to
e997263
Compare
Changelog
Context
This PR adds a method of adding actual datum for the datum hashes present in reference inputs.
Tested in:
Integrated in CLI:
Closes #803
Checklist