aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-01-31 09:40:23 +0100
committerMarcoFalke <falke.marco@gmail.com>2022-01-31 09:40:33 +0100
commit5f4c07b79902fb3780c01a7fec3ad8bff0c51189 (patch)
tree03a4b6b7a11c3e976b5a9ece5279e40baa83444e
parentb25a752dfdbb12fd579e1dbef2bb95096867046b (diff)
parentfa4339e4c1bb60e0d9263d4f0fe65d03aad52f88 (diff)
Merge bitcoin/bitcoin#24136: Extract CTxIn::MAX_SEQUENCE_NONFINAL constant, rework BIP 65/68/112 docs
fa4339e4c1bb60e0d9263d4f0fe65d03aad52f88 Extract CTxIn::MAX_SEQUENCE_NONFINAL constant (MarcoFalke) Pull request description: Extracting the constant makes it possible to attach documentation to it. Also, rework the docs for the other "sequence constants". ACKs for top commit: w0xlt: reACK fa4339e for specifying the transaction version. darosior: re-ACK fa4339e4c1bb60e0d9263d4f0fe65d03aad52f88 luke-jr: crACK fa4339e4c1bb60e0d9263d4f0fe65d03aad52f88 Tree-SHA512: 8d8f3dd5afb33eb5b72aa558e1e03de874c5ed02aa1084888e92ed86f3aaa5c725db45ded02e14cdfa67a92ac6774e97185b697f20a8ab63abbfcaa2fcd1fc6a
-rw-r--r--src/primitives/transaction.h36
-rw-r--r--src/rpc/rawtransaction_util.cpp2
-rw-r--r--src/test/fuzz/util.cpp2
-rw-r--r--src/test/miner_tests.cpp2
-rw-r--r--src/wallet/spend.cpp2
5 files changed, 32 insertions, 12 deletions
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
index 67ea4a3747..1fcbc45c72 100644
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -70,25 +70,45 @@ public:
uint32_t nSequence;
CScriptWitness scriptWitness; //!< Only serialized through CTransaction
- /* Setting nSequence to this value for every input in a transaction
- * disables nLockTime. */
+ /**
+ * Setting nSequence to this value for every input in a transaction
+ * disables nLockTime/IsFinalTx().
+ * It fails OP_CHECKLOCKTIMEVERIFY/CheckLockTime() for any input that has
+ * it set (BIP 65).
+ * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
+ */
static const uint32_t SEQUENCE_FINAL = 0xffffffff;
+ /**
+ * This is the maximum sequence number that enables both nLockTime and
+ * OP_CHECKLOCKTIMEVERIFY (BIP 65).
+ * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
+ */
+ static const uint32_t MAX_SEQUENCE_NONFINAL{SEQUENCE_FINAL - 1};
- /* Below flags apply in the context of BIP 68*/
- /* If this flag set, CTxIn::nSequence is NOT interpreted as a
- * relative lock-time. */
+ // Below flags apply in the context of BIP 68. BIP 68 requires the tx
+ // version to be set to 2, or higher.
+ /**
+ * If this flag is set, CTxIn::nSequence is NOT interpreted as a
+ * relative lock-time.
+ * It skips SequenceLocks() for any input that has it set (BIP 68).
+ * It fails OP_CHECKSEQUENCEVERIFY/CheckSequence() for any input that has
+ * it set (BIP 112).
+ */
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1U << 31);
- /* If CTxIn::nSequence encodes a relative lock-time and this flag
+ /**
+ * If CTxIn::nSequence encodes a relative lock-time and this flag
* is set, the relative lock-time has units of 512 seconds,
* otherwise it specifies blocks with a granularity of 1. */
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
- /* If CTxIn::nSequence encodes a relative lock-time, this mask is
+ /**
+ * If CTxIn::nSequence encodes a relative lock-time, this mask is
* applied to extract that lock-time from the sequence field. */
static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
- /* In order to use the same number of bits to encode roughly the
+ /**
+ * In order to use the same number of bits to encode roughly the
* same wall-clock duration, and because blocks are naturally
* limited to occur every 600s on average, the minimum granularity
* for time-based relative lock-time is fixed at 512 seconds.
diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp
index 3459897fe5..e23fe34480 100644
--- a/src/rpc/rawtransaction_util.cpp
+++ b/src/rpc/rawtransaction_util.cpp
@@ -63,7 +63,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
if (rbf) {
nSequence = MAX_BIP125_RBF_SEQUENCE; /* CTxIn::SEQUENCE_FINAL - 2 */
} else if (rawTx.nLockTime) {
- nSequence = CTxIn::SEQUENCE_FINAL - 1;
+ nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; /* CTxIn::SEQUENCE_FINAL - 1 */
} else {
nSequence = CTxIn::SEQUENCE_FINAL;
}
diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp
index 47c2be3faa..2514636d6e 100644
--- a/src/test/fuzz/util.cpp
+++ b/src/test/fuzz/util.cpp
@@ -408,7 +408,7 @@ uint32_t ConsumeSequence(FuzzedDataProvider& fuzzed_data_provider) noexcept
return fuzzed_data_provider.ConsumeBool() ?
fuzzed_data_provider.PickValueInArray({
CTxIn::SEQUENCE_FINAL,
- CTxIn::SEQUENCE_FINAL - 1,
+ CTxIn::MAX_SEQUENCE_NONFINAL,
MAX_BIP125_RBF_SEQUENCE,
}) :
fuzzed_data_provider.ConsumeIntegral<uint32_t>();
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index e07eb95856..c453dae701 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
// absolute height locked
tx.vin[0].prevout.hash = txFirst[2]->GetHash();
- tx.vin[0].nSequence = CTxIn::SEQUENCE_FINAL - 1;
+ tx.vin[0].nSequence = CTxIn::MAX_SEQUENCE_NONFINAL;
prevheights[0] = baseheight + 3;
tx.nLockTime = m_node.chainman->ActiveChain().Tip()->nHeight + 1;
hash = tx.GetHash();
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index a42df8262c..3d8ae2da69 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -796,7 +796,7 @@ static bool CreateTransactionInternal(
// to avoid conflicting with other possible uses of nSequence,
// and in the spirit of "smallest possible change from prior
// behavior."
- const uint32_t nSequence = coin_control.m_signal_bip125_rbf.value_or(wallet.m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1);
+ const uint32_t nSequence{coin_control.m_signal_bip125_rbf.value_or(wallet.m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : CTxIn::MAX_SEQUENCE_NONFINAL};
for (const auto& coin : selected_coins) {
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
}