-
Notifications
You must be signed in to change notification settings - Fork 214
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
Replace Set TxIn
with [TxIn]
to fix StateMachine.getInput
#594
Conversation
, _citxInputs = txInputs | ||
, _citxInputs = Set.toList txInputs |
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 is incorrect but to fix it we need to fix the Tx
from plutus-core
. Or create our own Tx
with [TxIn]
instead of Set TxIn
.
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.
Can you add a TODO and a story for this? I guess it will need to be done once next-node
is merged in main
.
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.
No need imho, this is good enough.
inputs = | ||
-- We need to sort the inputs as the order is important | ||
-- to find the corresponding redeemers | ||
inputs = sort $ |
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.
Here is the correct order of inputs as we sort cardano-api's TxIn
with an indented Ord
instance.
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 catch, I would have thought they would already be in the right order!
listToMaybe $ mapMaybe Tx.inScripts $ filter (\Tx.TxIn{Tx.txInRef} -> outRef == txInRef) $ Set.toList $ _citxInputs tx | ||
-- We retrieve the correspondent redeemer according to the index of txIn in the list | ||
let findRedeemer (ix, _) = Map.lookup (Tx.RedeemerPtr Tx.Spend ix) (_citxRedeemers tx) | ||
Ledger.Redeemer r <- listToMaybe $ mapMaybe findRedeemer $ filter (\(_, Tx.TxIn{Tx.txInRef}) -> outRef == txInRef) $ zip [0..] $ _citxInputs tx |
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.
Here is where we use the knowledge of inputs order to get the redeemer. I hope I got the idea correctly that index of TxIn
is binded to the redeemer pointer.
Source: IntersectMBO/cardano-node#3389 (comment)
Maybe instead of relying on their order it's better to include the index. Set TxIn ~> Set (TxInIndx, TxIn)
, that would make it more explicit.
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 fact that we now have a list instead of a set makes it clear enough that the order is significant in my opinion.
where | ||
withHash (ConsumeScriptAddress val red dat) = | ||
-- TODO: the index of the txin is probably incorrect as we take it from the set. |
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.
Is this going to have bad consequences?
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.
My understanding is that this PR makes a move from a completely broken state to a semi-broken state. Instead of not getting redeemers at all, we will start choosing them but with a big chance of selecting the incorrect ones.
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.
Speaking of fromOnChainTx
in particular, I think withHash
function was useless already since we use the Tx
here, and the inputs have an empty TxInType
here as I understand. And we might skip the ConsumeScriptAddress
case at all always return mempty
.
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.
As long as the redeemer pointer points to the right input, I think this is totally fine.
To show that there is a relation between the list and the indexes, I think it's better to do the Set.toList
once and pass the list to validators
.
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.
As long as the redeemer pointer points to the right input, I think this is totally fine.
There is a problem here that we take a set that could break the order. I looked at usages of the fromOnChainTx
and there is no anything that directly relies on that order. But would be nice to fix Tx
type.
where | ||
withHash (ConsumeScriptAddress val red dat) = | ||
-- TODO: the index of the txin is probably incorrect as we take it from the set. |
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.
As long as the redeemer pointer points to the right input, I think this is totally fine.
To show that there is a relation between the list and the indexes, I think it's better to do the Set.toList
once and pass the list to validators
.
inputs = | ||
-- We need to sort the inputs as the order is important | ||
-- to find the corresponding redeemers | ||
inputs = sort $ |
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 catch, I would have thought they would already be in the right order!
listToMaybe $ mapMaybe Tx.inScripts $ filter (\Tx.TxIn{Tx.txInRef} -> outRef == txInRef) $ Set.toList $ _citxInputs tx | ||
-- We retrieve the correspondent redeemer according to the index of txIn in the list | ||
let findRedeemer (ix, _) = Map.lookup (Tx.RedeemerPtr Tx.Spend ix) (_citxRedeemers tx) | ||
Ledger.Redeemer r <- listToMaybe $ mapMaybe findRedeemer $ filter (\(_, Tx.TxIn{Tx.txInRef}) -> outRef == txInRef) $ zip [0..] $ _citxInputs tx |
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 fact that we now have a list instead of a set makes it clear enough that the order is significant in my opinion.
This PR tries to fix the problem with
StateMachine.getInput
by properly querying the redeemer of the input by its index.Pre-submit checklist: