-
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
Implement sizeOfCoin
and costOfIncreasingCoin
#3215
Conversation
sizeOfCoin
and costOfIncreasingCoin
sizeOfCoin
and costOfIncreasingCoin
fe581ab
to
0a3e29c
Compare
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
1346eab
to
b13793b
Compare
3eea663
to
b17b6a8
Compare
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 made some general comments and suggestions. Will have another look in a bit!
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
it "costs 176 lovelace to increase 4294967295 by one on mainnet" $ do | ||
let feePolicy = LinearFee $ LinearFunction | ||
{ intercept = 150_000, slope = 44 } | ||
costOfIncreasingCoin feePolicy (Coin 4294967295) (Coin 1) |
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.
Suggestion: use an explicit power of 2 here.
Justification: it's now really obvious why this is a boundary. (Some readers of the code might not recognize that these values are related to the powers of 2.)
costOfIncreasingCoin feePolicy (Coin 4294967295) (Coin 1) | |
costOfIncreasingCoin feePolicy (Coin $ 2^32 - 1) (Coin 1) |
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.
#3215 (comment), however because of the test title I think it in particular makes sense to use 4294967295 here. I tweaked the title a bit: 1303e02
lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Outdated
Show resolved
Hide resolved
d496b19
to
98a73ec
Compare
@jonathanknowles about changing Also I believe the real values are easier to correlate to failures from
So in my mind "why are these values magic" is less important than "these are the magic values", although I admit there's some neatness to #3215 (comment). What do you think? |
21e87d7
to
1303e02
Compare
This improves coverage of boundary cases in sizeOfCoin properties.
Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Use 4-space indents, and put exports into alphabetical order.
This commit also uses these named constants in `genLovelace` to replace hard-coded values. If a developer is new to the codebase, they can understand the choice of these constants by navigating to their definitions and reading the comments.
Since `Lovelace` is an instance of `Num` and `Random`, we can avoid wrapping and unwrapping `Lovelace` values when using `choose`.
In the implementation of `sizeOfCoin`, we use hard-coded constants for powers of two, which avoids computing these values on each call. However, in the test code, we can be even clearer about our intent, by explicitly stating which powers of two we're interested in. For someone new to the codebase, being able to see the relationship with the powers of two is arguably helpful for being able to comprehend why we're testing these particular values. At a glance, it's arguably quite hard to see the the difference between: - 4294967295 - 4294967296 But it's very easy to see the difference between: - 2^32 - 1 - 2^32
In this commit, we also remove the expected cost increase from the name of the test. Otherwise, if someone updates this constant in future, it's possible that they'll forget to update the name of the test case, and the compiler won't tell them.
- Lead with "[it] costs" - Clearly specify the ≈4.29 ada value in the title
a285cec
to
ab82b9d
Compare
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.
Nice work! 👍🏻
bors r+ |
Build succeeded: |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- 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>
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- 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>
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- 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>
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- 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>
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- 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>
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- 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>
Implement and test the following functions:
Future work
The next PR will add a function to
TransactionLayer
with the following shape:Issue number
ADP-1514