-
Notifications
You must be signed in to change notification settings - Fork 636
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
Fix: TxOut::minimal_non_dust and Script::dust_value #2255
Conversation
concept ACK. I am ambivalent about taking the minrelayfee as an argument. Maybe we should promote it to a constant, take it as an arg to |
A test or two would be nice :P |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK b4f1bbb
Perhaps this is cleaner? pub fn minimal_non_dust(script_pubkey: ScriptBuf) -> Self {
// This is the default -minrelaytxfee (0.00001 BTC/kvB) in satoshis.
const MIN_RELAY_TX_FEE: u64 = 1000; // sat/kvB
const DUST_FEE_RATE: u64 3;
let len = size_from_script_pubkey(&script_pubkey);
let len = len
+ if script_pubkey.is_witness_program() {
32 + 4 + 1 + (107 / 4) + 4
} else {
32 + 4 + 1 + 107 + 4
};
let limit = (len as u64) * DUST_FEE_RATE * (MIN_RELAY_TX_FEE / 1000);
TxOut {
value: Amount::from_sat(limit),
script_pubkey,
}
} IMO no tests needed for this code change. |
yeah no tests to begin with so. |
Discovery: We had duplicate code in TxOut and Script. I consolidated it to Script and changed stuff around. |
The commit message needs changing heh. |
I'm not convinced we should take the parameter since it's hard-coded in Core. As I understand it if Core changes it a lot of applications break so it won't happen. Also if we're going to add it I'd prefer two method, the second one with |
The If we assume no one changes it, sure, a constant is fine. But Bitcoin Core allows users to change it on startup, so I think we should too. |
I split things up into a _custom and normal function. |
So turns out I either misremembered it or the code changed since when I first read it. This is a dangerous situation - some contracts rely on the value being something specific. E.g. if enough people raised the value LN anchors would break. I don't think it should be easily configurable in Core (but of course we have to allow it in our code). |
If this is true then LN anchors are just broken. The minrelayfee effectively is increased whenever Core nodes' mempools exceed 300Kb (with default settings). In any case, minrelayfee is purely a policy thing set by individual nodes. It absolutely should be configurable (it is impossible for the network to enforce any relay policy at all, including policy about minimum fees, so it is always "configurable" for somebody willing to do the work). Whether we want to support different values, for purposes of defining a "dust limit" (another Core policy which nodes are free to implement differently), I don't know. These days it's usually a true assumption that nodes will enforce a dust limit at the default Core limit. In future, when we have consistent mempool backlog exceeding the default mempool size, it usually won't be. In future, plausibly Core will boost the value. Or drop it entirely and depend on the mempool eviction logic to drop low-fee transactions. Or something else entirely. |
It should be noted that the dust limit is not tied to the ejection rate (which is dynamic based on the mempool size) but just the runtime parameter. |
@junderw oops, you're right. So txes above the minrelayfee will be relayed, they just might be immediately forgotten. This may be an important distinction. I'm unsure how CPFP interacts with this. If it's possible to CPFP a too-low-fee transaction but not possible to CPFP a below-minrelayfee transaction, then that's a serious difference. (All assuming that the vast majority of the network is using the default Core policy ofc) |
Upon looking into the Core code to gather links to the areas where values are parsed and used... I noticed an error on my part. I made a mistake: it was
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 09664c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking but I would prefer my comments to be addressed.
TxOut::minimal_non_dust has 3 problems. 1. There is an invisible dependency on Bitcoin Core's default minrelaytxfee value. It has been made explicit. 2. There is an off by one error. The dust limit comparison uses < and therefore `+ 1` was not needed. It has been fixed. 3. It was not returning 0 amount for OP_RETURN outputs. Script::dust_value has 2 problems. 1. The dust amount depends on minrelaytxfee which is configurable in Bitcoin Core. This method was not configurable. 2. The division operation was done before multiplying the byte amount, which can cause small differences when using uncommon scripts and minrelaytxfee values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1b23220
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1b23220
Aaaahhh! Just realized the commit message still mistakenly refers to minrelaytxfee...... (On Mobile RN) |
I can tolerate sligthly wrong commit message here. |
Was there a reason we didn't deprecate This change is hinders the upgrade path for upcoming 0.32.0 release. |
I think we just forgot. Should we put it back before release? |
c17db32 Pub back in deprecated dust_value (Tobin C. Harding) Pull request description: When we renamed `dust_value` to `minimal_non_dust` we forgot to keep the original and deprecated it, doing so assists with the upgrade path. Put back in deprecated `dust_value`, linking to the rename. Renamed in #2255, found while testing upgrade of downstream software. ACKs for top commit: tcharding: > ACK [c17db32](c17db32) I _think_ this matches the behavior of the old version apoelstra: ACK c17db32 I *think* this matches the behavior of the old version sanket1729: ACK c17db32 Tree-SHA512: 28e1bd2e1a0fd13c78c70ad2667b72b3bf649c293201b79c86c00f09d0126389ebaeb430b8dd32aeeec3d60cbd8761ae949f5784a5ea7756b1b9ae77ec96ce61
Fixes #2192
TxOut::minimal_non_dust has 3 problems.
+ 1
was not needed. It has been fixed.Script::dust_value has 2 problems.