tests: Add unix timestamp tests for OP_CLTV and max mediantimepast tests #32229

Closed
Christewart wants to merge 1 commit from 2025-04-06-locktime-tests into master AGit
Christewart commented 2025-04-07 16:44:37 +00:00 (Migrated from github.com)

This PR adds a functional (p2p/block-validation) test for OP_CHECKLOCKTIMEVERIFY (BIP65) using unix-timestamp locktimes in test/functional/feature_cltv.py. It also adds tests around the maximum possible median-time-past (MTP) value, UINT32_MAX, and how that interacts with transaction finality.

The unix-timestamp portion of BIP65 already has unit-level coverage in transaction_tests.cpp (via tx_valid.json/tx_invalid.json), but those tests call VerifyScript() directly and never exercise median-time-past (MTP) or block connection. MTP-vs-nLockTime behavior itself is covered separately in miner_tests.cpp (lines 525-534) and feature_csv_activation.py (lines 340-355), but neither exercises OP_CLTV specifically. This test closes that gap: it builds and submits full blocks over p2p and checks that a block containing an OP_CLTV-locked output is only accepted once BIP113 MTP actually satisfies the requested locktime.

This PR also adds a BIP113 test to feature_csv_activation.py showing that MTP can never advance past UINT32_MAX - 1, so an output with a plain nLockTime of UINT32_MAX can never be confirmed. This is a general BIP113 property independent of OP_CLTV.

Thanks to @mabu44 and @sedited for the review so far.

This PR adds a functional (p2p/block-validation) test for `OP_CHECKLOCKTIMEVERIFY` (BIP65) using unix-timestamp locktimes in test/functional/feature_cltv.py. It also adds tests around the maximum possible median-time-past (MTP) value, `UINT32_MAX`, and how that interacts with transaction finality. The unix-timestamp portion of BIP65 already has unit-level coverage in `transaction_tests.cpp` (via `tx_valid.json`/`tx_invalid.json`), but those tests call `VerifyScript()` directly and never exercise median-time-past (MTP) or block connection. MTP-vs-nLockTime behavior itself is covered separately in `miner_tests.cpp` (lines 525-534) and `feature_csv_activation.py` (lines 340-355), but neither exercises `OP_CLTV` specifically. This test closes that gap: it builds and submits full blocks over p2p and checks that a block containing an `OP_CLTV`-locked output is only accepted once BIP113 MTP actually satisfies the requested locktime. This PR also adds a BIP113 test to `feature_csv_activation.py` showing that MTP can never advance past `UINT32_MAX` - 1, so an output with a plain nLockTime of `UINT32_MAX` can never be confirmed. This is a general BIP113 property independent of `OP_CLTV`. Thanks to @mabu44 and @sedited for the review so far.
DrahtBot commented 2025-04-07 16:44:41 +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
Concept ACK sedited

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

<!--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/32229 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/32229.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/32229#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 | | ---- | --------- | | Concept ACK | [sedited](https://github.com/bitcoin/bitcoin/pull/32229#issuecomment-4518177621) | 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
mabu44 (Migrated from github.com) reviewed 2025-04-08 12:01:41 +00:00
mabu44 (Migrated from github.com) left a comment

The Unix-timestamp portion of BIP65 is currently tested in the c++ unit tests in "transactions_tests.cpp". Test data includes transactions that have OP_CLTV with Unix timestamps (the files are /src/test/data/tx_valid.json and tx_invalid.json).
Does your test cover scenarios that are not covered in the existing tests?

The Unix-timestamp portion of BIP65 is currently tested in the c++ unit tests in "transactions_tests.cpp". Test data includes transactions that have OP_CLTV with Unix timestamps (the files are /src/test/data/tx_valid.json and tx_invalid.json). Does your test cover scenarios that are not covered in the existing tests?
mabu44 (Migrated from github.com) commented 2025-04-08 08:21:45 +00:00

nit: typo "meadian"

nit: typo "me**a**dian"
mabu44 (Migrated from github.com) commented 2025-04-08 08:27:37 +00:00

Do we need to create a new time-locked transaction? Cannot we use the one that is already in spendtx?

Do we need to create a new time-locked transaction? Cannot we use the one that is already in spendtx?
mabu44 (Migrated from github.com) commented 2025-04-08 08:43:14 +00:00

Here you are testing what will happen in the year 2106 if no changes are deployed in the meantime. Right?

Here you are testing what will happen in the year 2106 if no changes are deployed in the meantime. Right?
Christewart commented 2025-04-08 16:23:11 +00:00 (Migrated from github.com)

Hi @mabu44 . Thanks for taking a look at this.

Do your test cover scenarios that are not covered in the existing tests?

Yes I believe so. I took a look at the values in tx_valid.json and tx_invalid.json. Here is a table

OP_CLTV parameter Transaction locktime field Valid
0 0 true
499999999 499999999 true
0 499999999 true
500000000 500000000 true
4294967295 4294967295 true
500000000 4294967295 true
0 0 true
-11 500000000 true
-19 4294967294 true
0 0 true
1 0 false
499999999 499999998 false
500000001 500000000 false
4294967295 4294967294 false
-1 0 false
-1 500000000 false
0 0 false
0 0 false
0 500000000 false
499999999 500000000 false
500000000 0 false
500000000 499999999 false
4294967296 4294967295 false
2147483648 2147483647 false
0 0 false

This test also directly tests the median-time-past logic. This is not tested in tx_{valid,invalid}.json as we just directly call VerifyScript() for individual transactions in the test files.

Interestingly, i think there may be one test case overlap with tx_valid.json. While this transaction could be valid with relay policy I don't believe a transaction with these locktimes would be allowed to be included in a block? This is because median-time-past logic for a block with this transaction could be not be satisfied as per my last test case here.

| 4294967295 | 4294967295 | true |

Some more eyes on this could be good as I may be making a mistake.

Hi @mabu44 . Thanks for taking a look at this. > Do your test cover scenarios that are not covered in the existing tests? Yes I believe so. I took a look at the values in `tx_valid.json` and `tx_invalid.json`. Here is a table | OP_CLTV parameter | Transaction locktime field | Valid | |-------------------|----------------------------|--------| | 0 | 0 | true | | 499999999 | 499999999 | true | | 0 | 499999999 | true | | 500000000 | 500000000 | true | | 4294967295 | 4294967295 | true | | 500000000 | 4294967295 | true | | 0 | 0 | true | | -11 | 500000000 | true | | -19 | 4294967294 | true | | 0 | 0 | true | | 1 | 0 | false | | 499999999 | 499999998 | false | | 500000001 | 500000000 | false | | 4294967295 | 4294967294 | false | | -1 | 0 | false | | -1 | 500000000 | false | | 0 | 0 | false | | 0 | 0 | false | | 0 | 500000000 | false | | 499999999 | 500000000 | false | | 500000000 | 0 | false | | 500000000 | 499999999 | false | | 4294967296 | 4294967295 | false | | 2147483648 | 2147483647 | false | | 0 | 0 | false | This test also directly tests the median-time-past logic. This is not tested in `tx_{valid,invalid}.json` as we just [directly call `VerifyScript()`](https://github.com/bitcoin/bitcoin/blob/cfe025ff0e1dcf984179a5a9b01dc8b865d95409/src/test/transaction_tests.cpp#L129) for individual transactions in the test files. Interestingly, i think there may be one test case overlap with `tx_valid.json`. While this transaction could be valid with relay policy I don't believe a transaction with these locktimes would be allowed to be included in a block? This is because median-time-past logic for a block with this transaction could be not be satisfied as per my last test case [here](https://github.com/Christewart/bitcoin/blob/69b6bb9438095f84ce90aecfc4e76b0ff21cc2b8/test/functional/feature_cltv.py#L256). >| 4294967295 | 4294967295 | true | Some more eyes on this could be good as I may be making a mistake.
Christewart (Migrated from github.com) reviewed 2025-04-08 16:26:06 +00:00
Christewart (Migrated from github.com) commented 2025-04-08 16:26:06 +00:00

I believe so because the previous one was mined in a valid block here: github.com/Christewart/bitcoin@69b6bb9438/test/functional/feature_cltv.py (L213)

I believe so because the previous one was mined in a valid block here: https://github.com/Christewart/bitcoin/blob/69b6bb9438095f84ce90aecfc4e76b0ff21cc2b8/test/functional/feature_cltv.py#L213
mabu44 (Migrated from github.com) reviewed 2025-04-10 12:03:43 +00:00
mabu44 (Migrated from github.com) left a comment

So this is an integration test of:

with some more edge cases relative to the year 2106. Right?

Interestingly, i think there may be one test case overlap with tx_valid.json. While this transaction could be valid with relay policy I don't believe a transaction with these locktimes would be allowed to be included in a block? This is because median-time-past logic for a block with this transaction could be not be satisfied as per my last test case here.

| 4294967295 | 4294967295 | true |

I think that such a transaction will become relay-valid in 2106, but, unless consensus changes, it will never be mined because no blocks will be produced to mine it.

So this is an integration test of: - *Transaction validity based on input script and transaction locktime*: currently tested in [transactions_tests.cpp](https://github.com/bitcoin/bitcoin/blob/master/src/test/transaction_tests.cpp); - *Transaction validity based on median block time*: currently tested in [miner_tests.cpp (lines 525-534)](https://github.com/bitcoin/bitcoin/blob/b8cefeb221490868d62b7a0695f8b5ea392d3654/src/test/miner_tests.cpp#L525-L534) and [feature_csv_activation.py (lines 340-355)](https://github.com/bitcoin/bitcoin/blob/b8cefeb221490868d62b7a0695f8b5ea392d3654/test/functional/feature_csv_activation.py#L340-L355) with some more edge cases relative to the year 2106. Right? > Interestingly, i think there may be one test case overlap with tx_valid.json. While this transaction could be valid with relay policy I don't believe a transaction with these locktimes would be allowed to be included in a block? This is because median-time-past logic for a block with this transaction could be not be satisfied as per my last test case [here](https://github.com/Christewart/bitcoin/blob/69b6bb9438095f84ce90aecfc4e76b0ff21cc2b8/test/functional/feature_cltv.py#L256). >> | 4294967295 | 4294967295 | true | I think that such a transaction will become relay-valid in 2106, but, unless consensus changes, it will never be mined because no blocks will be produced to mine it.
mabu44 (Migrated from github.com) commented 2025-04-10 11:44:32 +00:00

This tx was mined in line 195, not 213. I would move the creation of the transaction from line 230 to line 209. Otherwise, the check at line 218 could succeed not for the timelock (that is what we expect) but because of the duplicated transaction.

This tx was mined in [line 195](https://github.com/Christewart/bitcoin/blob/69b6bb9438095f84ce90aecfc4e76b0ff21cc2b8/test/functional/feature_cltv.py#L195), not [213](https://github.com/Christewart/bitcoin/blob/69b6bb9438095f84ce90aecfc4e76b0ff21cc2b8/test/functional/feature_cltv.py#L213). I would move the creation of the transaction from line 230 to line 209. Otherwise, the check at line 218 could succeed not for the timelock (that is what we expect) but because of the duplicated transaction.
mabu44 (Migrated from github.com) commented 2025-04-10 11:46:03 +00:00

This line can be removed

This line can be removed
mabu44 (Migrated from github.com) commented 2025-04-10 11:47:13 +00:00

This comment was not updated to reflect what the code is doing (same for the comments at line 256 and 258).

This comment was not updated to reflect what the code is doing (same for the comments at line 256 and 258).
Christewart commented 2025-04-10 17:11:59 +00:00 (Migrated from github.com)

Thank you again for the careful review. I've integrated your code review in 024c3bf

So this is an integration test of:

* _Transaction validity based on input script and transaction locktime_: currently tested in [transactions_tests.cpp](https://github.com/bitcoin/bitcoin/blob/master/src/test/transaction_tests.cpp);

* _Transaction validity based on median block time_: currently tested in [miner_tests.cpp (lines 525-534)](https://github.com/bitcoin/bitcoin/blob/b8cefeb221490868d62b7a0695f8b5ea392d3654/src/test/miner_tests.cpp#L525-L534) and [feature_csv_activation.py (lines 340-355)](https://github.com/bitcoin/bitcoin/blob/b8cefeb221490868d62b7a0695f8b5ea392d3654/test/functional/feature_csv_activation.py#L340-L355)

with some more edge cases relative to the year 2106. Right?

Yes.

Interestingly, i think there may be one test case overlap with tx_valid.json. While this transaction could be valid with relay policy I don't believe a transaction with these locktimes would be allowed to be included in a block? This is because median-time-past logic for a block with this transaction could be not be satisfied as per my last test case here.

| 4294967295 | 4294967295 | true |

I think that such a transaction will become relay-valid in 2106, but, unless consensus changes, it will never be mined because no blocks will be produced to mine it.

That is my understanding as well 👍

Thank you again for the careful review. I've integrated your code review in 024c3bf > So this is an integration test of: > > * _Transaction validity based on input script and transaction locktime_: currently tested in [transactions_tests.cpp](https://github.com/bitcoin/bitcoin/blob/master/src/test/transaction_tests.cpp); > > * _Transaction validity based on median block time_: currently tested in [miner_tests.cpp (lines 525-534)](https://github.com/bitcoin/bitcoin/blob/b8cefeb221490868d62b7a0695f8b5ea392d3654/src/test/miner_tests.cpp#L525-L534) and [feature_csv_activation.py (lines 340-355)](https://github.com/bitcoin/bitcoin/blob/b8cefeb221490868d62b7a0695f8b5ea392d3654/test/functional/feature_csv_activation.py#L340-L355) > > > with some more edge cases relative to the year 2106. Right? Yes. > > Interestingly, i think there may be one test case overlap with tx_valid.json. While this transaction could be valid with relay policy I don't believe a transaction with these locktimes would be allowed to be included in a block? This is because median-time-past logic for a block with this transaction could be not be satisfied as per my last test case [here](https://github.com/Christewart/bitcoin/blob/69b6bb9438095f84ce90aecfc4e76b0ff21cc2b8/test/functional/feature_cltv.py#L256). > > > > | 4294967295 | 4294967295 | true | > > I think that such a transaction will become relay-valid in 2106, but, unless consensus changes, it will never be mined because no blocks will be produced to mine it. That is my understanding as well :+1:
DrahtBot (Migrated from github.com) reviewed 2025-07-23 08:45:55 +00:00
DrahtBot (Migrated from github.com) commented 2025-07-23 08:45:55 +00:00
                               AttributeError: 'CBlock' object has no attribute 'sha256'
AttributeError: 'CBlock' object has no attribute 'sha256'
fanquake commented 2025-12-03 11:02:51 +00:00 (Migrated from github.com)

cc @petertodd

cc @petertodd
DrahtBot commented 2026-01-29 02:06:27 +00:00 (Migrated from github.com)

There hasn't been much activity lately. What is the status here?

Finding reviewers may take time. However, if the patch is no longer relevant, please close this pull request. If the author lost interest or time to work on this, please close it and mark it with one of the labels 'Up for grabs' or 'Insufficient Review', so that it can be picked up in the future.

<!--8ac04cdde196e94527acabf64b896448--> There hasn't been much activity lately. What is the status here? [Finding reviewers](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#finding-reviewers) may take time. However, if the patch is no longer relevant, please close this pull request. If the author lost interest or time to work on this, please close it and mark it with one of the labels 'Up for grabs' or 'Insufficient Review', so that it can be picked up in the future.
sedited commented 2026-03-03 13:13:28 +00:00 (Migrated from github.com)

If I understand this change correctly, this adds test cases for the finality of a block's transactions and how they might interplay with CLTV. Can you re-formulate the PR description to make it clear what this actually tests? Contrary to your current description, it looks like we are already testing unix timestamp values in the locktime extensively. Are the finality tests better suited for feature_csv_activation?

If I understand this change correctly, this adds test cases for the finality of a block's transactions and how they might interplay with CLTV. Can you re-formulate the PR description to make it clear what this actually tests? Contrary to your current description, it looks like we are already testing unix timestamp values in the locktime extensively. Are the finality tests better suited for `feature_csv_activation`?
fanquake commented 2026-04-30 14:56:39 +00:00 (Migrated from github.com)

@Christewart any chance you want to follow up to the above?

@Christewart any chance you want to follow up to the above?
Christewart commented 2026-04-30 18:42:24 +00:00 (Migrated from github.com)

Hi @sedited

it looks like we are already testing unix timestamp values in the locktime extensively.

feature_csv_activation.py tests relative lock times and the OP_CHECKSEQUENCEVERIFY opcode. This test case is testing OP_CHECKLOCKTIMEVERIFY and absolute wall clock locktimes ("unix timestamps"). Different fields on the transaction are used for verification (sequence vs locktime).

Are the finality tests better suited for feature_csv_activation

In my opinion no so since this is testing absolute wall clock locktimes via a different opcode - OP_CLTV.

The real interesting part to me is the setting the unix timestamp of the node to UINT32_MAX, and then attempting to spend OP_CLTV locked utxos when we have reached the UINT32_MAX timestamp in the locktime field.

Since we cannot satisfy the MTP requirement of BIP113 (i.e. we cannot create a block with timestamp UINT32_MAX+1 so we are following BIP113 and monotonically increase the timestamp on the block) - the utxo can never be spent.

From a quick glance through feature_csv_activation.py I don't see any references to 2**32 or UINT32_MAX - so I doubt this edge case is tested there - although if you could link to an exact line that it was tested on that would be helpful.

In general, I think @mabu44 's comment was good:

https://github.com/bitcoin/bitcoin/pull/32229#pullrequestreview-2756380784

EDIT:

Looking closer at feature_csv_activation.py it does look like it tests BIP113 logic (its unfortunate the file is named after the opcode and is testing more than the opcode). The logic testing UINT32_MAX could be moved over to that file, however the OP_CLTV test logic should stay here and I still believe there is no integration tests for OP_CLTV and unix timestamps - please link if you find them

Hi @sedited > it looks like we are already testing unix timestamp values in the locktime extensively. `feature_csv_activation.py` tests relative lock times and the `OP_CHECKSEQUENCEVERIFY` opcode. This test case is testing `OP_CHECKLOCKTIMEVERIFY` and absolute wall clock locktimes ("unix timestamps"). Different fields on the transaction are used for verification (`sequence` vs `locktime`). >Are the finality tests better suited for feature_csv_activation In my opinion no so since this is testing absolute wall clock locktimes via a different opcode - `OP_CLTV`. The real interesting part to me is the [setting the unix timestamp of the node to `UINT32_MAX`](https://github.com/Christewart/bitcoin/blob/cbc1095adb8f729c2cb06574144187a16f45c68a/test/functional/feature_cltv.py#L239), and then attempting to spend `OP_CLTV` locked utxos when we have reached the `UINT32_MAX` timestamp in the locktime field. Since we cannot satisfy the MTP requirement of BIP113 (i.e. we cannot create a block with timestamp `UINT32_MAX+1` so we are following BIP113 and monotonically increase the timestamp on the block) - the utxo can never be spent. From a quick glance through `feature_csv_activation.py` I don't see any references to `2**32` or `UINT32_MAX` - so I doubt this edge case is tested there - although if you could link to an exact line that it was tested on that would be helpful. In general, I think @mabu44 's comment was good: https://github.com/bitcoin/bitcoin/pull/32229#pullrequestreview-2756380784 EDIT: Looking closer at `feature_csv_activation.py` it does look like it tests BIP113 logic (its unfortunate the file is named after the opcode and is testing more than the opcode). The logic testing `UINT32_MAX` could be moved over to that file, however the `OP_CLTV` test logic should stay here and I still believe there is no integration tests for OP_CLTV and unix timestamps - please link if you find them
sedited commented 2026-05-22 11:18:03 +00:00 (Migrated from github.com)

The logic testing UINT32_MAX could be moved over to that file,

Yes, sorry for not being clearer on this before, but that is what I was suggesting.

however the OP_CLTV test logic should stay here and I still believe there is no integration tests for OP_CLTV and unix timestamps - please link if you find them.

Thanks for linking mabu44's comment again, I was referring to the same tests too. Maybe mention them in the PR descritpion?

The real interesting part to me is the setting the unix timestamp of the node to UINT32_MAX, and then attempting to spend OP_CLTV locked utxos when we have reached the UINT32_MAX timestamp in the locktime field.

I guess once that MTP is reached, we'll have to change some part of the calculation anyway, but I'm fine with having a test for documenting this.

Concept ACK

> The logic testing UINT32_MAX could be moved over to that file, Yes, sorry for not being clearer on this before, but that is what I was suggesting. > however the OP_CLTV test logic should stay here and I still believe there is no integration tests for OP_CLTV and unix timestamps - please link if you find them. Thanks for linking mabu44's comment again, I was referring to the same tests too. Maybe mention them in the PR descritpion? > The real interesting part to me is the [setting the unix timestamp of the node to UINT32_MAX](https://github.com/Christewart/bitcoin/blob/cbc1095adb8f729c2cb06574144187a16f45c68a/test/functional/feature_cltv.py#L239), and then attempting to spend OP_CLTV locked utxos when we have reached the UINT32_MAX timestamp in the locktime field. I guess once that MTP is reached, we'll have to change some part of the calculation anyway, but I'm fine with having a test for documenting this. Concept ACK
Christewart commented 2026-07-05 19:17:39 +00:00 (Migrated from github.com)

Hi @sedited , I pushed a new commit: 533d0c608312beaeb47bb5373169a17f9c756814

Here are the things that i've changed since you've last reviewed

  • Rewrote the PR description to clarify what this actually tests and to credit the existing coverage you and @mabu44 pointed to (see above).
  • Split the UINT32_MAX / median-time-past edge case out of feature_cltv.py and into feature_csv_activation.py, since that behavior is a general BIP113 property and not specific to OP_CLTV (per our earlier discussion).
  • Rebased onto latest master.
  • The rebase pulled in #35089 (create_block's height= kwarg replacing the old create_coinbase(...) calling convention), which broke a few call sites this PR touches. Fixed those up to match the new convention.

Let me know if this addresses your concerns or if there's anything else you'd like changed.

Hi @sedited , I pushed a new commit: 533d0c608312beaeb47bb5373169a17f9c756814 Here are the things that i've changed since you've last reviewed - Rewrote the PR description to clarify what this actually tests and to credit the existing coverage you and @mabu44 pointed to (see above). - Split the `UINT32_MAX` / median-time-past edge case out of `feature_cltv.py` and into `feature_csv_activation.py`, since that behavior is a general BIP113 property and not specific to `OP_CLTV` (per our earlier discussion). - Rebased onto latest master. - The rebase pulled in #35089 (`create_block`'s `height=` kwarg replacing the old `create_coinbase(...)` calling convention), which broke a few call sites this PR touches. Fixed those up to match the new convention. Let me know if this addresses your concerns or if there's anything else you'd like changed.
sedited (Migrated from github.com) reviewed 2026-07-23 16:20:13 +00:00
sedited (Migrated from github.com) commented 2026-07-23 13:56:51 +00:00

Nit: Missing space (and for the other cltv_validate call too).

Nit: Missing space (and for the other `cltv_validate` call too).
sedited (Migrated from github.com) commented 2026-07-23 15:11:58 +00:00

How about:

        # expect failure as we haven't satisfied wall clock time yet
        with self.nodes[0].assert_debug_log(expected_msgs=['bad-txns-nonfinal']):
            peer.send_and_ping(msg_block(block2))
            assert_not_equal(int(self.nodes[0].getbestblockhash(), 16), block2.hash_int)

As done further above in the file to capture the rejection reason?

How about: ``` # expect failure as we haven't satisfied wall clock time yet with self.nodes[0].assert_debug_log(expected_msgs=['bad-txns-nonfinal']): peer.send_and_ping(msg_block(block2)) assert_not_equal(int(self.nodes[0].getbestblockhash(), 16), block2.hash_int) ``` As done further above in the file to capture the rejection reason?
sedited (Migrated from github.com) commented 2026-07-23 14:59:47 +00:00

If I remove this line, the test still passes. Is it required? Doesn't this also just append another scriptsig to the existing one?

If I remove this line, the test still passes. Is it required? Doesn't this also just append another scriptsig to the existing one?
sedited (Migrated from github.com) commented 2026-07-23 16:19:40 +00:00

Is this really exercising the edge case behaviour? It seems kind of obvious that for as long as the MTP isn't maxed out, the transaction will fail. From what I gather we want to show that a transaction with nLockTime will never be mined. Wouldn't it be better to mine to an MTP of UINT32_MAX, and then show that a) submitting a transaction to the mempool with nLockTime at UINT32_MAX fails, and that extending the chain further with a block containing the transaction will fail with "time-too-old".

Is this really exercising the edge case behaviour? It seems kind of obvious that for as long as the MTP isn't maxed out, the transaction will fail. From what I gather we want to show that a transaction with nLockTime will never be mined. Wouldn't it be better to mine to an MTP of UINT32_MAX, and then show that a) submitting a transaction to the mempool with nLockTime at UINT32_MAX fails, and that extending the chain further with a block containing the transaction will fail with "time-too-old".
Christewart commented 2026-07-29 19:08:34 +00:00 (Migrated from github.com)
@sedited I believe all your points are integrated into https://github.com/bitcoin/bitcoin/pull/32229/commits/1f05d8e0364fa4b009e558c97e821be70313b8bc
sedited (Migrated from github.com) reviewed 2026-09-16 15:37:23 +00:00
sedited (Migrated from github.com) commented 2026-09-16 14:32:35 +00:00

Why is this line changed? Seems like it is not actually changing anything behaviour wise.

Why is this line changed? Seems like it is not actually changing anything behaviour wise.
sedited (Migrated from github.com) commented 2026-09-16 14:35:11 +00:00

The test passes if this line is left the same, so maybe this should not be changed?

The test passes if this line is left the same, so maybe this should not be changed?
sedited (Migrated from github.com) commented 2026-09-16 14:52:51 +00:00

Why twelve, doesn't this test only need eleven?

Why twelve, doesn't this test only need eleven?
sedited (Migrated from github.com) commented 2026-09-16 15:06:18 +00:00

Might it be better to derive this from the mediantime directly? Something like:

locktime = self.nodes[0].getblockheader(block.hash_hex)['mediantime'] + (60 * 60) # 1 hour
Might it be better to derive this from the mediantime directly? Something like: ```python locktime = self.nodes[0].getblockheader(block.hash_hex)['mediantime'] + (60 * 60) # 1 hour ```
sedited (Migrated from github.com) commented 2026-09-16 15:10:38 +00:00

Nit: create_block has a txlist arg that this without having to do it manually.

Nit: create_block has a txlist arg that this without having to do it manually.
sedited (Migrated from github.com) commented 2026-09-16 15:37:08 +00:00

Looked at the latest version here and I think this is still not addressed, but my comment was not really helpful. The interesting case in my eyes is that on the final block, a UINT32_MAX - 1 timelocked transaction is considered standard and enters the mempool, but can't ever be mined. How about adding this:

diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py
index 410278f407b..943890d81bc 100755
--- a/test/functional/feature_csv_activation.py
+++ b/test/functional/feature_csv_activation.py
@@ -61,7 +61,7 @@ from test_framework.wallet import (
 )
 
 TESTING_TX_COUNT = 83  # Number of testing transactions: 1 BIP113 tx, 16 BIP68 txs, 66 BIP112 txs (see comments above)
-MTP_EDGE_CASE_INPUT_COUNT = 2  # Extra inputs for the "median-time-past can never reach UINT32_MAX" BIP113 test
+MTP_EDGE_CASE_INPUT_COUNT = 3 # Extra inputs for the "median-time-past can never reach UINT32_MAX" BIP113 test
 COINBASE_BLOCK_COUNT = TESTING_TX_COUNT + MTP_EDGE_CASE_INPUT_COUNT  # Number of coinbase blocks we need to generate as inputs for our txs
 BASE_RELATIVE_LOCKTIME = 10
 SEQ_DISABLE_FLAG = 1 << 31
@@ -520,6 +520,10 @@ class BIP68_112_113Test(BitcoinTestFramework):
         block.solve()
         self.send_blocks([block], success=False, reject_reason='bad-txns-nonfinal')
 
+        # A transaction locked to UINT32_MAX - 1 is not final until the last block is mined
+        max_locktime_standard_tx = mtp_edge_case_tx(mtp_edge_case_inputs[2], UINT32_MAX - 1)
+        assert_raises_rpc_error(-26, 'non-final', self.nodes[0].sendrawtransaction, max_locktime_standard_tx.serialize().hex())
+
         # max out MTP on the network to UINT32_MAX, so that the next block's nTime can't exceed it (and thus any block will be rejected for time-too-old)
         while self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())['mediantime'] < UINT32_MAX:
             block = create_block(self.tip, height=self.tipheight + 1, ntime=UINT32_MAX)
@@ -530,6 +534,10 @@ class BIP68_112_113Test(BitcoinTestFramework):
 
         assert_equal(self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())['mediantime'], UINT32_MAX)
 
+        # The transaction locked to UINT32_MAX - 1 is now final and enters the mempool, but there can't be another block, so it won't be mined
+        self.nodes[0].sendrawtransaction(max_locktime_standard_tx.serialize().hex())
+        assert max_locktime_standard_tx.txid_hex in self.nodes[0].getrawmempool()
+
         # submitting a transaction to the mempool with nLockTime at UINT32_MAX fails
         assert_raises_rpc_error(-26, 'non-final', self.nodes[0].sendrawtransaction, never_final_tx.serialize().hex())
Looked at the latest version here and I think this is still not addressed, but my comment was not really helpful. The interesting case in my eyes is that on the final block, a UINT32_MAX - 1 timelocked transaction is considered standard and enters the mempool, but can't ever be mined. How about adding this: ```diff diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py index 410278f407b..943890d81bc 100755 --- a/test/functional/feature_csv_activation.py +++ b/test/functional/feature_csv_activation.py @@ -61,7 +61,7 @@ from test_framework.wallet import ( ) TESTING_TX_COUNT = 83 # Number of testing transactions: 1 BIP113 tx, 16 BIP68 txs, 66 BIP112 txs (see comments above) -MTP_EDGE_CASE_INPUT_COUNT = 2 # Extra inputs for the "median-time-past can never reach UINT32_MAX" BIP113 test +MTP_EDGE_CASE_INPUT_COUNT = 3 # Extra inputs for the "median-time-past can never reach UINT32_MAX" BIP113 test COINBASE_BLOCK_COUNT = TESTING_TX_COUNT + MTP_EDGE_CASE_INPUT_COUNT # Number of coinbase blocks we need to generate as inputs for our txs BASE_RELATIVE_LOCKTIME = 10 SEQ_DISABLE_FLAG = 1 << 31 @@ -520,6 +520,10 @@ class BIP68_112_113Test(BitcoinTestFramework): block.solve() self.send_blocks([block], success=False, reject_reason='bad-txns-nonfinal') + # A transaction locked to UINT32_MAX - 1 is not final until the last block is mined + max_locktime_standard_tx = mtp_edge_case_tx(mtp_edge_case_inputs[2], UINT32_MAX - 1) + assert_raises_rpc_error(-26, 'non-final', self.nodes[0].sendrawtransaction, max_locktime_standard_tx.serialize().hex()) + # max out MTP on the network to UINT32_MAX, so that the next block's nTime can't exceed it (and thus any block will be rejected for time-too-old) while self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())['mediantime'] < UINT32_MAX: block = create_block(self.tip, height=self.tipheight + 1, ntime=UINT32_MAX) @@ -530,6 +534,10 @@ class BIP68_112_113Test(BitcoinTestFramework): assert_equal(self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())['mediantime'], UINT32_MAX) + # The transaction locked to UINT32_MAX - 1 is now final and enters the mempool, but there can't be another block, so it won't be mined + self.nodes[0].sendrawtransaction(max_locktime_standard_tx.serialize().hex()) + assert max_locktime_standard_tx.txid_hex in self.nodes[0].getrawmempool() + # submitting a transaction to the mempool with nLockTime at UINT32_MAX fails assert_raises_rpc_error(-26, 'non-final', self.nodes[0].sendrawtransaction, never_final_tx.serialize().hex()) ```
sedited commented 2026-10-31 11:11:27 +00:00 (Migrated from github.com)

@Christewart can you follow up here?

@Christewart can you follow up here?
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 1f05d8e0364f · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:8541d3fafd3ea45d3ad824914bf78a806527457ae4801671a2c4a580beddb288:1e657457416e20a18d8d2d136919c48e28e1bfed7a76c26939ab1ca10a232c6a --> <!-- ralph-base:ab7e668cc6af5d716ad40166d1f88235a2f6d25d --> <!-- ralph-head:1f05d8e0364fa4b009e558c97e821be70313b8bc --> <!-- ralph-case:824237e433a2e25b3a0375129e4242e78f7c90545a69f9fe03c71adcb393b15d --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`1f05d8e0364f`](<https://git.fish.foo/bitcoin/bitcoin/commit/1f05d8e0364fa4b009e558c97e821be70313b8bc>) · [Full review report](<https://review.fish.foo/traces/32229-1f05d8e0364fa4b009e558c97e821be70313b8bc-1892-1.html>) · [Previous reports](<https://review.fish.foo/traces/32229/>) [permalink](<https://review.fish.foo/traces/32229-1f05d8e0364fa4b009e558c97e821be70313b8bc-1892-1.html>)
fanquake commented 2026-12-01 15:06:11 +00:00 (Migrated from github.com)

Christewart can you follow up here?

@Christewart interested in taking the review here?

> Christewart can you follow up here? @Christewart interested in taking the review here?
Christewart commented 2026-12-01 20:03:11 +00:00 (Migrated from github.com)

I don't plan on picking this up. I feel like we are going in circles.

I don't plan on picking this up. I feel like we are going in circles.
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!32229
No description provided.