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

[Bitcoin]: UTXO selection and dust improvements #3675

Merged
merged 11 commits into from
Mar 1, 2024

Conversation

satoshiotomakan
Copy link
Collaborator

@satoshiotomakan satoshiotomakan commented Feb 2, 2024

Description

  • Add SigningInput::Proto::dust_policy with the fixed_dust_threshold option.
  • Filter out Dust UTXOs before actual UTXO selecting.
  • Do not include change output if it's "dust".
  • Validate the requested amount if it's "dust".
  • InputSelector::select returns entire list of UTXOs if it couldn't find a combination of inputs to cover estimated transaction fee and the target amount. This is needed, because FeeEstimator estimates Segwit transaction too rough, however later, in estimateSegwitFee function, the transaction fee is significantly less, so the given UTXOs enough to cover it.

How to test

Run C++ tests

Types of changes

Checklist

  • Create pull request as draft initially, unless its complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

@satoshiotomakan satoshiotomakan marked this pull request as ready for review February 2, 2024 18:23
@satoshiotomakan satoshiotomakan changed the title [Bitcoin]: Check Transaction Outputs for Dust threshold [Bitcoin]: UTXO selection and dust improvements Feb 2, 2024
hewigovens
hewigovens previously approved these changes Feb 3, 2024
lamafab
lamafab previously approved these changes Feb 5, 2024
Copy link
Contributor

@lamafab lamafab left a comment

Choose a reason for hiding this comment

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

So disclaimer - I don't grasp the full C++ implementation, but generally this LGTM.

src/Bitcoin/InputSelector.h Outdated Show resolved Hide resolved
src/Bitcoin/InputSelector.cpp Outdated Show resolved Hide resolved
src/Bitcoin/TransactionBuilder.cpp Show resolved Hide resolved
src/Bitcoin/TransactionBuilder.cpp Show resolved Hide resolved
}

Amount LegacyDustCalculator::dustAmount([[maybe_unused]] Amount byteFee) noexcept {
return feeCalculator.calculateSingleInput(byteFee);
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally speaking, is it even appropriate to refer to this as dustAmount?

int64_t LinearFeeCalculator::calculateSingleInput(int64_t byteFee) const noexcept {
    return static_cast<int64_t>(std::ceil(bytesPerInput)) * byteFee; // std::ceil(101.25) = 102
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, but this is how our current chains work. This is a tradeoff to avoid breaking changes for other Bitcoin forks.

tests/chains/Bitcoin/InputSelectorTests.cpp Show resolved Hide resolved
@satoshiotomakan satoshiotomakan merged commit 7c71119 into master Mar 1, 2024
11 checks passed
@satoshiotomakan satoshiotomakan deleted the s/bitcoin-dust-amount branch March 1, 2024 13:08
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.

3 participants