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

Re-write balanceTransaction using Node.evaluateTransactionBalance #3100

Merged
merged 24 commits into from
Mar 23, 2022

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented Jan 27, 2022

  • Rewrite balanceTransaction using evaluateTransactionBalance
    • Effects on goldens can be viewed in the diff of this PR
  • Enable prop_balanceTransactionBalanced
  • Polish
  • Even more polish
    • Will look through from top to bottom before merging

Future work

  • Pay surplus as excess fee when we cannot afford a change-output. (Would like to do while comparing constructTx with balanceTx)
  • Ensure tx size limit is respected (Requires fixing ADP-1484 and this )

Comments

First part introducing goldens and the evaluateTransactionBalance function: #3150

Issue Number

ADP-1372

@Anviking Anviking self-assigned this Jan 27, 2022
@Anviking Anviking force-pushed the anviking/ADP-1372/rewrite-balanceTx branch 3 times, most recently from 97084f0 to 80fa40c Compare February 3, 2022 19:17
@Anviking Anviking changed the title Re-write balanceTransaction using Node.evaluateTransactinoBalance Re-write balanceTransaction using Node.evaluateTransactionBalance Feb 7, 2022
@Anviking Anviking force-pushed the anviking/ADP-1372/rewrite-balanceTx branch 5 times, most recently from 9ca963a to f8ba97c Compare February 17, 2022 16:10
@Anviking
Copy link
Member Author

bors try

iohk-bors bot added a commit that referenced this pull request Feb 17, 2022
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 17, 2022

try

Build failed:

@Anviking Anviking force-pushed the anviking/ADP-1372/rewrite-balanceTx branch 2 times, most recently from bafe8cd to 416c120 Compare February 21, 2022 18:00
@Anviking
Copy link
Member Author

bors try

iohk-bors bot added a commit that referenced this pull request Feb 21, 2022
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 21, 2022

try

Build succeeded:

@Anviking Anviking force-pushed the anviking/ADP-1372/rewrite-balanceTx branch 3 times, most recently from ca83c55 to 0c470e1 Compare February 22, 2022 17:07
@Anviking Anviking force-pushed the anviking/ADP-1372/rewrite-balanceTx branch from 0c470e1 to 6f9a10c Compare February 22, 2022 21:26
iohk-bors bot added a commit that referenced this pull request Feb 25, 2022
3150: Prepare for rewriting balanceTransaction r=Anviking a=Anviking

- [x] Add `evaluateTransactionBalance` to `TransactionLayer`
     - [x] Add `guardTxBalanced` to `balanceTransaction` 
     - Tested indirectly by the fact that `guardTxBalanced` doesn't fail in our existing integration and unit tests.
- [x] Add golden tests for `balanceTransaction` to ensure there are no regressions in #3100 

### Comments

Preparation for #3100 

### Issue Number

<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


ADP-1372


Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
@Anviking Anviking force-pushed the anviking/ADP-1372/rewrite-balanceTx branch 3 times, most recently from 403fba6 to ae8a220 Compare March 1, 2022 13:12
@Anviking
Copy link
Member Author

Anviking commented Mar 1, 2022

bors try

iohk-bors bot added a commit that referenced this pull request Mar 1, 2022
@Anviking Anviking marked this pull request as ready for review March 1, 2022 13:15
Anviking and others added 17 commits March 23, 2022 02:39
If `SelectionStrategyOptimal` results in the tx max size being exceeded,
try again with `SelectionStrategyMinimal`.
- Rename the property to make it clear that it checks more things than
just whether the result is balanced.

- make the feeExcess expectation better motivated.

- polish a few other old comments
- Use 4-space indents everywhere.
- Avoid vertical alignment.
- Ensure that case expressions and pattern guards are indented one level to
  the left of their handlers.
These were introduced in a prior PR, but we might as well clean them up
while we're adjusting this function.

https://input-output-hk.github.io/adrestia/code/Coding-Standards#limit-line-length-to-80-characters
@jonathanknowles jonathanknowles force-pushed the anviking/ADP-1372/rewrite-balanceTx branch from 1138a59 to df3c9ba Compare March 23, 2022 03:22
-- 'assignScriptRedeemers'. This should make the problem (1) unlikely,
-- but not necessarily impossible.
--
-- We should investigate and make sure to handle this better.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

transform

lift $ traceWith tr $ MsgSelectionForBalancingStart
(CS.toExternalUTxOMap $ UTxOIndex.toMap internalUtxoAvailable)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this conversion can be avoided if we don't require ourselves to include a UTxO value in the MsgSelectionForBalancingStart value, since we only ever care about the size, which is the same before and after applying toExternalUTxOMap.

I'll push a commit that removes this conversion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in 80f346c.

When recording details about the UTxO set in the log, we generally only
care about the size of the UTxO set, rather than its composition.

Therefore, we don't need to require ourselves to produce a value of type
`UTxO` in order to create a log entry: we just need to obtain the size
of the available UTxO set.

Therefore, we can avoid converting from the coin selection's internal
map of UTxO entries to values of the wallet's `UTxO` type, which
requires traversing the entire UTxO set and converting every single
entry.

We can't avoid traversing the wallet's UTxO set at least once, in order
to make a value of type `UTxOIndex`, but we can avoid doing it multiple
times.
…lue`.

This allows us to replace the pattern guard and the unsafe conversion
with a single checked conversion.
@jonathanknowles jonathanknowles force-pushed the anviking/ADP-1372/rewrite-balanceTx branch from 60fcb27 to 0b57295 Compare March 23, 2022 04:27
@jonathanknowles jonathanknowles self-requested a review March 23, 2022 04:28
Copy link
Contributor

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me. I see that you've highlighted all areas for further work with TODO comments and links to tickets, which is great.

Thanks for making this PR!

👍🏻

@jonathanknowles
Copy link
Contributor

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 23, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 3bf427b into master Mar 23, 2022
@iohk-bors iohk-bors bot deleted the anviking/ADP-1372/rewrite-balanceTx branch March 23, 2022 06:27
WilliamKingNoel-Bot pushed a commit that referenced this pull request Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants