Extract CTxIn::MAX_SEQUENCE_NONFINAL constant, rework BIP 65/68/112 docs #24136

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2201-docSeq changing 5 files +32 −12
  1. MarcoFalke commented at 8:56 am on January 24, 2022: member

    Extracting the constant makes it possible to attach documentation to it.

    Also, rework the docs for the other “sequence constants”.

  2. DrahtBot added the label RPC/REST/ZMQ on Jan 24, 2022
  3. DrahtBot added the label Wallet on Jan 24, 2022
  4. MarcoFalke removed the label Wallet on Jan 24, 2022
  5. MarcoFalke removed the label RPC/REST/ZMQ on Jan 24, 2022
  6. MarcoFalke added the label Refactoring on Jan 24, 2022
  7. MarcoFalke added the label Docs on Jan 24, 2022
  8. prusnak approved
  9. prusnak commented at 6:30 pm on January 24, 2022: contributor
    Approach ACK fab3ff2
  10. in src/primitives/transaction.h:95 in fab3ff2071 outdated
    93+    /**
    94+     * If this flag is set, CTxIn::nSequence is NOT interpreted as a
    95+     * relative lock-time.
    96+     * It skips SequenceLocks() for any input that has it set (BIP 68).
    97+     * It fails OP_CHECKSEQUENCEVERIFY/CheckSequence() for any input that has
    98+     * it set (BIP 112).
    


    darosior commented at 8:56 am on January 25, 2022:

    You are using the same language here as for BIP65 timelocks, whereas in this case it’s “local” (if an input needs both satisfy a BIP112 timelock and its nSequence has the disable flag) while in the other it’s “global” (if any input of the spending transaction has a BIP65 timelock and any other input has its nSequence set to SEQUENCE_FINAL).

    I don’t have a better suggestion. Just a nit that it might be confusing to someone only from these comments.


    MarcoFalke commented at 11:54 am on January 26, 2022:

    Sorry, can you explain this a bit better? Both OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY are evaluated in a local context of the input.

    Sure, the whole transaction fails “globally”, if any input is invalid, but this is true for both opcodes as well.


    darosior commented at 12:01 pm on January 26, 2022:
    Brainfart, sorry. I for some reason mistakenly assumed that IsFinalTx() returned true if any input’s nSequence was set to SEQUENCE_FINAL… And of course didn’t double check before posting this confusing comment.

    MarcoFalke commented at 12:25 pm on January 26, 2022:
    No worries. Going to resolve the thread for now.
  11. darosior commented at 8:58 am on January 25, 2022: member
    ACK fab3ff2071682caf77680be49e934b434e732988
  12. w0xlt approved
  13. w0xlt commented at 1:56 pm on January 26, 2022: contributor
    ACK fab3ff2 for improving documentation.
  14. Extract CTxIn::MAX_SEQUENCE_NONFINAL constant fa4339e4c1
  15. MarcoFalke force-pushed on Jan 26, 2022
  16. MarcoFalke commented at 2:12 pm on January 26, 2022: member
    Sorry for the force push. Clarified tx.version >= 2, requested in comment https://github.com/bitcoin/bitcoin/pull/7184/files#r47233948
  17. DrahtBot commented at 0:57 am on January 27, 2022: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24128 (wallet: BIP 326 sequence based anti-fee-snipe for taproot inputs by MarcoFalke)
    • #22871 (Discourage CSV as NOP when locktime disable is set & discourage unknown nSequence by JeremyRubin)

    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.

  18. w0xlt approved
  19. w0xlt commented at 2:39 am on January 27, 2022: contributor
    reACK fa4339e for specifying the transaction version.
  20. darosior commented at 4:02 pm on January 27, 2022: member
    re-ACK fa4339e4c1bb60e0d9263d4f0fe65d03aad52f88
  21. luke-jr approved
  22. luke-jr commented at 8:43 pm on January 29, 2022: member
    crACK fa4339e4c1bb60e0d9263d4f0fe65d03aad52f88
  23. in src/primitives/transaction.h:88 in fa4339e4c1
    88+    static const uint32_t MAX_SEQUENCE_NONFINAL{SEQUENCE_FINAL - 1};
    89 
    90-    /* Below flags apply in the context of BIP 68*/
    91-    /* If this flag set, CTxIn::nSequence is NOT interpreted as a
    92-     * relative lock-time. */
    93+    // Below flags apply in the context of BIP 68. BIP 68 requires the tx
    


    jonatack commented at 11:56 pm on January 30, 2022:

    I see this is from BIP 68, but it could be better (may propose some fixups to the BIP), plus add a newline to denote that this comment applies to the next four sections of doxygen docs + constants

    0      * disables nLockTime. */
    1     static const uint32_t SEQUENCE_FINAL = 0xffffffff;
    2 
    3-    /* Below flags apply in the context of BIP 68*/
    4+    /* The following flags apply in the context of BIP 68: */
    5+
    6     /* If this flag set, CTxIn::nSequence is NOT interpreted as a
    7      * relative lock-time. */
    

    MarcoFalke commented at 7:27 am on January 31, 2022:
    I think it should be clear that the comment, which uses plural (“flags”) refers to the flags below. I think not using a newline also helps here, so going to leave as-is for now.
  24. jonatack commented at 0:28 am on January 31, 2022: member

    Concept ACK. Another replacement to consider:

     0diff --git a/src/util/rbf.h b/src/util/rbf.h
     1index a957617389..33a38dad88 100644
     2--- a/src/util/rbf.h
     3+++ b/src/util/rbf.h
     4@@ -13,11 +13,12 @@ static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE{0xfffffffd};
     5 
     6 /** Check whether the sequence numbers on this transaction are signaling opt-in to replace-by-fee,
     7  * according to BIP 125.  Allow opt-out of transaction replacement by setting nSequence >
     8- * MAX_BIP125_RBF_SEQUENCE (SEQUENCE_FINAL-2) on all inputs.
     9+ * MAX_BIP125_RBF_SEQUENCE (SEQUENCE_FINAL - 2) on all inputs.
    10 *
    11-* SEQUENCE_FINAL-1 is picked to still allow use of nLockTime by non-replaceable transactions. All
    12-* inputs rather than just one is for the sake of multi-party protocols, where we don't want a single
    13-* party to be able to disable replacement by opting out in their own input. */
    14+* CTxIn::MAX_SEQUENCE_NONFINAL (SEQUENCE_FINAL - 1) is picked to still allow use
    15+* of nLockTime by non-replaceable transactions. Using all inputs rather than just one
    16+* is for the sake of multi-party protocols, where we don't want a single party
    17+* to be able to disable replacement by opting out in their own input. */
    18 bool SignalsOptInRBF(const CTransaction& tx);
    19 
    20 #endif // BITCOIN_UTIL_RBF_H
    

    Also: s/All inputs/Using all inputs/

  25. MarcoFalke merged this on Jan 31, 2022
  26. MarcoFalke closed this on Jan 31, 2022

  27. MarcoFalke deleted the branch on Jan 31, 2022
  28. MarcoFalke commented at 8:59 am on January 31, 2022: member

    Another replacement to consider:

    The goal of this pull was to document consensus rules. If policy is documented, I am wondering if the following diff should also be applied:

     0diff --git a/src/util/rbf.h b/src/util/rbf.h
     1index a957617389..fc1fbb60de 100644
     2--- a/src/util/rbf.h
     3+++ b/src/util/rbf.h
     4@@ -9,6 +9,11 @@
     5 
     6 class CTransaction;
     7 
     8+/**
     9+ * This is the maximum sequence number that enables all of: BIP 125,
    10+ * nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
    11+ * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
    12+ */
    13 static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE{0xfffffffd};
    14 
    15 /** Check whether the sequence numbers on this transaction are signaling opt-in to replace-by-fee,
    
  29. jonatack commented at 12:51 pm on January 31, 2022: member

    If policy is documented, I am wondering if the following diff should also be applied

    SGTM

  30. sidhujag referenced this in commit 2dbddc3931 on Feb 1, 2022
  31. DrahtBot locked this on Jan 31, 2023

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: 2024-12-22 03:12 UTC

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