Wallet: Don't backdate locktime rbf #36040

Manually merged
Bicaru20 merged 2 commits from 2026-dont-backdate-locktime-RBF into master 2026-11-20 23:55:02 +00:00 AGit
Bicaru20 commented 2026-08-20 15:28:02 +00:00 (Migrated from github.com)

Closes https://github.com/bitcoin/bitcoin/issues/26526

Currently, in Bitcoin Core, given an original transaction A and its replacement B, we refer to backdating when the locktime of A is higher than the locktime of B (A.locktime > B.locktime). This can happen because Bitcoin Core enables anti-fee-sniping by default, which sets the transaction's locktime to the current block height. For privacy, 10% of the time, it instead sets a different locktime, randomly chosen between the current height and the current height minus 100 blocks. This can lead into having a replacement of a transaction with a locktime older than its original transaction. This is unrealistics and can be used as a wallet fingerprint.

You can find a functional test to reproduce the behaviour mentioned here

The approach proposed in this PR adds a new parameter to CoinControl to keep track of the previous locktime in the case of a bumpfee. We then pass this parameter to the DiscourageFeeSniping function through a new parameter, minimum_height, whose default value is set to 0.

Alternative approach: Since the locktime of the new transaction is 0, we also considered setting it to the previous locktime value and then, inside `DiscourageFeeSniping`, saving the previous locktime and setting the transaction's locktime to the block height before applying any of the backdating logic. This way, we could avoid passing a new parameter to the function. We ultimately decided not to go with this approach, as it makes the code more difficult to follow.

The only RPC that is affected by this changes is bumpfee.

The pr also includes a functional test in wallet_bumpfee.py to test that when replacing a transation using bumpfee the locktime is not backdated.

We also conducted a small analysis to see how many the backdating in RBF transactions actually happen. We have data on the replaced transactions from 2025-05-01 to 2026-06-01. With that we have been able to detect this many backdatings: image

We took the date of the last transaction of the
replacement chain (A replacement chain are all the transactions that replace themselves)

In total we have over 1,000,000 rbf transactions, but we see that on average there are only about 200-300 hundred replaccements backdating per week. Looking at the percentages we see that on average is less than 2% of all the transactions that have been replaced.

So, it is clear that backdating in replacement transactions is unusual. However, the few transactions that do exhibit backdating are easily fingerprintable as having been replaced using bumpfee in Bitcoin Core or Electrum.

Closes https://github.com/bitcoin/bitcoin/issues/26526 Currently, in Bitcoin Core, given an original transaction A and its replacement B, we refer to **backdating** when the locktime of A is higher than the locktime of B (`A.locktime > B.locktime`). This can happen because Bitcoin Core enables **anti-fee-sniping** by default, which sets the transaction's locktime to the current block height. For privacy, 10% of the time, it instead sets a different locktime, randomly chosen between the current height and the current height minus 100 blocks. This can lead into having a replacement of a transaction with a locktime older than its original transaction. This is unrealistics and can be used as a wallet fingerprint. You can find a functional test to reproduce the behaviour mentioned [here](https://gist.github.com/Bicaru20/9afcb878dd103369255cd81cffac86ba) The approach proposed in this PR adds a new parameter to `CoinControl` to keep track of the previous locktime in the case of a `bumpfee`. We then pass this parameter to the DiscourageFeeSniping function through a new parameter, `minimum_height`, whose default value is set to 0. <details> <summary>Alternative approach:</summary> Since the locktime of the new transaction is 0, we also considered setting it to the previous locktime value and then, inside `DiscourageFeeSniping`, saving the previous locktime and setting the transaction's locktime to the block height before applying any of the backdating logic. This way, we could avoid passing a new parameter to the function. We ultimately decided not to go with this approach, as it makes the code more difficult to follow. </details> The only RPC that is affected by this changes is `bumpfee`. The pr also includes a functional test in `wallet_bumpfee.py` to test that when replacing a transation using `bumpfee` the locktime is not backdated. <details> <summary>We also conducted a small analysis to see how many the backdating in RBF transactions actually happen.</summary> We have data on the replaced transactions from 2025-05-01 to 2026-06-01. With that we have been able to detect this many backdatings: <img width="1782" height="891" alt="image" src="https://git.fish.foo/attachments/0d9eead7-216c-42d3-87df-9d5dbac9e802" /> _We took the date of the last transaction of the replacement chain (A replacement chain are all the transactions that replace themselves)_ In total we have over 1,000,000 rbf transactions, but we see that on average there are only about 200-300 hundred replaccements backdating per week. Looking at the percentages we see that on average is less than 2% of all the transactions that have been replaced. So, it is clear that backdating in replacement transactions is unusual. However, the few transactions that do exhibit backdating are easily fingerprintable as having been replaced using `bumpfee` in Bitcoin Core or Electrum. </details>
DrahtBot commented 2026-08-20 15:28:09 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK polespinasa, nervana21, achow101
Concept ACK vicjuma
Stale ACK molnard

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36843 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where comparison-specific test macros should replace generic comparisons:

  • test/functional/wallet_bumpfee.py: assert locktime - 99 <= rebumped_locktime <= locktime → Use assert_greater_than_or_equal(rebumped_locktime, locktime - 99) and assert_greater_than_or_equal(locktime, rebumped_locktime).

2026-11-04 09:34:04

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36040 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36040.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36040#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [polespinasa](https://github.com/bitcoin/bitcoin/pull/36040#pullrequestreview-5771490853), [nervana21](https://github.com/bitcoin/bitcoin/pull/36040#pullrequestreview-5814008256), [achow101](https://github.com/bitcoin/bitcoin/pull/36040#issuecomment-7053413606) | | Concept ACK | [vicjuma](https://github.com/bitcoin/bitcoin/pull/36040#pullrequestreview-5460837150) | | Stale ACK | [molnard](https://github.com/bitcoin/bitcoin/pull/36040#issuecomment-5782558859) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36843](https://github.com/bitcoin/bitcoin/pull/36843) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36843.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko) * [#35302](https://github.com/bitcoin/bitcoin/pull/35302) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible places where comparison-specific test macros should replace generic comparisons: - `test/functional/wallet_bumpfee.py`: `assert locktime - 99 <= rebumped_locktime <= locktime` → Use `assert_greater_than_or_equal(rebumped_locktime, locktime - 99)` and `assert_greater_than_or_equal(locktime, rebumped_locktime)`. <sup>2026-11-04 09:34:04</sup>
nervana21 commented 2026-08-21 00:34:49 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
nervana21 (Migrated from github.com) reviewed 2026-08-23 17:15:37 +00:00
nervana21 (Migrated from github.com) left a comment

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

nit:
Commit subject and body say "lockitme". Should be "locktime".

Commit body says "This changes change the behavior". It should be "This changes the behavior".

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme nit: Commit subject and body say "lockitme". Should be "locktime". Commit body says "This changes change the behavior". It should be "This changes the behavior".
nervana21 (Migrated from github.com) commented 2026-08-23 17:07:13 +00:00

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

    if (!new_coin_control.m_locktime.has_value()){

nit

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme ```suggestion if (!new_coin_control.m_locktime.has_value()){ ``` nit
Lines 1034-1039
nervana21 (Migrated from github.com) commented 2026-08-23 17:08:09 +00:00

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

            const int tip_floor_distance = block_height - static_cast<int>(minimum_height);
            if (tip_floor_distance > 0) {
                const int bound = minimum_height > 0
                    ? tip_floor_distance + 1
                    : std::min(100, tip_floor_distance + 1);
                const int back = rng_fast.randrange(bound);
                tx.nLockTime = block_height - back;
            }

There's an OBO in this logic. In the inclusive range [minimum_height, block_height] there are (block_height - minimum_height) + 1 possible values. randrange(block_height - minimum_height) only draws block_height - minimum_height possible values and can never pick the minimum_height value.

Also, when minimum_height == 0, we retain the prior behavior and backdate at most 99 blocks from tip. When minimum_height > 0, we should use the full inclusive window without the 100 block cap.

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme ```suggestion const int tip_floor_distance = block_height - static_cast<int>(minimum_height); if (tip_floor_distance > 0) { const int bound = minimum_height > 0 ? tip_floor_distance + 1 : std::min(100, tip_floor_distance + 1); const int back = rng_fast.randrange(bound); tx.nLockTime = block_height - back; } ``` There's an OBO in this logic. In the inclusive range `[minimum_height, block_height]` there are `(block_height - minimum_height) + 1` possible values. `randrange(block_height - minimum_height)` only draws `block_height - minimum_height` possible values and can never pick the `minimum_height` value. Also, when `minimum_height == 0`, we retain the prior behavior and backdate at most 99 blocks from tip. When `minimum_height > 0`, we should use the full inclusive window without the 100 block cap.
Lines 1040-1042
nervana21 (Migrated from github.com) commented 2026-08-23 17:10:10 +00:00

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

        // the privacy of high-latency transactions. Use minimum_height so new
        // sends still get a constant 0 fingerprint, while bumpfee keeps the prior 
        // height and does not make the replacement older than the original.
        // If that height is ahead of the local tip, use 0 so the tx stays final
        // and we do not fingerprint the lagging tip.
        if (minimum_height <= static_cast<uint32_t>(block_height)) {
            tx.nLockTime = minimum_height;
        } else {
            tx.nLockTime = 0;

In the case where we're fee bumping an already-nLockTimed tx, we should not reset its nLockTime back below that established minimum_height. Otherwise we fingerprint the tx. minimum_height defaults to 0, so new sends on a stale chain still retain the prior behavior of nLockTime = 0.

In the case where the minimum_height is ahead of the local tip, set nLockTime = 0

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme ```suggestion // the privacy of high-latency transactions. Use minimum_height so new // sends still get a constant 0 fingerprint, while bumpfee keeps the prior // height and does not make the replacement older than the original. // If that height is ahead of the local tip, use 0 so the tx stays final // and we do not fingerprint the lagging tip. if (minimum_height <= static_cast<uint32_t>(block_height)) { tx.nLockTime = minimum_height; } else { tx.nLockTime = 0; ``` In the case where we're fee bumping an already-nLockTimed tx, we should not reset its `nLockTime` back below that established `minimum_height`. Otherwise we fingerprint the tx. `minimum_height` defaults to 0, so new sends on a stale chain still retain the prior behavior of `nLockTime = 0`. In the case where the `minimum_height` is ahead of the local tip, set `nLockTime = 0`
Lines 193-195
nervana21 (Migrated from github.com) commented 2026-08-23 17:12:20 +00:00

b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

 * current chain tip unless we are not synced with the current chain).
 * The locktime is occasionally backdated, but never below minimum_height.
 * When minimum_height is 0, backdating is capped at 99 blocks from tip.
 * When minimum_height is set (bumpfee), backdating is uniform on [minimum_height, tip].
 * If the chain is not current and minimum_height is above the local tip, locktime is 0.
b7935c708edc225e20dcab0820dff774f841736b: Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme ```suggestion * current chain tip unless we are not synced with the current chain). * The locktime is occasionally backdated, but never below minimum_height. * When minimum_height is 0, backdating is capped at 99 blocks from tip. * When minimum_height is set (bumpfee), backdating is uniform on [minimum_height, tip]. * If the chain is not current and minimum_height is above the local tip, locktime is 0. ```
polespinasa (Migrated from github.com) reviewed 2026-08-25 14:25:01 +00:00
polespinasa (Migrated from github.com) left a comment

Approach ACK

reviewed f26586b91de16a03d4c265a7e8ee9fefb728dd65

in f26586b91de16a03d4c265a7e8ee9fefb728dd65 there as a typo in the commit message. It ends with - should be a .

Approach ACK reviewed f26586b91de16a03d4c265a7e8ee9fefb728dd65 in f26586b91de16a03d4c265a7e8ee9fefb728dd65 there as a typo in the commit message. It ends with - should be a .
polespinasa (Migrated from github.com) commented 2026-08-25 14:03:53 +00:00

in b7935c708edc225e20dcab0820dff774f841736b Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

nit: missing space between ) and {

in b7935c708edc225e20dcab0820dff774f841736b Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme nit: missing space between ) and {
polespinasa (Migrated from github.com) commented 2026-08-25 10:52:17 +00:00

in b7935c708edc225e20dcab0820dff774f841736b Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

Is this if needed? can we have a block_height smaller than the minimum_height? I think at least we will always be at the minimum_height, I can only think of a re-org, but then we must swich to a chain with more PoW so the height will likely be higher too.

Also I think this can be simplified into:

$ git diff
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 40eeb78f17..a34c95fcb3 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -1023,15 +1023,11 @@ void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast,
         // that transactions that are delayed after signing for whatever reason,
         // e.g. high-latency mix networks and some CoinJoin implementations, have
         // better privacy.
-        if (rng_fast.randrange(10) == 0) {
+        if (rng_fast.randrange(10) == 0 && tx.nLockTime > minimum_height) {
             // If a previous locktime is passed (like in the bump fee case), the
             // backdating is limited between the current height and the previous locktime
-            if (static_cast<uint32_t>(block_height) >= minimum_height) {
-                int locktime_range = std::min(100, int(block_height - minimum_height));
-                if (locktime_range > 0){
-                    tx.nLockTime = std::max(int(minimum_height), int(tx.nLockTime) - int(rng_fast.randrange(locktime_range)));
-                }
-            }
+            int range = std::min(100, int(block_height - minimum_height + 1));
+            tx.nLockTime = std::max(int(minimum_height), int(tx.nLockTime) - int(rng_fast.randrange(range)));
         }
     } else {
         // If our chain is lagging behind, we can't discourage fee sniping nor help
sliv3r@sliv3r-tuxedo:~/Documentos/Projectes/BitcoinCore/bitcoin$ 

This version I propose has several improvements:

  1. Removes some redundant if conditions.
  2. Fixes a missing + 1 case that you are missing by just taking block_height - minimum_height.
  3. Keeps the old behavior for the default case. Before this PR, short chains with less than a 100blocks would backdate locktime to 0, while this commit clamps it at 1.
in b7935c708edc225e20dcab0820dff774f841736b Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme Is this if needed? can we have a `block_height` smaller than the `minimum_height`? I think at least we will always be at the `minimum_height`, I can only think of a re-org, but then we must swich to a chain with more PoW so the height will likely be higher too. Also I think this can be simplified into: ```diff $ git diff diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 40eeb78f17..a34c95fcb3 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1023,15 +1023,11 @@ void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast, // that transactions that are delayed after signing for whatever reason, // e.g. high-latency mix networks and some CoinJoin implementations, have // better privacy. - if (rng_fast.randrange(10) == 0) { + if (rng_fast.randrange(10) == 0 && tx.nLockTime > minimum_height) { // If a previous locktime is passed (like in the bump fee case), the // backdating is limited between the current height and the previous locktime - if (static_cast<uint32_t>(block_height) >= minimum_height) { - int locktime_range = std::min(100, int(block_height - minimum_height)); - if (locktime_range > 0){ - tx.nLockTime = std::max(int(minimum_height), int(tx.nLockTime) - int(rng_fast.randrange(locktime_range))); - } - } + int range = std::min(100, int(block_height - minimum_height + 1)); + tx.nLockTime = std::max(int(minimum_height), int(tx.nLockTime) - int(rng_fast.randrange(range))); } } else { // If our chain is lagging behind, we can't discourage fee sniping nor help sliv3r@sliv3r-tuxedo:~/Documentos/Projectes/BitcoinCore/bitcoin$ ``` This version I propose has several improvements: 1. Removes some redundant if conditions. 2. Fixes a missing + 1 case that you are missing by just taking `block_height - minimum_height`. 3. Keeps the old behavior for the default case. Before this PR, short chains with less than a 100blocks would backdate locktime to 0, while this commit clamps it at 1.
polespinasa (Migrated from github.com) commented 2026-08-25 14:04:27 +00:00

in b7935c7 Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

nit: again, space between ) and {

in b7935c7 Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme nit: again, space between ) and {
polespinasa (Migrated from github.com) commented 2026-08-25 14:05:15 +00:00

in b7935c7 Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme

nit: this is over indented, there are 8 spaces instead of 4.

in b7935c7 Wallet: Do not allow bumpfee to backdate the replacement transaction lockitme nit: this is over indented, there are 8 spaces instead of 4.
polespinasa (Migrated from github.com) commented 2026-08-25 14:11:02 +00:00

in f26586b Test: bumpfee does not backdate the locktime

The test is weak, if the backdating code is broken and it does not backdate, this loop would run forever and never fail. Probably should add a big max num of tries so if after N iterations it did not pass, we can assume the code is wrong.

I would suggest a unit test for the function anyway, that way we can just test the backdating function.

in f26586b Test: bumpfee does not backdate the locktime The test is weak, if the backdating code is broken and it does not backdate, this loop would run forever and never fail. Probably should add a big max num of tries so if after N iterations it did not pass, we can assume the code is wrong. I would suggest a unit test for the function anyway, that way we can just test the backdating function.
polespinasa (Migrated from github.com) commented 2026-08-25 14:07:30 +00:00

in f26586b91de16a03d4c265a7e8ee9fefb728dd65 Test: bumpfee does not backdate the locktime

Missing commas between arguments, probably True con go with verbose=True so it is easier to understand.

in f26586b91de16a03d4c265a7e8ee9fefb728dd65 Test: bumpfee does not backdate the locktime Missing commas between arguments, probably True con go with `verbose=True` so it is easier to understand.
molnard (Migrated from github.com) reviewed 2026-08-26 09:07:54 +00:00
molnard (Migrated from github.com) left a comment

Concept ACK.

I think this can be simplified by enforcing the replacement-specific invariant in CreateRateBumpTransaction() (feebumper.cpp), after creation and before signing. It avoids adding state to CCoinControl, preserves the existing random distribution, and covers stale and previous_locktime > block_height cases that the current implementation misses.

The test appears flaky: current_height is incremented without mining, so the loop exits after one iteration, and unpatched code could pass often.

Concept ACK. I think this can be simplified by enforcing the replacement-specific invariant in `CreateRateBumpTransaction()` (feebumper.cpp), after creation and before signing. It avoids adding state to CCoinControl, preserves the existing random distribution, and covers stale and `previous_locktime > block_height` cases that the current implementation misses. The test appears flaky: `current_height` is incremented without mining, so the loop exits after one iteration, and unpatched code could pass often.
molnard (Migrated from github.com) commented 2026-08-26 08:46:21 +00:00

CCoinControl describes how a new transaction should be constructed - but m_previous_locktime is different. A normal transaction has no previous transaction. The concept exists only because CreateRateBumpTransaction() is constructing an RBF replacement.

There is a hidden coupling now. The generic transaction builder must now understand a fee-bumping detail => maintenance complexity later.

What if we try to find better ownership for this fee-bump-specific improvement? The fee-bumper already possesses both values, so it could enforce the relationship locally:

mtx = CMutableTransaction(*txr.tx);

if (!coin_control.m_locktime &&
    tx->nLockTime < LOCKTIME_THRESHOLD) {
    mtx.nLockTime =
        std::max(mtx.nLockTime, tx->nLockTime);
}

The generic builder creates a normal transaction. The fee-bumper then applies the replacement-specific invariant before signing.

`CCoinControl `describes how a new transaction should be constructed - but `m_previous_locktime` is different. A normal transaction has no previous transaction. The concept exists only because `CreateRateBumpTransaction()` is constructing an RBF replacement. There is a hidden coupling now. The generic transaction builder must now understand a fee-bumping detail => maintenance complexity later. What if we try to find better ownership for this fee-bump-specific improvement? The fee-bumper already possesses both values, so it could enforce the relationship locally: ``` mtx = CMutableTransaction(*txr.tx); if (!coin_control.m_locktime && tx->nLockTime < LOCKTIME_THRESHOLD) { mtx.nLockTime = std::max(mtx.nLockTime, tx->nLockTime); } ``` The generic builder creates a normal transaction. The fee-bumper then applies the replacement-specific invariant before signing.
molnard (Migrated from github.com) commented 2026-08-26 08:24:47 +00:00

When minimum_height is greater, nothing happens. The transaction keeps the already assigned block_height,, which is below the declared minimum.

This can happen, for example, if:

  • The chain has moved backward after a reorganization or manual invalidateblock.
  • The original wallet transaction was dropped or never broadcast.
  • The original transaction was created with a future height locktime.
When `minimum_height` is greater, nothing happens. The transaction keeps the already assigned `block_height,`, which is below the declared minimum. This can happen, for example, if: - The chain has moved backward after a reorganization or manual `invalidateblock`. - The original wallet transaction was dropped or never broadcast. - The original transaction was created with a future height locktime.
molnard (Migrated from github.com) commented 2026-08-26 08:35:48 +00:00

A true lower-bound implementation would retain the original distribution.

Example: rng_fast.randrange(50) => 0...49.

Therefore, the subtraction can never reach or cross minimum_height.

A true lower-bound implementation would retain the original distribution. Example: `rng_fast.randrange(50)` => 0...49. Therefore, the subtraction can never reach or cross `minimum_height`.
molnard (Migrated from github.com) commented 2026-08-26 08:13:54 +00:00

Suppose the original tx nLockTime is 96400. The node goes offline for more than 8 hours, and the user calls bumpfee. The PR passes 9640 into DiscourageFeeSniping() but the chain considered stale, so the execution goes directly to tx.nLockTime = 0;.
Therefore:

original:    900,000
replacement:       0
Suppose the original tx `nLockTime` is 96400. The node goes offline for more than 8 hours, and the user calls `bumpfee`. The PR passes 9640 into `DiscourageFeeSniping()` but the chain considered stale, so the execution goes directly to `tx.nLockTime = 0;`. Therefore: ``` original: 900,000 replacement: 0 ```
molnard (Migrated from github.com) commented 2026-08-26 08:56:21 +00:00

Small chance to that the test can pass with the unpatched code, when the first nonzero random backdate is only one or two blocks.

Small chance to that the test can pass with the unpatched code, when the first nonzero random backdate is only one or two blocks.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:18:07 +00:00
Lines 1034-1039
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:18:07 +00:00

Also, when minimum_height == 0, we retain the prior behavior and backdate at most 99 blocks from tip. When minimum_height > 0, we should use the full inclusive window without the 100 block cap.

The idea here is to avoid backdating when using bumpfee, without making these changes distinguishable from other transactions that use antifee sniping. If we were to use only minimum_height as the inclusive window, we could end up with replacements with a locktime more than 100 blocks behind the current tip. That would be easily fingerprintable as coming from Core, which is exactly what we want to avoid.

> Also, when `minimum_height == 0`, we retain the prior behavior and backdate at most 99 blocks from tip. When `minimum_height > 0`, we should use the full inclusive window without the 100 block cap. The idea here is to avoid backdating when using `bumpfee`, without making these changes distinguishable from other transactions that use antifee sniping. If we were to use only `minimum_height` as the inclusive window, we could end up with replacements with a locktime more than 100 blocks behind the current tip. That would be easily fingerprintable as coming from Core, which is exactly what we want to avoid.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:20:55 +00:00
Lines 1036-1038
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:20:55 +00:00

In the case where we're fee bumping an already-nLockTimed tx, we should not reset its nLockTime back below that established minimum_height. Otherwise we fingerprint the tx. minimum_height defaults to 0, so new sends on a stale chain still retain the prior behavior of nLockTime = 0.

The only time when this can happen is if the node is still downloading blocks or if the last block is from more than 8 horus ago. This males the block_height unrelaibale to compre and it could happen that minimum_height is greater than the block_height beacuse we don't have blockchain up to date. This could lead to setting a transaction with a locktime to 0 because even though minimum_height is less than the current block tip becasue the blockhain is not up to date. Example: We have the originstl transaction txA with locktime 12. The current tip is 15 but the node has only downloaded till 10. If we replace the transaction, that would set the locktime to 0 (since minimum_height is 12 and current_height is 10), and with that logic this would tell that the node is not up to date. Plus I do not belive that setting the rpelacement set to 0 fingerprints the transactions as there are lots of wallets than when bumping fee set the locktime to 0.

> In the case where we're fee bumping an already-nLockTimed tx, we should not reset its nLockTime back below that established minimum_height. Otherwise we fingerprint the tx. minimum_height defaults to 0, so new sends on a stale chain still retain the prior behavior of nLockTime = 0. The only time when this can happen is if the node is still downloading blocks or if the last block is from more than 8 horus ago. This males the `block_height` unrelaibale to compre and it could happen that `minimum_height` is greater than the `block_height` beacuse we don't have blockchain up to date. This could lead to setting a transaction with a locktime to 0 because even though `minimum_height` is less than the current block tip becasue the blockhain is not up to date. Example: We have the originstl transaction `txA` with locktime 12. The current tip is 15 but the node has only downloaded till 10. If we replace the transaction, that would set the locktime to 0 (since `minimum_height` is 12 and `current_height` is 10), and with that logic this would tell that the node is not up to date. Plus I do not belive that setting the rpelacement set to 0 fingerprints the transactions as there are lots of wallets than when bumping fee set the locktime to 0.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:21:48 +00:00
Lines 1036-1038
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:21:48 +00:00

In the case where the minimum_height is ahead of the local tip, set nLockTime = 0

But that would disable the antifee sniping completly, wouldn't it be beeter to leave the locktime in the current_tip? That way we are still antifee sniping.

> In the case where the minimum_height is ahead of the local tip, set nLockTime = 0 ~~But that would disable the antifee sniping completly, wouldn't it be beeter to leave the locktime in the `current_tip`? That way we are still antifee sniping.~~
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:22:36 +00:00
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:22:36 +00:00

Is this if needed? can we have a block_height smaller than the minimum_height? I think at least we will always be at the minimum_height, I can only think of a re-org, but then we must swich to a chain with more PoW so the height will likely be higher too.

If the original transaction has a final sequence number and a locktime greater than the current tip, the locktime is not enforced because of the sequence number, so the transaction is valid with a locktime far greater than the current tip. This would make minimum_height in the replacement greater than the current tip. This is the only case I can think of. The other solution would be to check the sequence number of the original transaction.

> Is this if needed? can we have a `block_height` smaller than the `minimum_height`? I think at least we will always be at the `minimum_height`, I can only think of a re-org, but then we must swich to a chain with more PoW so the height will likely be higher too. If the original transaction has a final sequence number and a locktime greater than the current tip, the locktime is not enforced because of the sequence number, so the transaction is valid with a locktime far greater than the current tip. This would make `minimum_height` in the replacement greater than the current tip. This is the only case I can think of. The other solution would be to check the sequence number of the original transaction.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:23:33 +00:00
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:23:33 +00:00

I'm not sure if doing it like this is a good idea. When backdating, if we apply this, the Discuragefeesniping will give a locktime between the [current_height, current_height-100], and most of the times this locktime will be older than the previous locktime since most of replacements are done after a few blocks. That means that we will have either a replacement transaction with a locktime set on the current_height or on the previous lockitme most of the time. If we keep the current logic, we'll have a more diverse distribution of locktimes for replacement transactions.

I'm not sure if doing it like this is a good idea. When backdating, if we apply this, the Discuragefeesniping will give a locktime between the `[current_height, current_height-100]`, and most of the times this locktime will be older than the previous locktime since most of replacements are done after a few blocks. That means that we will have either a replacement transaction with a locktime set on the current_height or on the previous lockitme most of the time. If we keep the current logic, we'll have a more diverse distribution of locktimes for replacement transactions.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:24:08 +00:00
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:24:08 +00:00

Fixed in c72998bc4e

Fixed in c72998bc4e
Bicaru20 commented 2026-08-28 10:24:41 +00:00 (Migrated from github.com)

Thanks for the reviews!

  • c72998bc4e: Fix the nits. Also applied Pol suggestion to simplify the code in Discuragefeesniping and at the same time fixing the OBO problem.
  • f911ae8345: Add verbose=True

For now putting the pr as a draft. Seeing some of the feedback I see now that the functional test is weak and that a unit test is better. Once the unit test is completed I will open the pr again.
During this time, feel free to respond to my replies to your comments so we can agree on the best approach.

Thanks for the reviews! - c72998bc4e: Fix the nits. Also applied Pol suggestion to simplify the code in `Discuragefeesniping` and at the same time fixing the OBO problem. - f911ae8345: Add `verbose=True` For now putting the pr as a draft. Seeing some of the feedback I see now that the functional test is weak and that a unit test is better. Once the unit test is completed I will open the pr again. During this time, feel free to respond to my replies to your comments so we can agree on the best approach.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:26:20 +00:00
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:26:20 +00:00
I think that is how it should be. See my previous answer: https://github.com/bitcoin/bitcoin/pull/36040#discussion_r3879830139
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:29:07 +00:00
Lines 1036-1038
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:29:07 +00:00

In the case where the minimum_height is ahead of the local tip, set nLockTime = 0

You're right about this one, otherwise we would be setting a locktime older than the original transaction.

> In the case where the minimum_height is ahead of the local tip, set nLockTime = 0 You're right about this one, otherwise we would be setting a locktime older than the original transaction.
Bicaru20 (Migrated from github.com) reviewed 2026-08-28 10:29:42 +00:00
Bicaru20 (Migrated from github.com) commented 2026-08-28 10:29:42 +00:00

Yes, you're rigth. I will fix it.

Yes, you're rigth. I will fix it.
danielabrozzoni (Migrated from github.com) reviewed 2026-08-28 14:14:09 +00:00
Lines 1036-1038
danielabrozzoni (Migrated from github.com) commented 2026-08-28 14:14:09 +00:00

In the case where we're fee bumping an already-nLockTimed tx, we should not reset its nLockTime back below that established minimum_height. Otherwise we fingerprint the tx.

I think this makes sense. For example:

  • Current block height is 15, we create txA with locktime = 15
  • A few more blocks come in, txA is not included in any, but we fall behind the tip
  • We want to replace txA with txB; minimum_height = 15. Here we could either: a) set txB's locktime to 0, or b) set txB's locktime to minimum_height

If we go with a), an observer would say that we are either:

  1. using a walelt that does anti-feesniping, but sets nlocktime to 0 when feebumping (assume there are any, I'm not sure)
  2. using Bitcoin Core or equivalent, but we're not synced to the tip.
    In the imaginary future where we all use the same exact anti-fee sniping strategy, 1. doesn't exist, and the observer would notice we're not synced to the tip

If we go with b), an observer would say that we are either:

  1. using a wallet that does anti-fee sniping on txs and replacements
  2. using some protocol based on presigned transactions that had a locktime set (and there's no fee sniping at all)

The reason 2. wouldn't exist in case a) is that it's pretty weird that in a protocol that uses locktime, a txA has a locktime, but its replacement doesn't.

> In the case where we're fee bumping an already-nLockTimed tx, we should not reset its nLockTime back below that established minimum_height. Otherwise we fingerprint the tx. I think this makes sense. For example: - Current block height is 15, we create `txA` with `locktime = 15` - A few more blocks come in, `txA` is not included in any, but we fall behind the tip - We want to replace txA with txB; `minimum_height = 15`. Here we could either: a) set txB's locktime to `0`, or b) set txB's locktime to `minimum_height` If we go with a), an observer would say that we are either: 1. using a walelt that does anti-feesniping, but sets nlocktime to 0 when feebumping (assume there are any, I'm not sure) 2. using Bitcoin Core or equivalent, but we're not synced to the tip. In the imaginary future where we all use the same exact anti-fee sniping strategy, 1. doesn't exist, and the observer would notice we're not synced to the tip If we go with b), an observer would say that we are either: 1. using a wallet that does anti-fee sniping on txs and replacements 2. using some protocol based on presigned transactions that had a locktime set (and there's no fee sniping at all) The reason 2. wouldn't exist in case a) is that it's pretty weird that in a protocol that uses locktime, a txA has a locktime, but its replacement doesn't.
molnard (Migrated from github.com) reviewed 2026-09-01 11:26:17 +00:00
Lines 1036-1038
molnard (Migrated from github.com) commented 2026-09-01 11:26:17 +00:00

I agree with the axiom of replacement.nLockTime >= original.nLockTime in any case. Good privacy strategy: do not reveal more than you already had, if possible.

Following that, the solution of setting replacement.nLockTime = original.nLockTime preserves the information already visible in the original, while other solutions introduce a new, unusual transition - since we cannot do better because our chain is stale.

I agree with the axiom of `replacement.nLockTime >= original.nLockTime` in any case. Good privacy strategy: do not reveal more than you already had, if possible. Following that, the solution of setting `replacement.nLockTime = original.nLockTime` preserves the information already visible in the original, while other solutions introduce a new, unusual transition - since we cannot do better because our chain is stale.
molnard (Migrated from github.com) reviewed 2026-09-01 11:30:40 +00:00
molnard (Migrated from github.com) commented 2026-09-01 11:30:40 +00:00

Fair point—the std::max() example may not be the right implementation.

My main point was architectural rather than about that exact implementation. What do you think about keeping this replacement-specific behavior in CreateRateBumpTransaction()? The fee-bumper owns both the original and replacement transactions and therefore knows the invariant it must enforce.

We could still generate the locktime using the desired distribution, possibly through a shared helper, while avoiding m_previous_locktime in the generic CCoinControl and keeping the generic transaction builder unaware of RBF history.

Fair point—the `std::max()` example may not be the right implementation. My main point was architectural rather than about that exact implementation. What do you think about keeping this replacement-specific behavior in `CreateRateBumpTransaction()`? The fee-bumper owns both the original and replacement transactions and therefore knows the invariant it must enforce. We could still generate the locktime using the desired distribution, possibly through a shared helper, while avoiding `m_previous_locktime` in the generic `CCoinControl` and keeping the generic transaction builder unaware of RBF history.
Bicaru20 (Migrated from github.com) reviewed 2026-09-08 21:18:17 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-08 21:18:17 +00:00

I'd rather keep all the anti fee sniping logic inside the Discuragefeesniping. I think this way it is easier to follow the code and not delegate part of this logic outside the function because of the RBF case. I feel that otherwise we would be duplicating code when the current approach just needs the m_previous_locktime in CCoinControl.

I'd rather keep all the anti fee sniping logic inside the `Discuragefeesniping`. I think this way it is easier to follow the code and not delegate part of this logic outside the function because of the RBF case. I feel that otherwise we would be duplicating code when the current approach just needs the `m_previous_locktime` in `CCoinControl`.
DrahtBot commented 2026-09-08 22:00:23 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task OpenBSD Cross: https://github.com/bitcoin/bitcoin/actions/runs/34280727979/job/102244563839
LLM reason (✨ experimental): CI failed due to a Clang build error from -Wthread-safety-analysis/-Werror in wallet/test/spend_tests.cpp (calling chainman->ActiveChain() without exclusively holding cs_main).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `OpenBSD Cross`: https://github.com/bitcoin/bitcoin/actions/runs/34280727979/job/102244563839</sub> <sub>LLM reason (✨ experimental): CI failed due to a Clang build error from `-Wthread-safety-analysis`/`-Werror` in `wallet/test/spend_tests.cpp` (calling `chainman->ActiveChain()` without exclusively holding `cs_main`).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
Bicaru20 commented 2026-09-08 22:06:27 +00:00 (Migrated from github.com)

Changes made:

  • cc8f4784cf: I adpoted @nervana21 suggestion. Now we don't reset the nLocktime below the established minimum_height even if we are on a stal chain. The only case when we reset the nlocktime to 0 is if the minimum_height is higher than the current block_height. In this case, we set it to 0.

  • 903d2bfa67: I've eliminated the functional test and added a unit test in the spend_tests.cpp of the wallet. I added the following cases:

    1. First, the case to check that the backdating when having a minimum_height occurs between the expected range ([minimum_height, block_height]).
    2. Second, the case to check that the backdating can reach the minimum_height. This way we prove that the OBO error is not there and also check that when calculating the range in spend.cpp this is not 0 as this would cause an error later on rng_fast.randrange(range).
    3. Third, the case where the minimum_height > block_height. In this case we set the locktime to 0.
    4. Fourth, the case where we have a stale chain and minimum_height <= block_height, in this case we set the locktime to minimum_height
    5. Finally, the case where we have a stale chain and minimum_height > block_height, in this case we set the locktime to 0.
Changes made: - cc8f4784cf9ba77fb22209adbfa9c2176b82228a: I adpoted @nervana21 suggestion. Now we don't reset the `nLocktime` below the established `minimum_height` even if we are on a stal chain. The only case when we reset the `nlocktime` to 0 is if the `minimum_height` is higher than the current `block_height`. In this case, we set it to 0. - 903d2bfa675f1acfc24e21fbbeff9ceb8b0e019e: I've eliminated the functional test and added a unit test in the `spend_tests.cpp` of the wallet. I added the following cases: 1. First, the case to check that the backdating when having a minimum_height occurs between the expected range (`[minimum_height, block_height]`). 2. Second, the case to check that the backdating can reach the `minimum_height`. This way we prove that the OBO error is not there and also check that when calculating the `range` in `spend.cpp` this is not 0 as this would cause an error later on `rng_fast.randrange(range)`. 3. Third, the case where the `minimum_height` > `block_height`. In this case we set the locktime to 0. 4. Fourth, the case where we have a stale chain and `minimum_height` <= `block_height`, in this case we set the locktime to `minimum_height` 5. Finally, the case where we have a stale chain and `minimum_height` > `block_height`, in this case we set the locktime to 0.
molnard (Migrated from github.com) reviewed 2026-09-09 10:45:37 +00:00
molnard (Migrated from github.com) commented 2026-09-09 10:45:37 +00:00

I looked more closely at the approach I suggested. Although it separates the replacement-specific behavior a bit more cleanly and avoids adding a field to CCoinControl, it introduces complexity elsewhere.

Your approach fits the existing code structure better, and I think the extra complexity of the separation outweighs its benefits here.

Thanks for taking the time to consider it.

I looked more closely at the approach I suggested. Although it separates the replacement-specific behavior a bit more cleanly and avoids adding a field to `CCoinControl`, it introduces complexity elsewhere. Your approach fits the existing code structure better, and I think the extra complexity of the separation outweighs its benefits here. Thanks for taking the time to consider it.
molnard (Migrated from github.com) reviewed 2026-09-09 12:11:47 +00:00
molnard (Migrated from github.com) left a comment

Concept ACK.

I ran all new and modified tests locally, and they passed. I've left my test-related comments inline.

Concept ACK. I ran all new and modified tests locally, and they passed. I've left my test-related comments inline.
molnard (Migrated from github.com) commented 2026-09-09 12:04:50 +00:00

nit:

With minimum_height == 0, this also changes the locktime distribution for ordinary sends when the chain height is below 99, short chains (like regtest).

For example, at height 2, the old code samples an offset from [0, 99] and clamps negative results to zero. Within the 10% random branch, offset 0 gives locktime 2, offset 1 gives locktime 1, and offsets 2–99 all give locktime 0. Zero therefore has a 98% probability within that branch.

The new code samples an offset from [0, 2], so locktimes 0, 1, and 2 each have a one-third probability within the random branch. The possible locktimes are the same, but their probabilities are different. The 90% branch that uses the current height is unchanged.

Is this intentional? I think this is good as it is, I just wanted to point out the change.

nit: With `minimum_height == 0`, this also changes the locktime distribution for ordinary sends when the chain height is below 99, short chains (like regtest). For example, at height 2, the old code samples an offset from `[0, 99]` and clamps negative results to zero. Within the 10% random branch, offset 0 gives locktime 2, offset 1 gives locktime 1, and offsets 2–99 all give locktime 0. Zero therefore has a 98% probability within that branch. The new code samples an offset from `[0, 2]`, so locktimes 0, 1, and 2 each have a one-third probability within the random branch. The possible locktimes are the same, but their probabilities are different. The 90% branch that uses the current height is unchanged. Is this intentional? I think this is good as it is, I just wanted to point out the change.
molnard (Migrated from github.com) commented 2026-09-09 11:54:04 +00:00

Could you add a case with minimum_height greater than 99 blocks below the tip? The current tests use gaps of only 1 and 10 blocks, so they wouldn't catch the removal of the 100-value cap. On a current chain, the locktime should still stay within [block_height - 99, block_height].

Could you add a case with `minimum_height` greater than 99 blocks below the tip? The current tests use gaps of only 1 and 10 blocks, so they wouldn't catch the removal of the 100-value cap. On a current chain, the locktime should still stay within `[block_height - 99, block_height]`.
molnard (Migrated from github.com) commented 2026-09-09 11:48:01 +00:00

Could you add a test covering the full modified path, starting with passing the original locktime through CCoinControl? The current tests call DiscourageFeeSniping() directly, so they would still pass if the original locktime were no longer forwarded.

A wallet unit test that calls CreateRateBumpTransaction() should be enough. Using a stale tip and an original height-based locktime below the tip would make the check deterministic: the replacement should retain the original locktime rather than fall back to zero.

Could you add a test covering the full modified path, starting with passing the original locktime through `CCoinControl`? The current tests call `DiscourageFeeSniping()` directly, so they would still pass if the original locktime were no longer forwarded. A wallet unit test that calls `CreateRateBumpTransaction()` should be enough. Using a stale tip and an original height-based locktime below the tip would make the check deterministic: the replacement should retain the original locktime rather than fall back to zero.
molnard (Migrated from github.com) commented 2026-09-09 11:51:09 +00:00

Could we use an explicitly fixed RNG seed here and verify that the resulting sequence reaches the minimum within the iteration limit? The test can fail even with correct code if none of the 200 attempts succeed (even though the chances are low - thinking long term).

Could we use an explicitly fixed RNG seed here and verify that the resulting sequence reaches the minimum within the iteration limit? The test can fail even with correct code if none of the 200 attempts succeed (even though the chances are low - thinking long term).
nervana21 (Migrated from github.com) reviewed 2026-09-09 20:22:11 +00:00
nervana21 (Migrated from github.com) commented 2026-09-09 20:07:43 +00:00

903d2bfa67: Test: bumpfee does not backdate the locktime

nit: these should be alphabetized with the rest of the includes

903d2bfa675f1acfc24e21fbbeff9ceb8b0e019e: Test: bumpfee does not backdate the locktime nit: these should be alphabetized with the rest of the includes
nervana21 (Migrated from github.com) commented 2026-09-09 20:20:03 +00:00

903d2bfa67: Test: bumpfee does not backdate the locktime

    bool backdated{false};
    bool saw_tip_locktime{false};
    for (int i{0}; i < 200; ++i) {
        DiscourageFeeSniping(mtx, rng_fast, chain, block_hash, block_height, block_height - 10);
        BOOST_CHECK_LE(mtx.nLockTime, static_cast<uint32_t>(block_height));
        BOOST_CHECK_GE(mtx.nLockTime, static_cast<uint32_t>(block_height - 10));
        if (mtx.nLockTime == static_cast<uint32_t>(block_height)) {
            saw_tip_locktime = true;
        } else {
            backdated = true;
        }
        if (backdated && saw_tip_locktime) break;
    }
    BOOST_CHECK(backdated);
    BOOST_CHECK(saw_tip_locktime);

Would it make sense to strengthen this test to check not only that we backdated but also check that we left the locktime unchanged?

903d2bfa675f1acfc24e21fbbeff9ceb8b0e019e: Test: bumpfee does not backdate the locktime ```suggestion bool backdated{false}; bool saw_tip_locktime{false}; for (int i{0}; i < 200; ++i) { DiscourageFeeSniping(mtx, rng_fast, chain, block_hash, block_height, block_height - 10); BOOST_CHECK_LE(mtx.nLockTime, static_cast<uint32_t>(block_height)); BOOST_CHECK_GE(mtx.nLockTime, static_cast<uint32_t>(block_height - 10)); if (mtx.nLockTime == static_cast<uint32_t>(block_height)) { saw_tip_locktime = true; } else { backdated = true; } if (backdated && saw_tip_locktime) break; } BOOST_CHECK(backdated); BOOST_CHECK(saw_tip_locktime); ``` Would it make sense to strengthen this test to check not only that we backdated but also check that we left the locktime unchanged?
nervana21 commented 2026-09-09 20:23:41 +00:00 (Migrated from github.com)

Thanks for taking the suggestions. I've left just a few more comments.

Thanks for taking the suggestions. I've left just a few more comments.
nervana21 (Migrated from github.com) reviewed 2026-09-09 22:14:48 +00:00
nervana21 (Migrated from github.com) commented 2026-09-09 22:14:48 +00:00

903d2bfa67: Test: bumpfee does not backdate the locktime

    // Verify DiscourageFeeSniping on a stale tip when minimum_height is set.

nit: wording

903d2bfa675f1acfc24e21fbbeff9ceb8b0e019e: Test: bumpfee does not backdate the locktime ```suggestion // Verify DiscourageFeeSniping on a stale tip when minimum_height is set. ``` nit: wording
Bicaru20 (Migrated from github.com) reviewed 2026-09-12 17:33:13 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-12 17:33:13 +00:00

Is this intentional? I think this is good as it is, I just wanted to point out the change.

I didn't though of that case, but I don't think it matters since in new chains you can start spending the UTXOs in block 101, and by then this is not a problem anymore.

> Is this intentional? I think this is good as it is, I just wanted to point out the change. I didn't though of that case, but I don't think it matters since in new chains you can start spending the UTXOs in block 101, and by then this is not a problem anymore.
Bicaru20 (Migrated from github.com) reviewed 2026-09-12 17:34:09 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-12 17:34:09 +00:00

Done! Added a test in feebumper_test.cpp which bumps a transaction directly through CreateRateBumpTransaction.

Done! Added a test in feebumper_test.cpp which bumps a transaction directly through `CreateRateBumpTransaction`.
Bicaru20 (Migrated from github.com) reviewed 2026-09-12 17:34:24 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-12 17:34:24 +00:00

Yes, I think it makes sense to use a fixed rng seed. Thanks for pointing it out!

Yes, I think it makes sense to use a fixed rng seed. Thanks for pointing it out!
Bicaru20 (Migrated from github.com) reviewed 2026-09-12 17:34:47 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-12 17:34:47 +00:00

Done! I modified the discourage_fee_sniping_backdating_bounds first test so the minimum_height is greater than the 100 block limit.

Done! I modified the `discourage_fee_sniping_backdating_bounds` first test so the `minimum_height` is greater than the 100 block limit.
Bicaru20 (Migrated from github.com) reviewed 2026-09-12 17:35:08 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-12 17:35:08 +00:00

Yes, I think it doesnt hurt and makes the test more robust.

Yes, I think it doesnt hurt and makes the test more robust.
Bicaru20 (Migrated from github.com) reviewed 2026-09-12 17:35:19 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-12 17:35:19 +00:00

Done!

Done!
Bicaru20 commented 2026-09-12 17:39:38 +00:00 (Migrated from github.com)

Thanks again for the reviews!

  • In b72a0533da:
    • I added a test in feebumper_test.cpp (since we use feebumper logic) which bumps a transaction directly through CreateRateBumpTransaction. As suggested by @molnard, we do it on a stale chain so we can check if the previous lockitme is propagated to the new tx.
    • In the test discourage_fee_sniping_backdating_bounds I added a fixed rng seed and modified the first test so the minimum_height is greater than the 100 block limit.
    • Also added saw_tip_locktime check suggested by @nervana21
Thanks again for the reviews! - In b72a0533dac88b46755f9ee1051eb588b1934050: - I added a test in `feebumper_test.cpp` (since we use feebumper logic) which bumps a transaction directly through `CreateRateBumpTransaction`. As suggested by @molnard, we do it on a stale chain so we can check if the previous lockitme is propagated to the new tx. - In the test `discourage_fee_sniping_backdating_bounds` I added a fixed rng seed and modified the first test so the `minimum_height` is greater than the 100 block limit. - Also added `saw_tip_locktime` check suggested by @nervana21
molnard (Migrated from github.com) reviewed 2026-09-14 10:00:55 +00:00
molnard (Migrated from github.com) left a comment

ACK b72a0533da with nits.

The code looks good. I've left a couple of minor comments on the tests.

ACK b72a0533dac88b46755f9ee1051eb588b1934050 with nits. The code looks good. I've left a couple of minor comments on the tests.
molnard (Migrated from github.com) commented 2026-09-14 09:48:19 +00:00

Shouldn't this be [block_height - 99, block_height]? randrange(100) returns values from 0 to 99, so the maximum backdate is 99 blocks. Including the current height, that gives 100 possible locktimes.

The BOOST_CHECK_GE below should also use block_height - 99; otherwise it allows a 100-block backdate.

Shouldn't this be `[block_height - 99, block_height]`? `randrange(100)` returns values from 0 to 99, so the maximum backdate is 99 blocks. Including the current height, that gives 100 possible locktimes. The `BOOST_CHECK_GE` below should also use `block_height - 99`; otherwise it allows a 100-block backdate.
molnard (Migrated from github.com) commented 2026-09-14 09:58:51 +00:00

Could we remove the break and run all 200 iterations? This would check more generated locktimes against both bounds and could catch regressions from future changes that the early exit would miss. We can still check backdated and saw_tip_locktime after the loop.

For example, with the current fixed seed, the first four locktimes are 111, 111, 111, 17, even if we remove the std::min(100, ...) cap. The loop exits there and misses the regression. In a standalone reproduction using Core's RNG, continuing the loop catches a violation of the 99-block bound on call 37.

Could we remove the `break` and run all 200 iterations? This would check more generated locktimes against both bounds and could catch regressions from future changes that the early exit would miss. We can still check `backdated` and `saw_tip_locktime` after the loop. For example, with the current fixed seed, the first four locktimes are `111, 111, 111, 17`, even if we remove the `std::min(100, ...)` cap. The loop exits there and misses the regression. In a standalone reproduction using Core's RNG, continuing the loop catches a violation of the 99-block bound on call 37.
nervana21 (Migrated from github.com) reviewed 2026-09-14 16:55:49 +00:00
nervana21 (Migrated from github.com) commented 2026-09-14 16:55:49 +00:00

b72a0533da: Test: bumpfee does not backdate the locktime

    // Mine one more block so one coinbase is mature, then sync a spendable wallet.
    CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
    auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey);

    std::vector<CRecipient> recipients{{*Assert(wallet->GetNewDestination(OutputType::BECH32, "dummy")),
                                        /*nAmount=*/40 * COIN, /*fSubtractFeeFromAmount=*/true}};

    auto res = CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, CCoinControl{});

Since we're only dealing with a single coinbase coin, I think this can be simplified.

b72a0533dac88b46755f9ee1051eb588b1934050: Test: bumpfee does not backdate the locktime ```suggestion // Mine one more block so one coinbase is mature, then sync a spendable wallet. CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey); std::vector<CRecipient> recipients{{*Assert(wallet->GetNewDestination(OutputType::BECH32, "dummy")), /*nAmount=*/40 * COIN, /*fSubtractFeeFromAmount=*/true}}; auto res = CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, CCoinControl{}); ``` Since we're only dealing with a single coinbase coin, I think this can be simplified.
nervana21 (Migrated from github.com) reviewed 2026-09-14 16:57:01 +00:00
nervana21 (Migrated from github.com) commented 2026-09-14 16:57:01 +00:00

b72a0533da: Test: bumpfee does not backdate the locktime

    // Rate bump with a stale tip: keep the original transaction's locktime.

nit

b72a0533dac88b46755f9ee1051eb588b1934050: Test: bumpfee does not backdate the locktime ```suggestion // Rate bump with a stale tip: keep the original transaction's locktime. ``` nit
nervana21 (Migrated from github.com) reviewed 2026-09-14 16:57:58 +00:00
nervana21 (Migrated from github.com) commented 2026-09-14 16:57:58 +00:00

b72a0533da: Test: bumpfee does not backdate the locktime

    auto bump_res = feebumper::CreateRateBumpTransaction(*wallet, txr.tx->GetHash(), CCoinControl{}, errors, old_fee, new_fee, mtx, /*require_mine=*/false, /*outputs=*/{});

as above

b72a0533dac88b46755f9ee1051eb588b1934050: Test: bumpfee does not backdate the locktime ```suggestion auto bump_res = feebumper::CreateRateBumpTransaction(*wallet, txr.tx->GetHash(), CCoinControl{}, errors, old_fee, new_fee, mtx, /*require_mine=*/false, /*outputs=*/{}); ``` as above
Bicaru20 (Migrated from github.com) reviewed 2026-09-15 11:46:35 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-15 11:46:35 +00:00

True, I got confussed when writing the comments. Thnaks!

True, I got confussed when writing the comments. Thnaks!
Bicaru20 (Migrated from github.com) reviewed 2026-09-15 11:46:38 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-15 11:46:38 +00:00

Agreed, it makes sense.

Agreed, it makes sense.
Bicaru20 (Migrated from github.com) reviewed 2026-09-15 11:58:04 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-15 11:58:04 +00:00

True, thisway is better. Thanks!

True, thisway is better. Thanks!
Bicaru20 (Migrated from github.com) reviewed 2026-09-15 12:30:57 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-15 12:30:57 +00:00

Done!

Done!
Bicaru20 (Migrated from github.com) reviewed 2026-09-15 12:31:04 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-15 12:31:04 +00:00

Done!

Done!
Bicaru20 commented 2026-09-15 12:33:59 +00:00 (Migrated from github.com)

Changes made:

  • Reduced the bump_transaction_fee_sniping_check test in feebumper_test as suggested by @nervana21
  • In discourage_fee_sniping_backdating_bounds I eliminated the breaks and change the 100 for a 99 as @molnard suggested.
Changes made: - Reduced the `bump_transaction_fee_sniping_check` test in feebumper_test as suggested by @nervana21 - In `discourage_fee_sniping_backdating_bounds` I eliminated the breaks and change the 100 for a 99 as @molnard suggested.
molnard commented 2026-09-15 20:53:22 +00:00 (Migrated from github.com)

ACK e34f9340d6

Checked the code and ran the tests - all good.

ACK e34f9340d615976b1398e6ead0ab8d2bda24907c Checked the code and ran the tests - all good.
nervana21 (Migrated from github.com) reviewed 2026-09-16 14:28:14 +00:00
Lines 193-195
nervana21 (Migrated from github.com) commented 2026-09-16 14:28:14 +00:00

675448e262: Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

 * The locktime is occasionally backdated, but never below minimum_height
 * and at most 99 blocks below the tip.

nit

675448e26225d2d82b363a508048dc7819037219: Wallet: Do not allow bumpfee to backdate the replacement transaction locktime ```suggestion * The locktime is occasionally backdated, but never below minimum_height * and at most 99 blocks below the tip. ``` nit
nervana21 commented 2026-09-16 14:30:06 +00:00 (Migrated from github.com)

675448e262: Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

For this commit message:
lockitme -> locktime
greter -> greater

675448e26225d2d82b363a508048dc7819037219: Wallet: Do not allow bumpfee to backdate the replacement transaction locktime For this commit message: lockitme -> locktime greter -> greater
nervana21 (Migrated from github.com) reviewed 2026-09-16 14:30:54 +00:00
nervana21 (Migrated from github.com) left a comment

tACK e34f9340d6

left minor, non-blocking nits

tACK e34f9340d615976b1398e6ead0ab8d2bda24907c left minor, non-blocking nits
molnard (Migrated from github.com) reviewed 2026-09-21 19:26:13 +00:00
molnard (Migrated from github.com) left a comment

tACK e34f9340d6

Reviewed the code and ran all tests locally.

tACK e34f9340d615976b1398e6ead0ab8d2bda24907c Reviewed the code and ran all tests locally.
Bicaru20 commented 2026-09-22 09:04:05 +00:00 (Migrated from github.com)

Addressed @nervana21 nits. Just minor changes:

  • Fixed the typos in the first commit message
  • Changed the comments in spend.h
Addressed @nervana21 nits. Just minor changes: - Fixed the typos in the first commit message - Changed the comments in `spend.h`
nervana21 commented 2026-09-22 14:35:13 +00:00 (Migrated from github.com)
ACK 8836a3643bca8fce1185b0420f509dc75dae0a4a
molnard commented 2026-09-22 19:21:35 +00:00 (Migrated from github.com)
tACK https://github.com/bitcoin/bitcoin/commit/8836a3643bca8fce1185b0420f509dc75dae0a4a
achow101 (Migrated from github.com) reviewed 2026-09-25 22:21:56 +00:00
achow101 (Migrated from github.com) commented 2026-09-25 22:18:42 +00:00

In 7049f9ba51 "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime"

I suggest calling this minimum_locktime rather than previous_locktime as it's use could be for more than just dealing with replacements.

In 7049f9ba5175c278110984e4964a4c56b264f9fe "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime" I suggest calling this `minimum_locktime` rather than `previous_locktime` as it's use could be for more than just dealing with replacements.
Lines 1028-1029
achow101 (Migrated from github.com) commented 2026-09-25 22:19:19 +00:00

In 7049f9ba51 "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime"

Discussing replacements is unnecessary in this function. This does not need to care about what the callers are.

In 7049f9ba5175c278110984e4964a4c56b264f9fe "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime" Discussing replacements is unnecessary in this function. This does not need to care about what the callers are.
achow101 (Migrated from github.com) commented 2026-09-25 22:19:31 +00:00

In 7049f9ba51 "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime"

Same comment regarding referencing replacements.

In 7049f9ba5175c278110984e4964a4c56b264f9fe "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime" Same comment regarding referencing replacements.
Lines 1338-1339
achow101 (Migrated from github.com) commented 2026-09-25 22:19:50 +00:00

In 7049f9ba51 "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime"

This should be below inside of if (use_anti_fee_sniping).

In 7049f9ba5175c278110984e4964a4c56b264f9fe "Wallet: Do not allow bumpfee to backdate the replacement transaction locktime" This should be below inside of `if (use_anti_fee_sniping)`.
achow101 (Migrated from github.com) commented 2026-09-25 22:20:19 +00:00

In 8836a3643b "Test: bumpfee does not backdate the locktime"

This does not need to be a unit test. For wallet things, we prefer functional tests over unit tests wherever possible.

In 8836a3643bca8fce1185b0420f509dc75dae0a4a "Test: bumpfee does not backdate the locktime" This does not need to be a unit test. For wallet things, we prefer functional tests over unit tests wherever possible.
Bicaru20 commented 2026-09-30 16:42:18 +00:00 (Migrated from github.com)

Addressed all the comments and suggestions by @achow101:

  • fae0b2cb06: As suggested, I changed the varible name from m_previous_locktime to m_minimum_locktime. Also changed the comments in spend.cpp to avoid disccusing replacements. In spend.cpp changed a condition so it is inside if (use_anti_fee_sniping).
  • bf80b5a711: Changed the bump_transaction_fee_sniping_check unit test to functional. I modified a little the approach: Create a transaction with a locktime older by 101 blocks and then replaced it with a stale tip so the lcoktime in the replacement is the same as the original. As explained in the test, I choose to create a tx with an explicit locktime 101 blocks below the current height beacuse antifee sniping normally sets the locktime to the current height, or it backdates it by a random 0-100 blocks. So a locktime 101 blocks older can't be produced by either, so if the bumped tx has this locktime, we know it was copied from the original transaction rather than recomputed by anti-fee-sniping.
Addressed all the comments and suggestions by @achow101: - fae0b2cb06a99c427be034ac5c8351acef4f3357: As suggested, I changed the varible name from `m_previous_locktime` to `m_minimum_locktime`. Also changed the comments in `spend.cpp` to avoid disccusing replacements. In `spend.cpp` changed a condition so it is inside `if (use_anti_fee_sniping)`. - bf80b5a7114216f29485bedf9c2358c6aa1947d3: Changed the `bump_transaction_fee_sniping_check` unit test to functional. I modified a little the approach: Create a transaction with a locktime older by 101 blocks and then replaced it with a stale tip so the lcoktime in the replacement is the same as the original. As explained in the test, I choose to create a tx with an explicit locktime 101 blocks below the current height beacuse antifee sniping normally sets the locktime to the current height, or it backdates it by a random 0-100 blocks. So a locktime 101 blocks older can't be produced by either, so if the bumped tx has this locktime, we know it was copied from the original transaction rather than recomputed by anti-fee-sniping.
Bicaru20 (Migrated from github.com) reviewed 2026-09-30 16:43:16 +00:00
Bicaru20 (Migrated from github.com) commented 2026-09-30 16:43:16 +00:00

Created a functional test in wallet_bumfee.py

Created a functional test in `wallet_bumfee.py`
First-time contributor

🔵 Suggestion · Fee-bump locktime overrides use a process-fatal check

Although no current caller setting m_locktime was found, passing it through the fee-bump interface would terminate the process instead of returning a request error.

Location: src/wallet/feebumper.cpp:323 (head).

🔵 Suggestion · Timestamp-locktime originals are missing from bump coverage

The new tests miss the height/timestamp filter, so they would not catch its removal giving timestamp-locktime originals replacement locktime 0 on a fresh tip.

Location: test/functional/wallet_bumpfee.py:912 (head).

🔵 Suggestion · Locktime comments overstate the minimum and backdating bounds

The new comments describe a general minimum and a 99-block bound, but the field only controls anti-fee-sniping heights and stale tips can preserve an older locktime.

Location: src/wallet/coincontrol.h:118 (head).

🔵 Suggestion · Add a release note for the bumpfee locktime change

feebumper.cpp:322-324 changes the locktime of bumpfee replacements, a user-visible change, but there is no doc/release-notes-36040.md; developer-notes.md asks for PR-specific release notes for visible user-facing changes.

Location: src/wallet/feebumper.cpp:322 (head).

🔵 Suggestion · Test the minimum-locktime equality boundary

A single fresh-tip minimum_height == block_height check was added (spend_tests.cpp:181-183). The stale-tip test still lacks an equality case asserting the locktime equals minimum_height rather than 0, so that boundary is not covered.

Location: src/wallet/test/spend_tests.cpp:181 (head).

Review coverage was incomplete.


Reviewed: 596dd6fd88ef · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:ed3d34ba0c0b28bb281b265eaca62222aae3a796 --> <!-- ralph-head:596dd6fd88efe92133a34a0ba8d00f5f369a4bfd --> <!-- ralph-case:d64e3b8ca8c152fafe124753c711e76e571f743b047c04e8117bd561086f82ba --> **🔵 Suggestion · Fee-bump locktime overrides use a process-fatal check** Although no current caller setting `m_locktime` was found, passing it through the fee-bump interface would terminate the process instead of returning a request error. Location: [`src/wallet/feebumper.cpp:323`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/596dd6fd88efe92133a34a0ba8d00f5f369a4bfd/src/wallet/feebumper.cpp#L323>) (head). **🔵 Suggestion · Timestamp-locktime originals are missing from bump coverage** The new tests miss the height/timestamp filter, so they would not catch its removal giving timestamp-locktime originals replacement locktime 0 on a fresh tip. Location: [`test/functional/wallet_bumpfee.py:912`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/596dd6fd88efe92133a34a0ba8d00f5f369a4bfd/test/functional/wallet_bumpfee.py#L912>) (head). **🔵 Suggestion · Locktime comments overstate the minimum and backdating bounds** The new comments describe a general minimum and a 99-block bound, but the field only controls anti-fee-sniping heights and stale tips can preserve an older locktime. Location: [`src/wallet/coincontrol.h:118`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/596dd6fd88efe92133a34a0ba8d00f5f369a4bfd/src/wallet/coincontrol.h#L118>) (head). **🔵 Suggestion · Add a release note for the bumpfee locktime change** feebumper.cpp:322-324 changes the locktime of bumpfee replacements, a user-visible change, but there is no doc/release-notes-36040.md; developer-notes.md asks for PR-specific release notes for visible user-facing changes. Location: [`src/wallet/feebumper.cpp:322`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/596dd6fd88efe92133a34a0ba8d00f5f369a4bfd/src/wallet/feebumper.cpp#L322>) (head). **🔵 Suggestion · Test the minimum-locktime equality boundary** A single fresh-tip minimum_height == block_height check was added (spend_tests.cpp:181-183). The stale-tip test still lacks an equality case asserting the locktime equals minimum_height rather than 0, so that boundary is not covered. Location: [`src/wallet/test/spend_tests.cpp:181`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/596dd6fd88efe92133a34a0ba8d00f5f369a4bfd/src/wallet/test/spend_tests.cpp#L181>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`596dd6fd88ef`](<https://git.fish.foo/bitcoin/bitcoin/commit/596dd6fd88efe92133a34a0ba8d00f5f369a4bfd>) · [Full review report](<https://review.fish.foo/traces/36040-596dd6fd88efe92133a34a0ba8d00f5f369a4bfd-2111-7.html>) · [Previous reports](<https://review.fish.foo/traces/36040/>) [permalink](<https://review.fish.foo/traces/36040-596dd6fd88efe92133a34a0ba8d00f5f369a4bfd-2111-7.html>)
achow101 (Migrated from github.com) reviewed 2026-09-30 21:36:32 +00:00
achow101 (Migrated from github.com) commented 2026-09-30 21:31:17 +00:00

Stopped at fae0b2cb06 (Wallet: Do not allow bumpfee to backdate the replacement transaction locktime)

Still mentions previous locktime

Stopped at fae0b2cb06a (Wallet: Do not allow bumpfee to backdate the replacement transaction locktime) Still mentions previous locktime
achow101 (Migrated from github.com) commented 2026-09-30 21:31:41 +00:00

Stopped at fae0b2cb06 (Wallet: Do not allow bumpfee to backdate the replacement transaction locktime)

Should also be inside of if (use_anti_fee_sniping)

Stopped at fae0b2cb06a (Wallet: Do not allow bumpfee to backdate the replacement transaction locktime) Should also be inside of `if (use_anti_fee_sniping)`
Bicaru20 commented 2026-10-02 09:29:01 +00:00 (Migrated from github.com)

Done!

  • In a6bc933b3f changed the commets so previous locktime is not metioned. Also changed the comment in cointcontrol.h from //! Save the previous locktime for replacements to //! Minimum locktime for the transaction being created.
Done! - In a6bc933b3f changed the commets so previous locktime is not metioned. Also changed the comment in `cointcontrol.h` from ` //! Save the previous locktime for replacements` to `//! Minimum locktime for the transaction being created`.
polespinasa (Migrated from github.com) reviewed 2026-10-06 09:42:21 +00:00
polespinasa (Migrated from github.com) left a comment

I think we could improve the test coverage.

Functional tests only test the stale tip branch, we should also test that a normal replacement never falls below its original height locktime.

For unit tests it is testing a minimum one block below the tip, but what about minimum_height == block_height? That case can be added for current and stale tips.

I think we could improve the test coverage. Functional tests only test the stale tip branch, we should also test that a normal replacement never falls below its original height locktime. For unit tests it is testing a minimum one block below the tip, but what about `minimum_height == block_height`? That case can be added for current and stale tips.
polespinasa (Migrated from github.com) commented 2026-10-06 09:29:15 +00:00

in a6bc933b3f Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

This is not true at all, it is only an optional anti-fee-sniping minimum timestamp value. The comment seems to indicate it is always taken into account, but it can be overwritten by an explicit locktime.

in a6bc933b3fae52dda0c8c3e5930d29c8ce30d567 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime This is not true at all, it is only an optional anti-fee-sniping minimum timestamp value. The comment seems to indicate it is always taken into account, but it can be overwritten by an explicit locktime.
Lines 318-321
polespinasa (Migrated from github.com) commented 2026-10-06 09:12:14 +00:00

in a6bc933b3f Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

This if statement is unnecessary as we never set a manual locktime when replacing. So we should always store the locktime as the minimum one.

    // Save the previous locktime as the minimum value for anti fee sniping
    assert(!new_coin_control.m_locktime.has_value());
    new_coin_control.m_minimum_locktime = tx->nLockTime;
in a6bc933b3fae52dda0c8c3e5930d29c8ce30d567 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime This if statement is unnecessary as we never set a manual locktime when replacing. So we should always store the locktime as the minimum one. ```suggestion // Save the previous locktime as the minimum value for anti fee sniping assert(!new_coin_control.m_locktime.has_value()); new_coin_control.m_minimum_locktime = tx->nLockTime; ```
polespinasa (Migrated from github.com) commented 2026-10-06 09:34:55 +00:00

in a6bc933 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

block_height and minimum_height mixes signed and unsiged values before casting the result to int. I think using consistent types make that safety easier to verify.

in a6bc933 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime `block_height` and `minimum_height` mixes signed and unsiged values before casting the result to `int`. I think using consistent types make that safety easier to verify.
polespinasa (Migrated from github.com) commented 2026-10-06 09:24:18 +00:00

in a6bc933b3f Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

nit: empty jump line

in a6bc933b3fae52dda0c8c3e5930d29c8ce30d567 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime nit: empty jump line
polespinasa (Migrated from github.com) commented 2026-10-06 09:25:13 +00:00

in a6bc933 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

nit: I don't think this comment is useful at all, it is indeed saying nothing, the code is self-explainatory.

in a6bc933 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime nit: I don't think this comment is useful at all, it is indeed saying nothing, the code is self-explainatory.
polespinasa (Migrated from github.com) commented 2026-10-06 09:31:13 +00:00

in a6bc933 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime

below the best known tip.

Maybe we don't know the tip or we are stale and we backdate more than 99blocks from the real tip.

in a6bc933 Wallet: Do not allow bumpfee to backdate the replacement transaction locktime `below the best known tip`. Maybe we don't know the tip or we are stale and we backdate more than 99blocks from the real tip.
polespinasa (Migrated from github.com) commented 2026-10-06 09:36:03 +00:00

in ced45ea971 Test: bumpfee does not backdate the locktime

The range in the comment is wrong, it should be a random 0-99 blocks.

in ced45ea971369d9c3ea78ed5451929199f6fad94 Test: bumpfee does not backdate the locktime The range in the comment is wrong, it should be `a random 0-99 blocks`.
polespinasa (Migrated from github.com) commented 2026-10-06 09:38:17 +00:00

in ced45ea971 Test: bumpfee does not backdate the locktime

This is not restoring the mocktime. You should not use the tip timestamp but the node mocktime. I think you can store rbf_node.mocktime and restore to that value.

in ced45ea971369d9c3ea78ed5451929199f6fad94 Test: bumpfee does not backdate the locktime This is not restoring the mocktime. You should not use the tip timestamp but the node mocktime. I think you can store `rbf_node.mocktime` and restore to that value.
vicjuma (Migrated from github.com) reviewed 2026-10-08 18:03:43 +00:00
vicjuma (Migrated from github.com) left a comment

Concept ACK

Concept ACK
vicjuma (Migrated from github.com) commented 2026-10-08 17:58:43 +00:00

What is 11? :-) It might be even better if we know that 11 blocks are created on top of the current 100-block tip

- for (int i{0}; i < 11; ++i) {

+ constexpr int EXTRA_BLOCKS{11}
+ for (int i{0}; i < EXTRA_BLOCKS; ++i) {
What is 11? :-) It might be even better if we know that 11 blocks are created on top of the current 100-block tip ```diff - for (int i{0}; i < 11; ++i) { + constexpr int EXTRA_BLOCKS{11} + for (int i{0}; i < EXTRA_BLOCKS; ++i) { ```
Bicaru20 (Migrated from github.com) reviewed 2026-10-13 12:53:10 +00:00
Bicaru20 (Migrated from github.com) commented 2026-10-13 12:53:10 +00:00

I think it self explanatory that is an optional parametet given that it is a std__optional. On a previous version I mentioned that this is for replacemetns transactions, but other reviwers mentioned that it is better to not mention the replacements in the comments, so I am a bit unsure to put this is for anti fee sniping in the comment.

I think it self explanatory that is an optional parametet given that it is a `std__optional`. On a previous version I mentioned that this is for replacemetns transactions, but other reviwers mentioned that it is better to not mention the replacements in the comments, so I am a bit unsure to put this is for anti fee sniping in the comment.
Bicaru20 (Migrated from github.com) reviewed 2026-10-13 15:26:59 +00:00
Bicaru20 (Migrated from github.com) commented 2026-10-13 15:26:59 +00:00

Done! Instead of declaring anew variable, I updeted the code with some comments that explain the reason of the extra 11 blocks.

Done! Instead of declaring anew variable, I updeted the code with some comments that explain the reason of the extra 11 blocks.
Bicaru20 (Migrated from github.com) reviewed 2026-10-13 15:27:02 +00:00
Bicaru20 (Migrated from github.com) commented 2026-10-13 15:27:02 +00:00

Now we use static_cast to pass the variable to int in the line 1029.

Now we use `static_cast` to pass the variable to `int` in the line 1029.
Bicaru20 commented 2026-10-13 15:27:43 +00:00 (Migrated from github.com)

Feedback addressed!

  • In aecdce2ac2 I cleaned the code a little bit and updated some comments.
  • In 76a55ec1d0 I added some coments in the unit test to explain why we mine 11 blocks. In the functional test I updeated the comment so the range is correct (0-99). Also changed lokctime subtraction from 101 to 100.
Feedback addressed! - In aecdce2ac2 I cleaned the code a little bit and updated some comments. - In 76a55ec1d0 I added some coments in the unit test to explain why we mine 11 blocks. In the functional test I updeated the comment so the range is correct (0-99). Also changed lokctime subtraction from 101 to 100.
Bicaru20 commented 2026-10-13 15:29:02 +00:00 (Migrated from github.com)

I've just seen there are some conflicts in wallet_bumpfee. I will address them as soon as I can.

I've just seen there are some conflicts in `wallet_bumpfee`. I will address them as soon as I can.
DrahtBot commented 2026-10-13 16:30:30 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Bicaru20 (Migrated from github.com) reviewed 2026-10-14 08:40:30 +00:00
Bicaru20 (Migrated from github.com) commented 2026-10-14 08:40:30 +00:00

I couldn't do it with rbf_node.mocktime, so following examples from other tests I saved the time using int(time.time())

I couldn't do it with rbf_node.mocktime, so following examples from other tests I saved the time using `int(time.time())`
Bicaru20 commented 2026-10-14 08:44:47 +00:00 (Migrated from github.com)

Rebased

Rebased
polespinasa (Migrated from github.com) reviewed 2026-11-03 15:55:30 +00:00
polespinasa (Migrated from github.com) left a comment

The implementation looks good to me, left a few comments on the testing part before acking it :)

The implementation looks good to me, left a few comments on the testing part before acking it :)
polespinasa (Migrated from github.com) commented 2026-11-03 15:44:58 +00:00

in ec91996 Test: bumpfee does not backdate the locktime

Probably worth to check that setting the minimum locktime to the tip does not backadate.

$ git diff
diff --git a/src/wallet/test/spend_tests.cpp b/src/wallet/test/spend_tests.cpp
index 67bf06c9c4..f6da4e9238 100644
--- a/src/wallet/test/spend_tests.cpp
+++ b/src/wallet/test/spend_tests.cpp
@@ -178,6 +178,10 @@ BOOST_FIXTURE_TEST_CASE(discourage_fee_sniping_backdating_bounds, TestChain100Se
     }
     BOOST_CHECK(backdated);
 
+    // A minimum at the tip leaves no room for backdating.
+    DiscourageFeeSniping(mtx, rng_fast, chain, block_hash, block_height, block_height);
+    BOOST_CHECK_EQUAL(mtx.nLockTime, static_cast<uint32_t>(block_height));
+
     // If minimum_height > block_height the locktime is set to 0.
     DiscourageFeeSniping(mtx, rng_fast, chain, block_hash, block_height, block_height + 1);
     BOOST_CHECK_EQUAL(mtx.nLockTime, 0);
in ec91996 Test: bumpfee does not backdate the locktime Probably worth to check that setting the minimum locktime to the tip does not backadate. ```diff $ git diff diff --git a/src/wallet/test/spend_tests.cpp b/src/wallet/test/spend_tests.cpp index 67bf06c9c4..f6da4e9238 100644 --- a/src/wallet/test/spend_tests.cpp +++ b/src/wallet/test/spend_tests.cpp @@ -178,6 +178,10 @@ BOOST_FIXTURE_TEST_CASE(discourage_fee_sniping_backdating_bounds, TestChain100Se } BOOST_CHECK(backdated); + // A minimum at the tip leaves no room for backdating. + DiscourageFeeSniping(mtx, rng_fast, chain, block_hash, block_height, block_height); + BOOST_CHECK_EQUAL(mtx.nLockTime, static_cast<uint32_t>(block_height)); + // If minimum_height > block_height the locktime is set to 0. DiscourageFeeSniping(mtx, rng_fast, chain, block_hash, block_height, block_height + 1); BOOST_CHECK_EQUAL(mtx.nLockTime, 0); ```
polespinasa (Migrated from github.com) commented 2026-11-03 15:55:05 +00:00

in ec9199610b Test: bumpfee does not backdate the locktime

I think the test is missing some coverage, it only asserts what happens with a stale tip.
Probably an easy way to test what happens with a fresh tip would be somemetihng like:

$ git diff
diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py
index 216328c72e..fe06bc800f 100755
--- a/test/functional/wallet_bumpfee.py
+++ b/test/functional/wallet_bumpfee.py
@@ -935,6 +935,10 @@ def test_bumpfee_fee_sniping_check(self, rbf_node, peer_node):

    # Set the mock time back to what it was
    rbf_node.setmocktime(curr_time)
+    # With a fresh tip, the next bump must advance the locktime into the 99-block window.
+    rebumped = rbf_node.bumpfee(bumped)["txid"]
+    rebumped_locktime = rbf_node.gettransaction(rebumped, verbose=True)["decoded"]["locktime"]
+    assert locktime - 99 <= rebumped_locktime <= locktime, rebumped_locktime
    self.clear_mempool()

in ec9199610b804c44b11e20dba23f84228fe85db5 Test: bumpfee does not backdate the locktime I think the test is missing some coverage, it only asserts what happens with a stale tip. Probably an easy way to test what happens with a fresh tip would be somemetihng like: ```diff $ git diff diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index 216328c72e..fe06bc800f 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -935,6 +935,10 @@ def test_bumpfee_fee_sniping_check(self, rbf_node, peer_node): # Set the mock time back to what it was rbf_node.setmocktime(curr_time) + # With a fresh tip, the next bump must advance the locktime into the 99-block window. + rebumped = rbf_node.bumpfee(bumped)["txid"] + rebumped_locktime = rbf_node.gettransaction(rebumped, verbose=True)["decoded"]["locktime"] + assert locktime - 99 <= rebumped_locktime <= locktime, rebumped_locktime self.clear_mempool() ```
polespinasa (Migrated from github.com) commented 2026-11-03 15:37:48 +00:00

in ec9199610b Test: bumpfee does not backdate the locktime

I think this is wrong. This is hardcoding a specific timestamp to the node. If curr_time = int(time.time()) was stored at time 2. And rbf_node.setmocktime(curr_time) was executed at time 5, the node clock will be set to time 2.

Instead of using time, probably you should store the node mocktime itself, and if there is no mocktime hardcoded, just set it to 0 which means use the system clock. See test_node.py L479.

I would probably prefer something like:

$ git diff
diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py
index 216328c72e..4464e5cfd7 100755
--- a/test/functional/wallet_bumpfee.py
+++ b/test/functional/wallet_bumpfee.py
@@ -15,7 +15,6 @@ make assumptions about execution order.
 """
 from decimal import Decimal
 import re
-import time
 
 from test_framework.blocktools import (
     COINBASE_MATURITY,
@@ -920,8 +919,7 @@ def test_bumpfee_fee_sniping_check(self, rbf_node, peer_node):
     original_locktime = rbf_node.gettransaction(txid, verbose=True)["decoded"]["locktime"]
     assert_equal(original_locktime, locktime - 100)
 
-    # Save the current time
-    curr_time = int(time.time())
+    previous_mocktime = rbf_node.mocktime
 
     # Make the tip stale.
     tip_time = rbf_node.getblockheader(rbf_node.getbestblockhash())["time"]
@@ -933,8 +931,7 @@ def test_bumpfee_fee_sniping_check(self, rbf_node, peer_node):
     bumped_locktime = rbf_node.gettransaction(bumped, verbose=True)["decoded"]["locktime"]
     assert_equal(bumped_locktime, original_locktime)
 
-    # Set the mock time back to what it was
-    rbf_node.setmocktime(curr_time)
+    rbf_node.setmocktime(previous_mocktime or 0)
     self.clear_mempool()

in ec9199610b804c44b11e20dba23f84228fe85db5 Test: bumpfee does not backdate the locktime I think this is wrong. This is hardcoding a specific timestamp to the node. If `curr_time = int(time.time())` was stored at time 2. And `rbf_node.setmocktime(curr_time)` was executed at time 5, the node clock will be set to time 2. Instead of using time, probably you should store the node mocktime itself, and if there is no mocktime hardcoded, just set it to 0 which means use the system clock. See `test_node.py` L479. I would probably prefer something like: ```diff $ git diff diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index 216328c72e..4464e5cfd7 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -15,7 +15,6 @@ make assumptions about execution order. """ from decimal import Decimal import re -import time from test_framework.blocktools import ( COINBASE_MATURITY, @@ -920,8 +919,7 @@ def test_bumpfee_fee_sniping_check(self, rbf_node, peer_node): original_locktime = rbf_node.gettransaction(txid, verbose=True)["decoded"]["locktime"] assert_equal(original_locktime, locktime - 100) - # Save the current time - curr_time = int(time.time()) + previous_mocktime = rbf_node.mocktime # Make the tip stale. tip_time = rbf_node.getblockheader(rbf_node.getbestblockhash())["time"] @@ -933,8 +931,7 @@ def test_bumpfee_fee_sniping_check(self, rbf_node, peer_node): bumped_locktime = rbf_node.gettransaction(bumped, verbose=True)["decoded"]["locktime"] assert_equal(bumped_locktime, original_locktime) - # Set the mock time back to what it was - rbf_node.setmocktime(curr_time) + rbf_node.setmocktime(previous_mocktime or 0) self.clear_mempool() ```
Bicaru20 (Migrated from github.com) reviewed 2026-11-04 09:33:51 +00:00
Bicaru20 (Migrated from github.com) commented 2026-11-04 09:33:51 +00:00

rbf_node.mocktime is None until setmocktime is used. So we could either set the mocktime with the tip_time or to 0 (None), as you said. I've opted for putting it back to 0.

`rbf_node.mocktime` is None until `setmocktime` is used. So we could either set the mocktime with the `tip_time` or to 0 (None), as you said. I've opted for putting it back to 0.
Bicaru20 commented 2026-11-04 09:39:31 +00:00 (Migrated from github.com)

Feedback from @polespinasa addressed! Adopted its suggestions on the tests!

Feedback from @polespinasa addressed! Adopted its suggestions on the tests!
polespinasa (Migrated from github.com) reviewed 2026-11-04 15:58:38 +00:00
polespinasa (Migrated from github.com) left a comment

ACK 596dd6fd88

Thanks for addressing feedback, lgtm now :)

ACK 596dd6fd88efe92133a34a0ba8d00f5f369a4bfd Thanks for addressing feedback, lgtm now :)
nervana21 (Migrated from github.com) reviewed 2026-11-07 17:27:46 +00:00
nervana21 (Migrated from github.com) left a comment
ACK 596dd6fd88efe92133a34a0ba8d00f5f369a4bfd
achow101 commented 2026-11-20 23:43:13 +00:00 (Migrated from github.com)
ACK 596dd6fd88efe92133a34a0ba8d00f5f369a4bfd
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36040
No description provided.