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

Feature request: Dust threshold value based on output script #2009

Open
arik-so opened this issue Dec 2, 2023 · 8 comments · May be fixed by #2010
Open

Feature request: Dust threshold value based on output script #2009

arik-so opened this issue Dec 2, 2023 · 8 comments · May be fixed by #2010
Labels

Comments

@arik-so
Copy link
Contributor

arik-so commented Dec 2, 2023

Sometimes when parsing transactions I need to check whether an output value is too low for a given output type. Would you consider adding some sort of utility, maybe to bitcoin.address, that would allow me to look up the dust threshold based on the output script? Perhaps bitcoin.address.dustThresholdFromOutputScript() or something similar?

@junderw
Copy link
Member

junderw commented Dec 2, 2023

Ooh, that sounds like a good idea.

I'll see if I can whip something up later.

If anyone wants to work on it let me know.

@junderw
Copy link
Member

junderw commented Dec 2, 2023

Basically:

  1. If it's provably unspendable (OP_RETURN et al) then 0 sats is ok
  2. If it's segwit then use 67 bytes if not, use 148 bytes
  3. Add the size of the output, which is script size + size of varint for scriptSize + 8 (for i64 amount)
  4. Multiply bytes by 3 to get sats (round up). (MIN_RELAY_TX_FEE = 1000 assumed)

https://github.com/bitcoin/bitcoin/blob/160d23677ad799cf9b493eaa923b2ac080c3fb8e/src/policy/policy.cpp#L26-L63

@junderw
Copy link
Member

junderw commented Dec 2, 2023

Questions:

  1. Add a parameter to represent MIN_RELAY? (I checked and it's not based off of the eject level, it's based off of the min_relay parameter (which defaults to 1000)
  2. If we do add a parameter... should we do sat/kvB? (1000) or sat/vB (1)? (defaults in parens)

@junderw junderw linked a pull request Dec 3, 2023 that will close this issue
@junderw
Copy link
Member

junderw commented Dec 3, 2023

Check out the PR.

@arik-so
Copy link
Contributor Author

arik-so commented Dec 3, 2023

Wow, that was fast! Do answer your second question: I think sat/vByte is probably the most convenient.

@junderw
Copy link
Member

junderw commented Dec 3, 2023

I guess it really doesn't matter. We can change it later.

Just check it out and make sure it jives with the Core code.

@arik-so
Copy link
Contributor Author

arik-so commented Mar 1, 2024

By the way, thank you so much for implementing this! Shall I close this issue?

@junderw
Copy link
Member

junderw commented Mar 1, 2024

No it'll be closed when we merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants