-
Notifications
You must be signed in to change notification settings - Fork 10
Add support for AwaitTxStatusChangeReq contract request #83
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
Conversation
fa8003e to
0d871e4
Compare
test/Spec/MockContract.hs
Outdated
| case drop 1 $ dropWhile (/= "--out-file") args of | ||
| filepath : _ -> | ||
| modify @(MockContractState w) (files . at (Text.unpack filepath) ?~ OtherFile "TxBody") | ||
| modify @(MockContractState w) (files . at (Text.unpack filepath) ?~ _) |
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.
Tests are currently failing as we didn't previously care for the contents of these files but now we want to read them back to return the 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.
@gege251 do you have any idea what the best solution for this could be? Atm mockReadFileTextEnvelope fails because these are stored as OtherFile but to store them as TextEnvelopeFiles I need to serialise an actual tx into it
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.
A bit hacky idea, but what if we would create a new TxFile constructor for MockFile, and use that in the pattern match in mockReadFileTextEnvelope, and return some dummy CardanoTx with some random id (I think, we don't need it to be correct at this point).
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 might be easier said that done.
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.
src/BotPlutusInterface/Contract.hs
Outdated
| , "Signatories (pkh): " <> Text.unwords (map pkhToText requiredSigners) | ||
| ] | ||
|
|
||
| let ext = if signable then "signed" else "raw" |
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 even correct? Seems to be the case from the tests but I am not sure we will always have one of the two files
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.
"raw" must be there in each case, "signed" is only available, if we have all the necessarry signing keys to sign the tx. I think this works.
Finish without sign and submit behaviour is not exactly ideal, and we had a few discussions about this with Sam, but didn't really have time to improve it unfortunately...
[nits] It's not at all important, but I think we could move this part (reading the actual tx and txId from file and changing the filenames) between the build and sign steps, so we don't have to do all these conditionals.
Change-type: minor Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
0d871e4 to
d2e3e87
Compare
samuelWilliams99
left a comment
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 way we're handling this doesn't give a safe path back to regular execution if a tx doesn't make it.
We need to return a non valid tx response if we don't ever see the transaction on the index, or if it gets rolled back, otherwise we can't really handle failure here.
The question of how long to wait before assuming a tx didn't land is an annoying one, as we cant be fully sure unless we enforce a validity range on a tx.
So, in this case, lets do that.
If the tx has a validity range, and we shoot past it without seeing it in the block, return out. otherwise, have some hard coded long delay before assuming failure.
Almost fix tests with a hacky solution
|
@samuelWilliams99 I added a timeout of 5 blocks after which the the status is reported as |
7768b6c to
342f7a2
Compare
…the Tx does not show up in chain-index after a set number of blocks (currently 5) Change-type: patch Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
342f7a2 to
fd77f79
Compare
|
I interval thing was a way of knowing definitively if we've waited enough. With our current solution, we're assuming all txs will land within some time frame, but if we use validity interval, we know theres a point at which a tx MUST have failed, and isn't just caught up in traffic |
…-index response to the contract Change-type: patch Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
samuelWilliams99
left a comment
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.
since the txId was wrong, does this mean that the new txid we'll get back from submitting a transaction won't work with the raw tx endpoint?
src/BotPlutusInterface/Helpers.hs
Outdated
| Unknown -> do | ||
| curSlot <- currentSlot | ||
| if curSlot >= maxSlot | ||
| then throwError @e $ review _OtherContractError $ pack $ "Could not find tx after maxAttempts. ID: " ++ show i |
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 isn't really max attempts anymore, so this error is misleading
src/BotPlutusInterface/Helpers.hs
Outdated
| import Prelude | ||
|
|
||
| awaitTxConfirmedUntilSlot :: forall w s e. (AsContractError e) => TxId -> Slot -> Contract w s e () | ||
| awaitTxConfirmedUntilSlot i maxSlot = go 0 |
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.
not a fan of i, as thats usually a loop integer. perhaps txId or something
src/BotPlutusInterface/Helpers.hs
Outdated
| case mTx of | ||
| Unknown -> do | ||
| curSlot <- currentSlot | ||
| if curSlot >= maxSlot |
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.
lets have maxslot as inclusive, as thats what maximum implies, so switch this to a >
| -- pure $ TxIdResponse Nothing | ||
| throwError @Text "TxFromTxId is unimplemented" | ||
| TxFromTxId txId -> do | ||
| -- TODO: Track some kind of state here, add tests to ensure this works correctly |
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.
Get a ticket for this if one doesnt already exist
a968353 to
0eb5051
Compare
0eb5051 to
bd6421f
Compare
… tx id Change-type: minor Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Unfortunately you are correct. I added an extra commit that renames the files with the correct tx id... but it feels wrong :P |
szg251
left a comment
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 only had a few nits to comment, looks good to me!
| txOutRefToCliArg :: TxOutRef -> Text | ||
| txOutRefToCliArg (TxOutRef (TxId txId) txIx) = | ||
| encodeByteString (fromBuiltin txId) <> "#" <> showText txIx | ||
| txOutRefToCliArg (TxOutRef (TxId tId) txIx) = |
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.
[nits] I think there's a typo here
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.
Had to rename that because we are importing txId from Ledger.Tx
src/BotPlutusInterface/Contract.hs
Outdated
| , "Signatories (pkh): " <> Text.unwords (map pkhToText requiredSigners) | ||
| ] | ||
|
|
||
| let ext = if signable then "signed" else "raw" |
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.
"raw" must be there in each case, "signed" is only available, if we have all the necessarry signing keys to sign the tx. I think this works.
Finish without sign and submit behaviour is not exactly ideal, and we had a few discussions about this with Sam, but didn't really have time to improve it unfortunately...
[nits] It's not at all important, but I think we could move this part (reading the actual tx and txId from file and changing the filenames) between the build and sign steps, so we don't have to do all these conditionals.
| submitTx constraints | ||
|
|
||
| assertContractWithTxId contract initState $ \state outTxId -> | ||
| assertContractWithTxId contract initState $ \state _ -> |
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.
[nits] We don't need to use assertContractWithTxId anymore, this could be replaced with a simple runContractPure
| Constraints.mustPayToPubKey paymentPkh2 (Ada.lovelaceValueOf 1000) | ||
| txId <- submitTx constraints | ||
| tell $ Last $ Just $ Text.pack $ show $ Tx.txId <$> txId | ||
| tell $ Last $ Just test |
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.
[nits] The purpose of returning the txId was to prove that we can return values from the contract, but I think it is not really important to include in this test case.
We could just assert that the value in the observable state is "Init contract".
Change-type: patch Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Change-type: patch Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Change-type: patch Signed-off-by: Giovanni Garufi <giovanni@mlabs.city>
Change-type: minor
Signed-off-by: Giovanni Garufi giovanni@mlabs.city