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

Fix Input resolution for inputs only present in db #1685

Merged
merged 6 commits into from
May 26, 2020

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented May 25, 2020

Issue Number

#1670

Overview

  • 1502136
    📍 add regression test illustrating the issue
    Input that should be resolved aren't. In order to resolve inputs, we are actually wrongly using
    the transactions available from the history that was fetched from the database, instead of using
    the entire database! So, giving different query parameters restricting the set of outputs has an
    influence on something it shouldn't.

  • 8ec0123
    📍 resolve transaction inputs from db when fetching the history
    Before, this was done in the application layer, from the available history ('assemble' in 'Cardano.Wallet'). This requires exactly two extra lookups. One in the TxOut table, and one in the Checkpoint table so the performance impact should be quite small. It simplifies the application logic quite a bit and doesn't much impact the database logic, so it's almost a win-win. Plus, it fixes the issue where resolvable inputs would appear as non resolved

  • 64bf4db
    📍 fix DB model to also return full 'TransactionInfo' when fetching the tx history

  • 21d75d2
    📍 Fix db benchmark build
    Benchmarks may produce higher timings after this change, but it's OK
    since the answers are more correct now, and the work has just shifted
    from the wallet layer into the db layer.

  • fffe476
    📍 re-add lost comment about input resolution for incoming/outgoing transactions

  • 67adc07
    📍 rename 'txs' -> 'pending' to better match context

Comments

@KtorZ KtorZ requested a review from rvl May 25, 2020 17:22
@KtorZ KtorZ self-assigned this May 25, 2020
)
=> (Context t -> [Natural] -> IO ApiByronWallet)
-> SpecWith (Context t)
scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do
Copy link
Member Author

Choose a reason for hiding this comment

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

This fails before the fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the tx input resolving is moved into the DBLayer, this test could probably be more easily done at the unit level.

-- to assemble coin selection information for outgoing payments.
-- To reliably provide this information, it should be looked up when
-- applying blocks, but that is future work (issue #573).
assemble
Copy link
Member Author

Choose a reason for hiding this comment

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

no longer needed, the db now returns [TransactionInfo] directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it still noted somewhere that coin selection information can't (yet) be provided for outgoing payments?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've rewritten the comment and linked to the github issue in the relevant place in the db layer 👍 , good point

Copy link
Contributor

@rvl rvl left a comment

Choose a reason for hiding this comment

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

LGTM

)
=> (Context t -> [Natural] -> IO ApiByronWallet)
-> SpecWith (Context t)
scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the tx input resolving is moved into the DBLayer, this test could probably be more easily done at the unit level.

lib/core/src/Cardano/Wallet/DB/Sqlite.hs Show resolved Hide resolved
lib/core/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
-- to assemble coin selection information for outgoing payments.
-- To reliably provide this information, it should be looked up when
-- applying blocks, but that is future work (issue #573).
assemble
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it still noted somewhere that coin selection information can't (yet) be provided for outgoing payments?

@KtorZ KtorZ added the RESOLVING ISSUE Mark a PR as resolving issues, for auto-generated CHANGELOG label May 26, 2020
@KtorZ
Copy link
Member Author

KtorZ commented May 26, 2020

bors r+

@KtorZ
Copy link
Member Author

KtorZ commented May 26, 2020

bors r-

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 26, 2020

Canceled

@KtorZ
Copy link
Member Author

KtorZ commented May 26, 2020

Whoops. I failed to push because there was a change upstream I didn't see. Rebasing and pushing.

@KtorZ KtorZ force-pushed the KtorZ/1670/input-resolution-fix branch from ad7f8f9 to 67adc07 Compare May 26, 2020 09:44
@KtorZ
Copy link
Member Author

KtorZ commented May 26, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request May 26, 2020
1685: Fix Input resolution for inputs only present in db r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1670

# Overview

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

- 1502136
  📍 **add regression test illustrating the issue**
  Input that should be resolved aren't. In order to resolve inputs, we are actually wrongly using
the transactions available from the history that was fetched from the database, instead of using
the entire database! So, giving different query parameters restricting the set of outputs has an
influence on something it shouldn't.

- 8ec0123
  📍 **resolve transaction inputs from db when fetching the history**
  Before, this was done in the application layer, from the available history ('assemble' in 'Cardano.Wallet'). This requires exactly two extra lookups. One in the TxOut table, and one in the Checkpoint table so the performance impact should be quite small. It simplifies the application logic quite a bit and doesn't much impact the database logic, so it's almost a win-win. Plus, it fixes the issue where resolvable inputs would appear as non resolved

- 64bf4db
  📍 **fix DB model to also return full 'TransactionInfo' when fetching the tx history**
  
- 21d75d2
  📍 **Fix db benchmark build**
  Benchmarks may produce higher timings after this change, but it's OK
since the answers are more correct now, and the work has just shifted
from the wallet layer into the db layer.

- fffe476
  📍 **re-add lost comment about input resolution for incoming/outgoing transactions**
  
- 67adc07
  📍 **rename 'txs' -> 'pending' to better match context**


# Comments

<!-- 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: KtorZ <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 26, 2020

Build failed

KtorZ and others added 6 commits May 26, 2020 13:48
Input that should be resolved aren't. In order to resolve inputs, we are actually wrongly using
the transactions available from the history that was fetched from the database, instead of using
the entire database! So, giving different query parameters restricting the set of outputs has an
influence on something it shouldn't.
Before, this was done in the application layer, from the available history ('assemble' in 'Cardano.Wallet'). This requires exactly two extra lookups. One in the TxOut table, and one in the Checkpoint table so the performance impact should be quite small. It simplifies the application logic quite a bit and doesn't much impact the database logic, so it's almost a win-win. Plus, it fixes the issue where resolvable inputs would appear as non resolved
Benchmarks may produce higher timings after this change, but it's OK
since the answers are more correct now, and the work has just shifted
from the wallet layer into the db layer.
@KtorZ KtorZ force-pushed the KtorZ/1670/input-resolution-fix branch from 67adc07 to 7c085f9 Compare May 26, 2020 11:49
@KtorZ
Copy link
Member Author

KtorZ commented May 26, 2020

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 26, 2020

@iohk-bors iohk-bors bot merged commit ff0c8eb into master May 26, 2020
@iohk-bors iohk-bors bot deleted the KtorZ/1670/input-resolution-fix branch May 26, 2020 12:42
iohk-bors bot added a commit that referenced this pull request May 27, 2020
1696: sql: Fix input resolution when number of inputs is large r=KtorZ a=rvl

### Issue Number

#1670 / #1685

### Overview

The "too many SQL variables" problem strikes again in the nightly benchmark.

One way to fix it is to do a SQL join or subquery.

Another way to fix it (this PR) is to make the select query in chunks.

### Comments

Tested with:

    cabal run cardano-wallet-core:bench:db  -- --match prefix "TxHistory (Read)/1000"

or

    stack bench cardano-wallet-core:bench:db --ba '--match prefix "TxHistory (Read)/1000"'


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
RESOLVING ISSUE Mark a PR as resolving issues, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants