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

Run multiple coin selections to estimate fees #1653

Merged
merged 1 commit into from
May 20, 2020

Conversation

rvl
Copy link
Contributor

@rvl rvl commented May 12, 2020

Issue Number

Relates to ADP-283 / #1648.

Overview

  • Extends POST /wallets/{id}/payment-fees API endpoint with a "better" estimation. Adds fields for expected minimum and maximum fees.

Comments

  • decide on whether the api change should be breaking or backwards compatible
  • also do similar fee estimation for delegation transactions
  • better handling of coin selection errors while sampling
  • determine how many samples to take, or a criteria for stopping sampling.
  • decide on quantile calculation method (currently using median).
  • unit test estimateFeeForCoinSelection

@rvl rvl self-assigned this May 12, 2020
@rvl rvl force-pushed the rvl/adp-283/fee-estimate-stats branch from 8123a1c to ea99f42 Compare May 14, 2020 13:33
@rvl rvl changed the title wip: run multiple coin selections to estimate fees Run multiple coin selections to estimate fees May 14, 2020
@rvl rvl marked this pull request as ready for review May 14, 2020 13:46
@rvl rvl force-pushed the rvl/adp-283/fee-estimate-stats branch from ea99f42 to 5d33ab3 Compare May 14, 2020 14:50
@rvl rvl requested a review from jonathanknowles May 15, 2020 08:19
@jonathanknowles jonathanknowles self-requested a review May 15, 2020 09:36
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.

Hi Rodney

I've not looked into the statistics yet, but this looks very reasonable.

I do have a question regarding backwards compatibility.

The approach taken (so far) is to add a pair of fields to the existing ApiFee type:

- newtype ApiFee = ApiFee
-     { amount :: !(Quantity "lovelace" Natural) }
+ data ApiFee = ApiFee
+     { amount :: !(Quantity "lovelace" Natural)
+     , estimatedMin :: !(Quantity "lovelace" Natural)
+     , estimatedMax :: !(Quantity "lovelace" Natural)
+    }

Values of this type are returned by the following endpoint:

POST /wallets/{id}/payment-fees

As an alternative to modifying this endpoint, have you considered introducing a new endpoint and new type? Something like:

POST /wallets/{id}/payment-fee-estimates

With the following type:

data ApiFeeEstimate = ApiFeeEstimate
    { estimatedMin :: !(Quantity "lovelace" Natural)
    , estimatedMax :: !(Quantity "lovelace" Natural)
   }

@KtorZ KtorZ added the IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG label May 15, 2020
@rvl rvl force-pushed the rvl/adp-283/fee-estimate-stats branch 2 times, most recently from 3954256 to 7d1bb4f Compare May 19, 2020 13:39
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.

Hi @rvl

Given the requirements as stated, this PR looks very sensible to me!

Ideally, we'd have some experimental data available to indicate the time and space costs of making multiple coin selections for different kinds of UTxO distributions. Unfortunately we don't have such data yet. (Though I'd very much like to create such a benchmark in future.)

Having said that, our current coin selection property tests do give us some (limited) information. With our current configuration, we're able to generate around 1,000 coin selections per second on our test machine. But this time includes the time taken to generate arbitrary UTxO sets. We currently generate UTxOs with between 1 and 256 entries, chosen according to a uniform random distribution. If we were to start with the same UTxO every time (to match what this PR is doing), this would almost certainly reduce the calculation time.

Assuming 100 samples from a similarly-sized UTxO set, the fee estimation endpoint could take around 1/10 second on a similar machine. So this seems reasonable as a starting point. 👍

If we wanted to err on the side of caution, then we could watch the clock while taking samples, and stop prematurely if we've taken too long. (Though perhaps that could be a future PR.)

As for the rest of the PR: I only have a minor request, which is to fix a couple of formatting issues (see comments with suggested changes included).

Also, I have a question regarding the property test (relating to the fee maximum).

Apart from that, all looks good!

@rvl
Copy link
Contributor Author

rvl commented May 20, 2020

We are going to change the estimate-fees api without making it backwards compatible.

@rvl rvl force-pushed the rvl/adp-283/fee-estimate-stats branch from d5bbb3d to 840e210 Compare May 20, 2020 10:52
@rvl
Copy link
Contributor Author

rvl commented May 20, 2020

Thanks - rebased and squashed.

bors merge

iohk-bors bot added a commit that referenced this pull request May 20, 2020
1653: Run multiple coin selections to estimate fees r=rvl a=rvl

### Issue Number

Relates to ADP-283 / #1648.

### Overview

- Extends `POST /wallets/{id}/payment-fees` API endpoint with a "better" estimation. Adds fields for expected minimum and maximum fees.

### Comments

- [x] decide on whether the api change should be breaking or backwards compatible
- [x] also do similar fee estimation for delegation transactions
- [x] better handling of coin selection errors while sampling
- [ ] determine how many samples to take, or a criteria for stopping sampling.
- [x] decide on quantile calculation method (currently using median).
- [x] unit test `estimateFeeForCoinSelection`


Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 20, 2020

Build failed

@KtorZ KtorZ force-pushed the rvl/adp-283/fee-estimate-stats branch from 840e210 to c602532 Compare May 20, 2020 16:32
@KtorZ
Copy link
Member

KtorZ commented May 20, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request May 20, 2020
1653: Run multiple coin selections to estimate fees r=KtorZ a=rvl

### Issue Number

Relates to ADP-283 / #1648.

### Overview

- Extends `POST /wallets/{id}/payment-fees` API endpoint with a "better" estimation. Adds fields for expected minimum and maximum fees.

### Comments

- [x] decide on whether the api change should be breaking or backwards compatible
- [x] also do similar fee estimation for delegation transactions
- [x] better handling of coin selection errors while sampling
- [ ] determine how many samples to take, or a criteria for stopping sampling.
- [x] decide on quantile calculation method (currently using median).
- [x] unit test `estimateFeeForCoinSelection`


Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 20, 2020

Build failed

@KtorZ
Copy link
Member

KtorZ commented May 20, 2020

bors rety

@KtorZ
Copy link
Member

KtorZ commented May 20, 2020

bors retry

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 20, 2020

@iohk-bors iohk-bors bot merged commit 64d48e9 into master May 20, 2020
@iohk-bors iohk-bors bot deleted the rvl/adp-283/fee-estimate-stats branch May 20, 2020 19:05
piotr-iohk pushed a commit to piotr-iohk/ikar that referenced this pull request May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants