-
Notifications
You must be signed in to change notification settings - Fork 217
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
Prepare for rewriting balanceTransaction #3150
Conversation
e3e4962
to
37f8a0c
Compare
errBadEra = error $ unwords | ||
[ "evaluateTransactionBalance:" | ||
, "cannot add a datum hash to the transaction body of an" | ||
, "era which doesn't support datum hashes." | ||
] |
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 thought I'd address these, but TBH, because there probably are higher priority problems, it might actually make sense to leave these for now...
bors try |
tryBuild succeeded: |
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.
Hi @Anviking
Thanks for making this PR!
I don't fully understand it yet, but I've left some comments and small requests.
Hopefully we can have a call to help clear up any misunderstandings that I have.
Thanks!
[ "What was supposed to be an initial overestimation of fees " | ||
, "turned out to be an underestimation, and I cannot recover. " | ||
, "This is a cardano-wallet bug." | ||
[ "I have somehow failed balancing the transaction. The balance" |
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.
Just a suggestion:
[ "I have somehow failed balancing the transaction. The balance" | |
[ "I have failed to balance the transaction. The balance" |
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 do like the "somehow" however, to signal that this is unexpected -> f347a64
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 point! Perhaps it's good to include the "somehow" after all. I agree it's nice to signal that this is unexpected.
-> Maybe Node.Value | ||
-- ^ Evaluate the balance of a transaction using the ledger. A valid | ||
-- transaction must be balanced. | ||
-- |
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 think this usage of the term "balance" might be confusing for people.
There is a pre-existing convention that "balance" refers to the sum of something. For example:
- The "available UTxO balance": the sum of all values in the wallet's UTxO set.
- The "input balance": the sum of all values provided by inputs in a transaction.
- The "output balance": the sum of all values consumed by outputs in a transaction.
I think this usage of "balance" as the "sum" of something is quite intuitive.
Though in "evaluateTransactionBalance", "balance" seems to refer to a delta between input value provided to the transaction and output value consumed by the transaction. In other words, it's a delta between two sums: Σ input value − Σ output value
.
Could we consider the term "delta" instead? This usage already has a precedent: https://github.com/input-output-hk/cardano-wallet/blob/bfacc71ada6b926ee608e5e537e7040d37842eaf/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs#L510
Alternatively, if you're really keen on using the term "balance" here, then perhaps we should add some more comments to define what sort of "balance" it is. What do you think?
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 a further suggestion: if we adopt the term "balance", then perhaps we could add a comment similar to:
The balance of a transaction is defined as:
(value consumed by the transaction) − (value produced by the transaction)
This way, we avoid having to mention the fee, since the fee is part of the value that's "consumed" by the transaction.
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'm in favour of balance
as a term because it seems well-used in the node and ledger — including the ledger's evaluateTransactionBalance
we make use of.
Delta seems to be a concept specific to coin-selection, and differs from balance in that it is not affected by the fee.
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
instance Buildable BalanceTxGolden where | ||
build (BalanceTxGoldenFailure c err) = mconcat | ||
[ build c | ||
, ",,," |
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.
Question: why three commas 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.
I know, it looks strange! The idea was to have well-defined CSV columns for the sake of gnuplot
. However, leaving empty values didn't seem to work... Maybe I should use a single comma unless we come up with a proper checked-in gnuplot script.
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.
-> ece4adc, not sure what you think.
On a related note: having a concise ToText
for balanceTx/coin-selection errors would be very neat!
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.
On a related note: having a concise ToText for balanceTx/coin-selection errors would be very neat!
Perhaps rendering these as JSON makes more sense? Since these errors sometimes have to contain structured information.
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
d948111
to
57bc6fa
Compare
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
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.
Hi @Anviking
I've added a few comments to add links to tickets on JIRA for the various TODO
comments. If you could add the links, and link those JIRA tickets to the appropriate epic, then I think it would be fine to merge!
I've also added a few other comments and suggestions. Hopefully these should be make sense, but let me know if not.
Thanks again!
Jonathan
Squashed: Tweak arguments of evaluateTransactionBalance Allow passing in the UTxO in two parts: 1. `W.UTxO` 2. `[(TxIn, TxOut, Maybe (Hash "Datum"))]` which are internally combined. This could have been avoided if either: 1. `W.UTxO` could support datum hashes 2. A `UTxO -> Cardano.UTxO` conversion were available in core. Improve errors of evaluateTransactionBalance
Produces CSV files with the columns > wallet balance, fee, minfee, error for a 1 UTxO wallet balance of 0 to 4 ada, with the following payloads: - 1ada-payment - delegate - pingPong_1 - pingPong_2
Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
253402e
to
2453aa1
Compare
@@ -1722,6 +1724,13 @@ toCardanoStakeCredential = Cardano.StakeCredentialByKey | |||
toCardanoLovelace :: W.Coin -> Cardano.Lovelace | |||
toCardanoLovelace (W.Coin c) = Cardano.Lovelace $ intCast c | |||
|
|||
toCardanoUTxO :: ShelleyBasedEra era -> W.UTxO -> Cardano.UTxO era |
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.
Maybe this will only be needed from the tests, but keeping for now...
Thanks @jonathanknowles ! bors r+ |
Build succeeded: |
3100: Re-write balanceTransaction using Node.evaluateTransactionBalance r=jonathanknowles a=Anviking - [x] Rewrite balanceTransaction using `evaluateTransactionBalance` - Effects on goldens can be viewed in the diff of this PR - [x] Enable `prop_balanceTransactionBalanced` - [x] Polish - [x] Even more polish - [ ] Will look through from top to bottom before merging ### Future work - [x] Pay surplus as excess fee when we cannot afford a change-output. (Would like to do while comparing constructTx with balanceTx) - [x] Ensure tx size limit is respected (Requires fixing ADP-1484 _and_ [this](https://github.com/input-output-hk/cardano-wallet/blob/ae8a2206b6f659b879d3bf14fd4ffdad7e781992/lib/core/src/Cardano/Wallet.hs#L1788-L1818) ) ### Comments First part introducing goldens and the evaluateTransactionBalance function: #3150 ### Issue Number ADP-1372 <!-- 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. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io> Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
evaluateTransactionBalance
toTransactionLayer
guardTxBalanced
tobalanceTransaction
guardTxBalanced
doesn't fail in our existing integration and unit tests.balanceTransaction
to ensure there are no regressions in Re-write balanceTransaction using Node.evaluateTransactionBalance #3100Comments
Preparation for #3100
Issue Number
ADP-1372