kernel: Add API getter functions for timelock fields (nLockTime, nSequence) #34846

pull theStack wants to merge 2 commits into bitcoin:master from theStack:202603-kernel-add_timelock_getters changing 4 files +41 −0
  1. theStack commented at 3:48 am on March 18, 2026: contributor

    This PR introduces two new C API functions to libbitcoinkernel:

    • btck_transaction_get_locktime to access a transaction’s nLockTime value
    • btck_transaction_input_get_sequence to access a transaction input’s nSequence value

    Inspired by https://bnoc.xyz/t/forward-compatible-coinbase-locktimes-for-bip-54. After reading this I thought it would be a nice/useful showcase to check BIP54 compliance of (historical) blocks using bitcoinkernel, without having to manually deserialize the transaction (this is just about one of the four BIP54 rules though, especially the sigops limit is much more involved).

  2. kernel: Add API function for getting a tx's nLockTime 6b64b181d5
  3. kernel: Add API function for getting a tx input's nSequence 9f28120a5b
  4. DrahtBot added the label Validation on Mar 18, 2026
  5. DrahtBot commented at 3:49 am on March 18, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK sedited, yuvicc, stickies-v

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

    LLM Linter (✨ experimental)

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

    • src/test/kernel/test_kernel.cpp: “+ BOOST_CHECK_THROW(Transaction{broken_tx_data}, std::runtime_error);” -> recommendation: replace with BOOST_CHECK_EXCEPTION to assert the exception type and message, e.g. BOOST_CHECK_EXCEPTION(Transaction{broken_tx_data}, std::runtime_error, HasReason(“the exact failure message”));

    2026-03-18 03:49:00

  6. sedited approved
  7. sedited commented at 7:33 am on March 18, 2026: contributor

    ACK 9f28120a5bff605690b9cc6ac8da255bdafffe48

    Since you’re here, I was thinking of dropping warn unused when returning these primitive types, but I saw that secp returns it pretty much everywhere. Do you know what the policy is there?

  8. yuvicc commented at 6:24 pm on March 18, 2026: contributor
    ACK 9f28120a5bff605690b9cc6ac8da255bdafffe48
  9. theStack commented at 7:09 pm on March 18, 2026: contributor

    Since you’re here, I was thinking of dropping warn unused when returning these primitive types, but I saw that secp returns it pretty much everywhere. Do you know what the policy is there?

    Dropping the “warn unused” instances for getters with primitive type results would make sense I think. As for secp, I’m not sure what the exact policy is, I assume the main idea is to reduce the risk of users accessing out-parameter results without having checked their validity (with the return value indicating success/failure) first. The maintainers know probably more about this (@jonasnick @real-or-random @sipa).

  10. real-or-random commented at 8:31 am on March 19, 2026: contributor

    As for secp, I’m not sure what the exact policy is,

    The truth is that we’re not sure either: https://github.com/bitcoin-core/secp256k1/issues/961

    I think there are a handful of cases where we want to have this for sure. The most prominent example is that not using the return value of signature verification is probably a catastrophic bug in the caller. And the same should be true for any function with only a boolean result, i.e., those without out-parameters: if you don’t use the return value, then there’s no point in calling the function in the first place.

    I assume the main idea is to reduce the risk of users accessing out-parameter results without having checked their validity (with the return value indicating success/failure) first.

    That’s a good point.

  11. in src/test/kernel/test_kernel.cpp:408 in 9f28120a5b
    400@@ -401,8 +401,11 @@ BOOST_AUTO_TEST_CASE(btck_transaction_tests)
    401 
    402     BOOST_CHECK_EQUAL(tx.CountOutputs(), 2);
    403     BOOST_CHECK_EQUAL(tx.CountInputs(), 1);
    404+    BOOST_CHECK_EQUAL(tx.GetLocktime(), 510826);
    405     auto broken_tx_data{std::span<std::byte>{tx_data.begin(), tx_data.begin() + 10}};
    406     BOOST_CHECK_THROW(Transaction{broken_tx_data}, std::runtime_error);
    407+    auto input{tx.GetInput(0)};
    408+    BOOST_CHECK_EQUAL(input.GetSequence(), 0xfffffffe);
    


    stickies-v commented at 2:04 pm on March 19, 2026:

    nit: helper variable makes things less clear imo

    0    BOOST_CHECK_EQUAL(tx.GetInput(0).GetSequence(), 0xfffffffe);
    
  12. stickies-v approved
  13. stickies-v commented at 2:05 pm on March 19, 2026: contributor
    ACK 9f28120a5bff605690b9cc6ac8da255bdafffe48
  14. sedited merged this on Mar 19, 2026
  15. sedited closed this on Mar 19, 2026

  16. theStack deleted the branch on Mar 19, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-03-20 18:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me