Skip to content
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

Add transaction TTL to payments API #2167

Merged
merged 7 commits into from
Oct 29, 2020
Merged

Add transaction TTL to payments API #2167

merged 7 commits into from
Oct 29, 2020

Conversation

rvl
Copy link
Contributor

@rvl rvl commented Sep 23, 2020

Issue Number

ADP-93 / #1840

Overview

  • Add transaction TTL to swagger spec. User provides the value in seconds.
  • Add transaction TTL to API types
  • Add TTL slot calculation to API handler function
  • Adjust mkStdTx to make ttl easier - it now takes the expiry slot directly.
  • Integration tests

Comments

Next PRs

@rvl rvl added the ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG label Sep 23, 2020
@rvl rvl added this to the (ADP-93) Transaction scheduler milestone Sep 23, 2020
@rvl rvl self-assigned this Sep 23, 2020
@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch from 1d6b0e2 to 2e2c62c Compare October 1, 2020 08:40
@rvl rvl changed the title Add transaction TTL to swagger spec Add transaction TTL to payments API Oct 1, 2020
@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch 2 times, most recently from cebf2d3 to f3b251d Compare October 2, 2020 10:57
@rvl rvl changed the base branch from master to rvl/1838/ttl-tx October 2, 2020 10:57
@rvl rvl force-pushed the rvl/1838/ttl-tx branch 4 times, most recently from 0c634ac to c938a0c Compare October 9, 2020 09:22
Base automatically changed from rvl/1838/ttl-tx to master October 9, 2020 19:30
@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch 4 times, most recently from f6fc3bd to 6bb0383 Compare October 13, 2020 06:08
@rvl
Copy link
Contributor Author

rvl commented Oct 13, 2020

bors try

iohk-bors bot added a commit that referenced this pull request Oct 13, 2020
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 13, 2020

try

Build failed:

@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch from 6bb0383 to e4b840e Compare October 13, 2020 06:21
@rvl
Copy link
Contributor Author

rvl commented Oct 13, 2020

Fixed code warning, doh.

bors try

iohk-bors bot added a commit that referenced this pull request Oct 13, 2020
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 13, 2020

try

Build failed:

Need to fix something.

@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch from e4b840e to e8e1e41 Compare October 15, 2020 05:41
lib/core/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Api/Types.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Api/Types.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/DB/Sqlite.hs Show resolved Hide resolved
specifications/api/swagger.yaml Show resolved Hide resolved
specifications/api/swagger.yaml Show resolved Hide resolved
specifications/api/swagger.yaml Outdated Show resolved Hide resolved
@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch from e8e1e41 to 7781555 Compare October 19, 2020 10:42
@rvl rvl force-pushed the rvl/1840/tx-ttl-api branch from 31b9a57 to a736044 Compare October 22, 2020 06:09

-- Expected and actual are fairly close. Any difference should only be
-- due to slot rounding.
slotDiff txExpectedExp txActualExp `shouldSatisfy` (< 50)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about also waiting for the transaction to expire and verify that its state eventually becomes reported as expired?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is testing that a custom transaction expiry works, and then I test expiry and reporting of the tx status in the next test case TRANS_TTL_03.

@@ -43,7 +43,7 @@

module Cardano.Wallet
(
-- * Developement
-- * Development
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2-year old typo, never too late to fix 😅

expTime <- addUTCTime ttl <$> getCurrentTime
try $ ti $ ceilingSlotAt expTime
where
ttl = fromMaybe defaultTTL maybeTTL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} deriving (Eq, Generic, Show)

data PostTransactionFeeData (n :: NetworkDiscriminant) = PostTransactionFeeData
{ payments :: (NonEmpty (AddressAmount (ApiT Address, Proxy n)))
, withdrawal :: !(Maybe ApiWithdrawalPostData)
, metadata :: !(Maybe (ApiT TxMetadata))
, timeToLive :: !(Maybe (Quantity "second" NominalDiffTime))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rvl
Copy link
Contributor Author

rvl commented Oct 26, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Oct 26, 2020
2167: Add transaction TTL to payments API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Add transaction TTL to swagger spec. User provides the value in seconds.
- [x] Add transaction TTL to API types
- [x] Add TTL slot calculation to API handler function
- [x] Adjust mkStdTx to make ttl easier - it now takes the expiry slot directly.
- [x] Integration tests

### Comments

Next PR
- [ ] Add CLI option `cardano-wallet transaction create [--ttl=SECONDS]`
- [ ] Perhaps clean up the large number of function arguments and return values in transaction layer functions.


Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 26, 2020

Timed out.

@rvl
Copy link
Contributor Author

rvl commented Oct 27, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Oct 27, 2020
2167: Add transaction TTL to payments API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Add transaction TTL to swagger spec. User provides the value in seconds.
- [x] Add transaction TTL to API types
- [x] Add TTL slot calculation to API handler function
- [x] Adjust mkStdTx to make ttl easier - it now takes the expiry slot directly.
- [x] Integration tests

### Comments

Next PRs
- [x] Allow deleting expired transactions ⇒ #2262
- [x] Add CLI option `cardano-wallet transaction create [--ttl=SECONDS]` ⇒ #2267
- [ ] Perhaps clean up the large number of function arguments and return values in transaction layer functions.


Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 27, 2020

Build failed:

  src/Test/Integration/Framework/DSL.hs:1486:7:
  1) API Specifications, SHELLEY_TRANSACTIONS, TRANS_TTL_03 - Expired transactions
       expected a successful response but got an error: DecodeFailure "{\"code\":\"created_invalid_transaction\",\"message\":\"That's embarrassing. It looks like I've created an invalid transaction that could not be parsed by the node. Here's an error message that may help with debugging: HardForkApplyTxErrFromEra S (Z (WrapApplyTxErr {unwrapApplyTxErr = ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (ExpiredUTxO (SlotNo 2907) (SlotNo 2908))))]}))\"}"
       While verifying (Status {statusCode = 500, statusMessage = "Internal Server Error"},Left (DecodeFailure "{\"code\":\"created_invalid_transaction\",\"message\":\"That's embarrassing. It looks like I've created an invalid transaction that could not be parsed by the node. Here's an error message that may help with debugging: HardForkApplyTxErrFromEra S (Z (WrapApplyTxErr {unwrapApplyTxErr = ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (ExpiredUTxO (SlotNo 2907) (SlotNo 2908))))]}))\"}"))


-- this transaction is going to expire really soon.
basePayload <- mkTxPayload ctx wb amt fixturePassphrase
let payload = addTxTTL 0.1 basePayload
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this is a bit flaky :s, we should choose a time slightly larger in front of the time slot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes, not good.

The TTL must be small enough that the tx expires before it can get into a block, but large enough that the node allows it into its mempool.

I need another approach to testing this which isn't flaky.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvl a possible approach could be to double-spend? If we make two transactions that are using a common UTxO, both should be "accepted" in the mempool and only one would go through ultimately. Then, we can set a large-enough but still short TTL and simply wait for either one to expire.

So, the test could be:

a) Setup a wallet with a single UTxO
b) Send funds to A with TTL t
c) Forget transaction
d) Send funds to B with TTL t

Yet, this maybe does not test what you intend to test? If we want to check that the transaction is not inserted because it is expired (and not because it is double-spending), then it doesn't work :/

@rvl
Copy link
Contributor Author

rvl commented Oct 28, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Oct 28, 2020
2167: Add transaction TTL to payments API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Add transaction TTL to swagger spec. User provides the value in seconds.
- [x] Add transaction TTL to API types
- [x] Add TTL slot calculation to API handler function
- [x] Adjust mkStdTx to make ttl easier - it now takes the expiry slot directly.
- [x] Integration tests

### Comments

Next PRs
- [x] Allow deleting expired transactions ⇒ #2262
- [x] Add CLI option `cardano-wallet transaction create [--ttl=SECONDS]` ⇒ #2267
- [ ] Perhaps clean up the large number of function arguments and return values in transaction layer functions.


Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 28, 2020

Build failed:

Failures:

  src/Test/Integration/Scenario/API/Shelley/Transactions.hs:1132:18:
  1) API Specifications, SHELLEY_TRANSACTIONS, TRANS_EXTERNAL_02 - Multiple Outputs Transaction - Shelley witnesses
       Waited longer than 90s (more than 2 epochs) to resolve action: "wFaucet and wSrc balances are as expected".
       expected: Quantity {getQuantity = 999989843200}
        but got: Quantity {getQuantity = 999989843000}

  To rerun use: --match "/API Specifications/SHELLEY_TRANSACTIONS/TRANS_EXTERNAL_02 - Multiple Outputs Transaction - Shelley witnesses/"

Randomized with seed 734248806

Finished in 2189.6516 seconds
687 examples, 1 failure, 4 pending

@KtorZ
Copy link
Member

KtorZ commented Oct 29, 2020

bors retry

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 29, 2020

Build succeeded:

@iohk-bors iohk-bors bot merged commit c06c779 into master Oct 29, 2020
@iohk-bors iohk-bors bot deleted the rvl/1840/tx-ttl-api branch October 29, 2020 17:55
iohk-bors bot added a commit that referenced this pull request Nov 2, 2020
2262: Allow deleting expired transactions from the API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Using the existing transaction delete endpoint, also permit removing expired transactions.
- [x] Simplify DB model and state machine tests for this function
- [x] Integration test

### Comments

- Based on PR #2167 branch - merge that first.

2282: Increase bors timeout from 2h to 3h r=Anviking a=Anviking

# Issue Number

#2279 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] Increase bors timeout from 2h to 3h


# Comments

It seems hydra is often slow to schedule/run the jobs, causing ≈18% of bors r+ to fail.

It should be better to increase the timeout to 3h, than to have it fail.

This doesn't affect the timeout of buildkite or hydra themselves.

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
iohk-bors bot added a commit that referenced this pull request Nov 2, 2020
2262: Allow deleting expired transactions from the API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Using the existing transaction delete endpoint, also permit removing expired transactions.
- [x] Simplify DB model and state machine tests for this function
- [x] Integration test

### Comments

- Based on PR #2167 branch - merge that first.

Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this pull request Nov 4, 2020
2262: Allow deleting expired transactions from the API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Using the existing transaction delete endpoint, also permit removing expired transactions.
- [x] Simplify DB model and state machine tests for this function
- [x] Integration test

### Comments

- Based on PR #2167 branch - merge that first.

Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this pull request Nov 6, 2020
2262: Allow deleting expired transactions from the API r=rvl a=rvl

### Issue Number

ADP-93 / #1840

### Overview

- [x] Using the existing transaction delete endpoint, also permit removing expired transactions.
- [x] Simplify DB model and state machine tests for this function
- [x] Integration test

### Comments

- Based on PR #2167 branch - merge that first.

Co-authored-by: Rodney Lorrimar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants