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

RandomImprove : Test covering fees correctly #254

Merged
merged 6 commits into from
Nov 12, 2021

Conversation

vsubhuman
Copy link
Contributor

Added test that consistently fails on random improve not adding enough funds to cover the fees

@vsubhuman vsubhuman marked this pull request as draft November 8, 2021 11:10
@vsubhuman vsubhuman marked this pull request as ready for review November 8, 2021 11:10
Copy link
Contributor Author

@vsubhuman vsubhuman left a comment

Choose a reason for hiding this comment

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

/check

@vsubhuman
Copy link
Contributor Author

Fails with insufficient funds at the moment:

image

Waiting for #252 to get resolved to fix that.

The conditions in the test are:

  1. Output value is 100
  2. Min fee when only output is added is 53
  3. Three outputs are available, 150 each
  4. When only two outputs are added (which is enough to cover the output) - the min fee is 228
  5. The total then comes to 328 and two outputs are not enough to cover that - hence the fail
  6. If three outputs would be added - min fee then is 264 and the total comes to 364
  7. Three outputs together are 450 and should be enough to cover the required 364

Base automatically changed from ruslan/coin-selection-fix-using-all-inputs to master November 8, 2021 20:41
@vsubhuman vsubhuman requested review from rooooooooob and pedromtcosta and removed request for SebastienGllmt November 8, 2021 22:46
@pedromtcosta
Copy link
Contributor

@vsubhuman I made the following changes:

  • updated test to assert for the fee amount of 264 because now we expect the TX from that test to have 3 inputs;
  • after "Phase 2: Improvement", if the total input is smaller than the total output, meaning the added fees from the inputs were not covered, we add the sufficient inputs to cover for the total output

// Phase 3: add extra inputs needed for fees
// We do this at the end because this new inputs won't be associated with
// a specific output, so the improvement algorithm we do above does not apply here.
if input_total.partial_cmp(&output_total).unwrap().eq(&Ordering::Less) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Why using partial_cmp here?
  2. Unchecked unwrap doesn't look good.

If these two types are both Value I think you can even just use <, e.g. see how while added < needed is used above

Copy link
Contributor

@pedromtcosta pedromtcosta Nov 9, 2021

Choose a reason for hiding this comment

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

Ah, that was a bad copy paste from my end 😅
Just pushed a version with a regular < comparison

@vsubhuman
Copy link
Contributor Author

vsubhuman commented Nov 9, 2021

@rooooooooob , check the solution plz if you have a chance

Copy link
Contributor

@rooooooooob rooooooooob left a comment

Choose a reason for hiding this comment

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

I guess this is a good enough fix to do it at the end. CIP 2 actually leaves out the fees entirely and says it's out of scope of the CIP so this detail is not covered which is why I tried to do it during the adding phase.

We're also trying to figure out what we want to do for multiassets since those also weren't covered but we can cover that at a later point.

@rooooooooob
Copy link
Contributor

/check

Copy link
Contributor Author

@vsubhuman vsubhuman left a comment

Choose a reason for hiding this comment

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

/check

@vsubhuman
Copy link
Contributor Author

vsubhuman commented Nov 12, 2021

Thank you, @pedromtcosta ! Looks good!

@vsubhuman vsubhuman added this to the 10.0.0 milestone Nov 12, 2021
@vsubhuman vsubhuman merged commit 0a451c4 into master Nov 12, 2021
@vsubhuman vsubhuman deleted the ruslan/random-improve-insufficient-funds branch November 12, 2021 11:15
@vsubhuman vsubhuman mentioned this pull request Feb 6, 2022
40 tasks
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.

Issue with the CIP2 random-improve coin-selection when small inputs and need to calculate change
3 participants