libitx / txforge

Modern Bitcoin transaction builder, capable of supporting any non-standard and custom script type.
Apache License 2.0
63 stars 21 forks source link

Replace dust limit constant with dynamically calculated dust threshold #8

Closed libitx closed 3 years ago

libitx commented 3 years ago

PR #7 by @freddiehonohan allowed the hardcoded dust limit to be overridden by the user with a dustLimit config option. This has been merged but not released yet.

Propose reverting this change and replacing the dust limit constant with a function that is determined by output script size and miner relay fee.

See https://github.com/bitcoin-sv/bitcoin-sv/blob/master/src/primitives/transaction.h#L188-L208 for reference.

Correct function should be:

dustLimit = 3 * (lockingScriptSize + 148) * minRelayTxFee / 1000

Required changes:

  1. rates config option should include mine and relay figures. User can provide their own rates object straight from minercraft. Care needed to ensure this isn't a breaking change for some.
  2. the build() function should calculate the dustLimit for each output programatically - as per function above
  3. no need for dust limit constant or config option