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

No more base weight #21

Merged
merged 9 commits into from
Mar 31, 2024
Merged

Conversation

LLFourn
Copy link
Collaborator

@LLFourn LLFourn commented Jan 25, 2024

Fixes #1

On top of #19

  • CoinSelector no longer tracks anything but input weight
  • Previously the value of the target outputs was in Target but the
    weights were accounted for in CoinSelector. Now they're in all in
    target.
  • This allows us to actually figure out how many outputs there are and
    therefore the actual weight of the transaction accounting for the varint for the number of outputs.

This wasn't what the issue had in mind but it was easier to take the base_weight out of CoinSelector and put it in Target rather than put Target in CoinSelector. Getting rid of base_weight is a more crucial change than expected because rust bitcoin changed what Transaction::weight returns for empty output transactions recently so using it to determine base_weight will get different answers between versions (this breaks our weight tests but this PR will fix it I think if we uprade dev deps). We only need to know the total weight of the outputs and how many there are now to get the right answers for weight.

- CoinSelector no longer tracks anything but input weight
- Previously the value of the target outputs was in `Target` but the
  weights were accounted for in CoinSelector. Now they're in all in
  target.
- This allows us to actually figure out how many outputs there are and
  therefore the actual weight of the transaction accounting for varints.
changeless should not be that slow but if it fails to find a changeless
solution then the test will exhaustive search so that clearly will take forever.
@murchandamus
Copy link

murchandamus commented Jan 29, 2024

Yeah, the waste metric is only used as a tiebreaker rather than something to optimize for because it would happily consolidate all your UTXOs at low feerates. What did you end up using instead?

Sorry, I only discovered this codebase recently per the Optech Newsletter, I’ll take a bit of a look around. :)

@LLFourn
Copy link
Collaborator Author

LLFourn commented Jan 30, 2024

Hey @murchandamus! We've been keeping this code base low profile because it's still in science experiment stage. FWIW we gathered a long time ago that the waste metric was not something that you should use to actually optimize for -- it was just a good one to use to start the experiment. I'm interested in your work here: https://delvingbitcoin.org/t/gutterguard-and-coingrinder-simulation-results/279. It would be cool to try and replicate it.

We're just using what we call LowestFee metric: Tries to minimize the fee cost of the selection while taking into account the cost of spending the change (using the "long term feerate").

@murchandamus
Copy link

murchandamus commented Jan 30, 2024

Ah that sounds similar to what I’m trying to do with CoinGrinder, where I am trying to always find the input set with the lowest input weight. The PR should hopefully be very readable: I organized the pullrequest to start with a simple implementation of the algorithm and then each improvement or optimization a separate commit. I still have a little hope that it might make the release, even if I did miss the really big feerates. In combination with BnB, and the waste metric, I guess I’d get something similar as the outcome of your LowestFee metric.

LLFourn and others added 2 commits January 30, 2024 13:42
We already have const `Drain::NONE` which should be used instead.
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK ab38cb0

I saw some obvious mistakes so I pushed fixes as commits. Everything else looks good to me. The LowestFee bound function looks correct.

The logic was wrong before because it was making the RBF constraints
take precedence. Instead, we should be taking the maximum between
the fee calculated from the target feerate and the minimum fee that
satisfies the RBF constraints.
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK c650306

@evanlinjin evanlinjin merged commit e8cb15c into bitcoindevkit:master Mar 31, 2024
5 checks passed
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.

Simplify DrainWeights/Target API
3 participants