bdk icon indicating copy to clipboard operation
bdk copied to clipboard

Inconsistent checking of RBF rules

Open LLFourn opened this issue 5 years ago • 11 comments

BIP125 rules 3 and 4 are not being checked properly according to my understanding:

https://github.com/bitcoindevkit/bdk/blob/c2b2da7601fb570952cfd858f3821b3a4fd87ec9/src/wallet/mod.rs#L730-L746

It should be checking rules 3 and 4 regardless of the fee policy chosen in txbuilder.

LLFourn avatar Dec 30 '20 04:12 LLFourn

I think we can kinda ignore rule 3 at the moment, since we don't support merging multiple unconfirmed transactions, so this:

The replacement transaction pays an absolute fee of at least the sum paid by the original transactions.

For us basically means that we should just pay at least the previous fee.

I agree on rule 4 though, the FeeAmount branch should check for *amount < details.fees + _something_.

And now that I think about it, it's kind of a chicken-and-egg problem: rule 4 says that we should pay at least the size of the new transaction, but at this point we don't know it yet. So even the part above where required_feerate is computed is wrong.. Not sure what's the best way to handle this, I've gotta think about it a bit more..

afilini avatar Jan 05 '21 11:01 afilini

Coin selection algorithms should take min_absolute_fee and target_feerate into consideration on the get-go (and only succeed when both constraints are satisfied).

bdk_core will solve this issue, WIP here: https://github.com/LLFourn/bdk_core_staging/pull/21

evanlinjin avatar Sep 14 '22 17:09 evanlinjin

We discussed it in the call and decided to close this issue. Please comment if you think it should be re-opened

nondiremanuel avatar Sep 26 '23 12:09 nondiremanuel

Per discussion in dev call today this doesn't seem to be fixed yet.

notmandatory avatar Mar 26 '24 13:03 notmandatory

Per @evanlinjin we can fix this issue by using the new bdk_coin_select crate.

notmandatory avatar Mar 26 '24 13:03 notmandatory

More notes from @evanlinjin from discord chat: "We already have the TxParams::bumping_fee field we just aren't checking them correctly. However, I am concerned about rule 4 not being enforced properly (since we are actually doing coin selection again for RBF). An easy policy (that would enforce rule 4) would be to say the new tx cannot be larger than the one we are replacing. However, this is not what we are doing with our RBF logic. We add all old inputs into TxParams::utxos which is inputs that must be spent.

Therefore, it is possible that our new transaction may be larger in weight than the old one Right now, I'm very tempted to say let's use bdk_coin_select..."

notmandatory avatar Mar 26 '24 15:03 notmandatory

I volunteer to try and fix RBF API with bdk_coin_select. Don't have an ETA yet.

LLFourn avatar Mar 27 '24 05:03 LLFourn

Thanks @LLFourn , if you can fix with integration of bdk_coin_select that'd be great.

notmandatory avatar Mar 28 '24 00:03 notmandatory

@LLFourn Since we're not going to have have a bdk_coin_select crate for 1.0 can I defer this issue to the 2.0 milestone?

notmandatory avatar Jun 01 '24 23:06 notmandatory

Yes I'd like to make the extracted bdk_coin_select one of the priorities for 2.0 so if it's better to fix this together with that I'll update the milestone.

notmandatory avatar Jun 17 '24 19:06 notmandatory

Sorry ACK I haven't had time to do this work so yes you can push it to 2.0.0. Thanks.

LLFourn avatar Jun 27 '24 02:06 LLFourn