Skip to content

Commit a573dd2

Browse files
committed
[doc] replace mentions of v3 with TRUC
Keep mentions of v3 in debug strings to help people who might not know that TRUC is applied when version=3. Also keep variable names in tests, as it is less verbose to keep v3 and v2.
1 parent 089b575 commit a573dd2

File tree

9 files changed

+131
-130
lines changed

9 files changed

+131
-130
lines changed

src/policy/truc_policy.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct ParentInfo {
4343
const Txid& m_txid;
4444
/** Wtxid used for debug string */
4545
const Wtxid& m_wtxid;
46-
/** version used to check inheritance of v3 and non-v3 */
46+
/** version used to check inheritance of TRUC and non-TRUC */
4747
decltype(CTransaction::version) m_version;
4848
/** If parent is in mempool, whether it has any descendants in mempool. */
4949
bool m_has_mempool_descendant;
@@ -65,7 +65,7 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
6565

6666
const auto in_package_parents{FindInPackageParents(package, ptx)};
6767

68-
// Now we have all ancestors, so we can start checking v3 rules.
68+
// Now we have all ancestors, so we can start checking TRUC rules.
6969
if (ptx->version == TRUC_VERSION) {
7070
// SingleV3Checks should have checked this already.
7171
if (!Assume(vsize <= V3_MAX_VSIZE)) {
@@ -80,7 +80,7 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
8080

8181
const bool has_parent{mempool_ancestors.size() + in_package_parents.size() > 0};
8282
if (has_parent) {
83-
// A v3 child cannot be too large.
83+
// A TRUC child cannot be too large.
8484
if (vsize > V3_CHILD_MAX_VSIZE) {
8585
return strprintf("v3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
8686
ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
@@ -140,7 +140,7 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
140140
}
141141
}
142142
} else {
143-
// Non-v3 transactions cannot have v3 parents.
143+
// Non-TRUC transactions cannot have TRUC parents.
144144
for (auto it : mempool_ancestors) {
145145
if (it->GetTx().version == TRUC_VERSION) {
146146
return strprintf("non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)",
@@ -166,7 +166,7 @@ std::optional<std::pair<std::string, CTransactionRef>> SingleV3Checks(const CTra
166166
const std::set<Txid>& direct_conflicts,
167167
int64_t vsize)
168168
{
169-
// Check v3 and non-v3 inheritance.
169+
// Check TRUC and non-TRUC inheritance.
170170
for (const auto& entry : mempool_ancestors) {
171171
if (ptx->version != TRUC_VERSION && entry->GetTx().version == TRUC_VERSION) {
172172
return std::make_pair(strprintf("non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)",
@@ -203,7 +203,7 @@ std::optional<std::pair<std::string, CTransactionRef>> SingleV3Checks(const CTra
203203

204204
// Remaining checks only pertain to transactions with unconfirmed ancestors.
205205
if (mempool_ancestors.size() > 0) {
206-
// If this transaction spends V3 parents, it cannot be too large.
206+
// If this transaction spends TRUC parents, it cannot be too large.
207207
if (vsize > V3_CHILD_MAX_VSIZE) {
208208
return std::make_pair(strprintf("v3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
209209
ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(), vsize, V3_CHILD_MAX_VSIZE),
@@ -217,14 +217,14 @@ std::optional<std::pair<std::string, CTransactionRef>> SingleV3Checks(const CTra
217217
// possible through a reorg.
218218
const auto& children = parent_entry->GetMemPoolChildrenConst();
219219
// Don't double-count a transaction that is going to be replaced. This logic assumes that
220-
// any descendant of the V3 transaction is a direct child, which makes sense because a V3
221-
// transaction can only have 1 descendant.
220+
// any descendant of the TRUC transaction is a direct child, which makes sense because a
221+
// TRUC transaction can only have 1 descendant.
222222
const bool child_will_be_replaced = !children.empty() &&
223223
std::any_of(children.cbegin(), children.cend(),
224224
[&direct_conflicts](const CTxMemPoolEntry& child){return direct_conflicts.count(child.GetTx().GetHash()) > 0;});
225225
if (parent_entry->GetCountWithDescendants() + 1 > V3_DESCENDANT_LIMIT && !child_will_be_replaced) {
226-
// Allow sibling eviction for v3 transaction: if another child already exists, even if
227-
// we don't conflict inputs with it, consider evicting it under RBF rules. We rely on v3 rules
226+
// Allow sibling eviction for TRUC transaction: if another child already exists, even if
227+
// we don't conflict inputs with it, consider evicting it under RBF rules. We rely on TRUC rules
228228
// only permitting 1 descendant, as otherwise we would need to have logic for deciding
229229
// which descendant to evict. Skip if this isn't true, e.g. if the transaction has
230230
// multiple children or the sibling also has descendants due to a reorg.

src/policy/truc_policy.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,36 @@
1515
#include <set>
1616
#include <string>
1717

18-
// This module enforces rules for BIP 431 TRUC transactions (with version=3) which help make
19-
// RBF abilities more robust.
18+
// This module enforces rules for BIP 431 TRUC transactions which help make
19+
// RBF abilities more robust. A transaction with version=3 is treated as TRUC.
2020
static constexpr decltype(CTransaction::version) TRUC_VERSION{3};
2121

22-
// v3 only allows 1 parent and 1 child when unconfirmed.
22+
// TRUC only allows 1 parent and 1 child when unconfirmed. This translates to a descendant set size
23+
// of 2 and ancestor set size of 2.
2324
/** Maximum number of transactions including an unconfirmed tx and its descendants. */
2425
static constexpr unsigned int V3_DESCENDANT_LIMIT{2};
25-
/** Maximum number of transactions including a V3 tx and all its mempool ancestors. */
26+
/** Maximum number of transactions including a TRUC tx and all its mempool ancestors. */
2627
static constexpr unsigned int V3_ANCESTOR_LIMIT{2};
2728

2829
/** Maximum sigop-adjusted virtual size of all v3 transactions. */
2930
static constexpr int64_t V3_MAX_VSIZE{10000};
30-
/** Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed v3 transaction. */
31+
/** Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed TRUC transaction. */
3132
static constexpr int64_t V3_CHILD_MAX_VSIZE{1000};
3233
// These limits are within the default ancestor/descendant limits.
3334
static_assert(V3_MAX_VSIZE + V3_CHILD_MAX_VSIZE <= DEFAULT_ANCESTOR_SIZE_LIMIT_KVB * 1000);
3435
static_assert(V3_MAX_VSIZE + V3_CHILD_MAX_VSIZE <= DEFAULT_DESCENDANT_SIZE_LIMIT_KVB * 1000);
3536

36-
/** Must be called for every transaction, even if not v3. Not strictly necessary for transactions
37+
/** Must be called for every transaction, even if not TRUC. Not strictly necessary for transactions
3738
* accepted through AcceptMultipleTransactions.
3839
*
3940
* Checks the following rules:
40-
* 1. A v3 tx must only have v3 unconfirmed ancestors.
41-
* 2. A non-v3 tx must only have non-v3 unconfirmed ancestors.
42-
* 3. A v3's ancestor set, including itself, must be within V3_ANCESTOR_LIMIT.
43-
* 4. A v3's descendant set, including itself, must be within V3_DESCENDANT_LIMIT.
44-
* 5. If a v3 tx has any unconfirmed ancestors, the tx's sigop-adjusted vsize must be within
41+
* 1. A TRUC tx must only have TRUC unconfirmed ancestors.
42+
* 2. A non-TRUC tx must only have non-TRUC unconfirmed ancestors.
43+
* 3. A TRUC's ancestor set, including itself, must be within V3_ANCESTOR_LIMIT.
44+
* 4. A TRUC's descendant set, including itself, must be within V3_DESCENDANT_LIMIT.
45+
* 5. If a TRUC tx has any unconfirmed ancestors, the tx's sigop-adjusted vsize must be within
4546
* V3_CHILD_MAX_VSIZE.
46-
* 6. A v3 tx must be within V3_MAX_VSIZE.
47+
* 6. A TRUC tx must be within V3_MAX_VSIZE.
4748
*
4849
*
4950
* @param[in] mempool_ancestors The in-mempool ancestors of ptx.
@@ -53,35 +54,35 @@ static_assert(V3_MAX_VSIZE + V3_CHILD_MAX_VSIZE <= DEFAULT_DESCENDANT_SIZE_LIMIT
5354
* @param[in] vsize The sigop-adjusted virtual size of ptx.
5455
*
5556
* @returns 3 possibilities:
56-
* - std::nullopt if all v3 checks were applied successfully
57+
* - std::nullopt if all TRUC checks were applied successfully
5758
* - debug string + pointer to a mempool sibling if this transaction would be the second child in a
5859
* 1-parent-1-child cluster; the caller may consider evicting the specified sibling or return an
5960
* error with the debug string.
60-
* - debug string + nullptr if this transaction violates some v3 rule and sibling eviction is not
61+
* - debug string + nullptr if this transaction violates some TRUC rule and sibling eviction is not
6162
* applicable.
6263
*/
6364
std::optional<std::pair<std::string, CTransactionRef>> SingleV3Checks(const CTransactionRef& ptx,
6465
const CTxMemPool::setEntries& mempool_ancestors,
6566
const std::set<Txid>& direct_conflicts,
6667
int64_t vsize);
6768

68-
/** Must be called for every transaction that is submitted within a package, even if not v3.
69+
/** Must be called for every transaction that is submitted within a package, even if not TRUC.
6970
*
7071
* For each transaction in a package:
71-
* If it's not a v3 transaction, verify it has no direct v3 parents in the mempool or the package.
72+
* If it's not a TRUC transaction, verify it has no direct TRUC parents in the mempool or the package.
7273
73-
* If it is a v3 transaction, verify that any direct parents in the mempool or the package are v3.
74+
* If it is a TRUC transaction, verify that any direct parents in the mempool or the package are TRUC.
7475
* If such a parent exists, verify that parent has no other children in the package or the mempool,
7576
* and that the transaction itself has no children in the package.
7677
*
77-
* If any v3 violations in the package exist, this test will fail for one of them:
78-
* - if a v3 transaction T has a parent in the mempool and a child in the package, then PV3C(T) will fail
79-
* - if a v3 transaction T has a parent in the package and a child in the package, then PV3C(T) will fail
80-
* - if a v3 transaction T and a v3 (sibling) transaction U have some parent in the mempool,
78+
* If any TRUC violations in the package exist, this test will fail for one of them:
79+
* - if a TRUC transaction T has a parent in the mempool and a child in the package, then PV3C(T) will fail
80+
* - if a TRUC transaction T has a parent in the package and a child in the package, then PV3C(T) will fail
81+
* - if a TRUC transaction T and a TRUC (sibling) transaction U have some parent in the mempool,
8182
* then PV3C(T) and PV3C(U) will fail
82-
* - if a v3 transaction T and a v3 (sibling) transaction U have some parent in the package,
83+
* - if a TRUC transaction T and a TRUC (sibling) transaction U have some parent in the package,
8384
* then PV3C(T) and PV3C(U) will fail
84-
* - if a v3 transaction T has a parent P and a grandparent G in the package, then
85+
* - if a TRUC transaction T has a parent P and a grandparent G in the package, then
8586
* PV3C(P) will fail (though PV3C(G) and PV3C(T) might succeed).
8687
*
8788
* @returns debug string if an error occurs, std::nullopt otherwise.

src/test/fuzz/package_eval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
225225
tx_mut.vin.emplace_back();
226226
}
227227

228-
// Make a p2pk output to make sigops adjusted vsize to violate v3, potentially, which is never spent
228+
// Make a p2pk output to make sigops adjusted vsize to violate TRUC rules, potentially, which is never spent
229229
if (last_tx && amount_in > 1000 && fuzzed_data_provider.ConsumeBool()) {
230230
tx_mut.vout.emplace_back(1000, CScript() << std::vector<unsigned char>(33, 0x02) << OP_CHECKSIG);
231231
// Don't add any other outputs.

src/test/txvalidation_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static inline CTransactionRef make_tx(const std::vector<COutPoint>& inputs, int3
9191

9292
BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
9393
{
94-
// Test V3 policy helper functions
94+
// Test TRUC policy helper functions
9595
CTxMemPool& pool = *Assert(m_node.mempool);
9696
LOCK2(cs_main, pool.cs);
9797
TestMemPoolEntryHelper entry;
@@ -105,7 +105,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
105105
// Default values.
106106
CTxMemPool::Limits m_limits{};
107107

108-
// Cannot spend from an unconfirmed v3 transaction unless this tx is also v3.
108+
// Cannot spend from an unconfirmed TRUC transaction unless this tx is also TRUC.
109109
{
110110
// mempool_tx_v3
111111
// ^
@@ -140,7 +140,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
140140
BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v2_from_v2_and_v3, GetVirtualTransactionSize(*tx_v2_from_v2_and_v3), package_v3_v2_v2, empty_ancestors), expected_error_str_2);
141141
}
142142

143-
// V3 cannot spend from an unconfirmed non-v3 transaction.
143+
// TRUC cannot spend from an unconfirmed non-TRUC transaction.
144144
{
145145
// mempool_tx_v2
146146
// ^
@@ -202,7 +202,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
202202
BOOST_CHECK(PackageV3Checks(tx_v2_from_v2, GetVirtualTransactionSize(*tx_v2_from_v2), package_v2_v2, empty_ancestors) == std::nullopt);
203203
}
204204

205-
// Tx spending v3 cannot have too many mempool ancestors
205+
// Tx spending TRUC cannot have too many mempool ancestors
206206
// Configuration where the tx has multiple direct parents.
207207
{
208208
Package package_multi_parents;
@@ -255,7 +255,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
255255
BOOST_CHECK(PackageV3Checks(tx_v3_multi_gen, GetVirtualTransactionSize(*tx_v3_multi_gen), package_multi_gen, empty_ancestors) == std::nullopt);
256256
}
257257

258-
// Tx spending v3 cannot be too large in virtual size.
258+
// Tx spending TRUC cannot be too large in virtual size.
259259
auto many_inputs{random_outpoints(100)};
260260
many_inputs.emplace_back(mempool_tx_v3->GetHash(), 0);
261261
{
@@ -273,7 +273,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
273273
expected_error_str);
274274
}
275275

276-
// Tx spending v3 cannot have too many sigops.
276+
// Tx spending TRUC cannot have too many sigops.
277277
// This child has 10 P2WSH multisig inputs.
278278
auto multisig_outpoints{random_outpoints(10)};
279279
multisig_outpoints.emplace_back(mempool_tx_v3->GetHash(), 0);
@@ -317,7 +317,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
317317
expected_error_str);
318318
}
319319

320-
// Parent + child with v3 in the mempool. Child is allowed as long as it is under V3_CHILD_MAX_VSIZE.
320+
// Parent + child with TRUC in the mempool. Child is allowed as long as it is under V3_CHILD_MAX_VSIZE.
321321
auto tx_mempool_v3_child = make_tx({COutPoint{mempool_tx_v3->GetHash(), 0}}, /*version=*/3);
322322
{
323323
BOOST_CHECK(GetTransactionWeight(*tx_mempool_v3_child) <= V3_CHILD_MAX_VSIZE * WITNESS_SCALE_FACTOR);
@@ -329,7 +329,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
329329
BOOST_CHECK(PackageV3Checks(tx_mempool_v3_child, GetVirtualTransactionSize(*tx_mempool_v3_child), package_v3_1p1c, empty_ancestors) == std::nullopt);
330330
}
331331

332-
// A v3 transaction cannot have more than 1 descendant. Sibling is returned when exactly 1 exists.
332+
// A TRUC transaction cannot have more than 1 descendant. Sibling is returned when exactly 1 exists.
333333
{
334334
auto tx_v3_child2 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 1}}, /*version=*/3);
335335

src/test/util/txmempool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void CheckMempoolV3Invariants(const CTxMemPool& tx_pool)
150150
// Check that special maximum virtual size is respected
151151
Assert(entry.GetTxSize() <= V3_MAX_VSIZE);
152152

153-
// Check that special v3 ancestor/descendant limits and rules are always respected
153+
// Check that special TRUC ancestor/descendant limits and rules are always respected
154154
Assert(entry.GetCountWithDescendants() <= V3_DESCENDANT_LIMIT);
155155
Assert(entry.GetCountWithAncestors() <= V3_ANCESTOR_LIMIT);
156156
Assert(entry.GetSizeWithDescendants() <= V3_MAX_VSIZE + V3_CHILD_MAX_VSIZE);
@@ -159,12 +159,12 @@ void CheckMempoolV3Invariants(const CTxMemPool& tx_pool)
159159
// If this transaction has at least 1 ancestor, it's a "child" and has restricted weight.
160160
if (entry.GetCountWithAncestors() > 1) {
161161
Assert(entry.GetTxSize() <= V3_CHILD_MAX_VSIZE);
162-
// All v3 transactions must only have v3 unconfirmed parents.
162+
// All TRUC transactions must only have TRUC unconfirmed parents.
163163
const auto& parents = entry.GetMemPoolParentsConst();
164164
Assert(parents.begin()->get().GetSharedTx()->version == TRUC_VERSION);
165165
}
166166
} else if (entry.GetCountWithAncestors() > 1) {
167-
// All non-v3 transactions must only have non-v3 unconfirmed parents.
167+
// All non-TRUC transactions must only have non-TRUC unconfirmed parents.
168168
for (const auto& parent : entry.GetMemPoolParentsConst()) {
169169
Assert(parent.get().GetSharedTx()->version != TRUC_VERSION);
170170
}

src/test/util/txmempool.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
4747
bool expect_valid,
4848
const CTxMemPool* mempool);
4949

50-
/** For every transaction in tx_pool, check v3 invariants:
51-
* - a v3 tx's ancestor count must be within V3_ANCESTOR_LIMIT
52-
* - a v3 tx's descendant count must be within V3_DESCENDANT_LIMIT
53-
* - if a v3 tx has ancestors, its sigop-adjusted vsize must be within V3_CHILD_MAX_VSIZE
54-
* - any non-v3 tx must only have non-v3 parents
55-
* - any v3 tx must only have v3 parents
50+
/** For every transaction in tx_pool, check TRUC invariants:
51+
* - a TRUC tx's ancestor count must be within V3_ANCESTOR_LIMIT
52+
* - a TRUC tx's descendant count must be within V3_DESCENDANT_LIMIT
53+
* - if a TRUC tx has ancestors, its sigop-adjusted vsize must be within V3_CHILD_MAX_VSIZE
54+
* - any non-TRUC tx must only have non-TRUC parents
55+
* - any TRUC tx must only have TRUC parents
5656
* */
5757
void CheckMempoolV3Invariants(const CTxMemPool& tx_pool);
5858

0 commit comments

Comments
 (0)