2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
- #include < policy/v3_policy .h>
5
+ #include < policy/truc_policy .h>
6
6
7
7
#include < coins.h>
8
8
#include < consensus/amount.h>
14
14
#include < numeric>
15
15
#include < vector>
16
16
17
- /* * Helper for PackageV3Checks : Returns a vector containing the indices of transactions (within
17
+ /* * Helper for PackageTRUCChecks : Returns a vector containing the indices of transactions (within
18
18
* package) that are direct parents of ptx. */
19
19
std::vector<size_t > FindInPackageParents (const Package& package, const CTransactionRef& ptx)
20
20
{
@@ -37,13 +37,13 @@ std::vector<size_t> FindInPackageParents(const Package& package, const CTransact
37
37
return in_package_parents;
38
38
}
39
39
40
- /* * Helper for PackageV3Checks , storing info for a mempool or package parent. */
40
+ /* * Helper for PackageTRUCChecks , storing info for a mempool or package parent. */
41
41
struct ParentInfo {
42
42
/* * Txid used to identify this parent by prevout */
43
43
const Txid& m_txid;
44
44
/* * Wtxid used for debug string */
45
45
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 */
47
47
decltype (CTransaction::version) m_version;
48
48
/* * If parent is in mempool, whether it has any descendants in mempool. */
49
49
bool m_has_mempool_descendant;
@@ -55,36 +55,36 @@ struct ParentInfo {
55
55
{}
56
56
};
57
57
58
- std::optional<std::string> PackageV3Checks (const CTransactionRef& ptx, int64_t vsize,
58
+ std::optional<std::string> PackageTRUCChecks (const CTransactionRef& ptx, int64_t vsize,
59
59
const Package& package,
60
60
const CTxMemPool::setEntries& mempool_ancestors)
61
61
{
62
62
// This function is specialized for these limits, and must be reimplemented if they ever change.
63
- static_assert (V3_ANCESTOR_LIMIT == 2 );
64
- static_assert (V3_DESCENDANT_LIMIT == 2 );
63
+ static_assert (TRUC_ANCESTOR_LIMIT == 2 );
64
+ static_assert (TRUC_DESCENDANT_LIMIT == 2 );
65
65
66
66
const auto in_package_parents{FindInPackageParents (package, ptx)};
67
67
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.
69
69
if (ptx->version == TRUC_VERSION) {
70
- // SingleV3Checks should have checked this already.
71
- if (!Assume (vsize <= V3_MAX_VSIZE )) {
72
- return strprintf (" v3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
73
- ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (), vsize, V3_MAX_VSIZE );
70
+ // SingleTRUCChecks should have checked this already.
71
+ if (!Assume (vsize <= TRUC_MAX_VSIZE )) {
72
+ return strprintf (" version=3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
73
+ ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (), vsize, TRUC_MAX_VSIZE );
74
74
}
75
75
76
- if (mempool_ancestors.size () + in_package_parents.size () + 1 > V3_ANCESTOR_LIMIT ) {
76
+ if (mempool_ancestors.size () + in_package_parents.size () + 1 > TRUC_ANCESTOR_LIMIT ) {
77
77
return strprintf (" tx %s (wtxid=%s) would have too many ancestors" ,
78
78
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString ());
79
79
}
80
80
81
81
const bool has_parent{mempool_ancestors.size () + in_package_parents.size () > 0 };
82
82
if (has_parent) {
83
- // A v3 child cannot be too large.
84
- if (vsize > V3_CHILD_MAX_VSIZE ) {
85
- return strprintf (" v3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
83
+ // A TRUC child cannot be too large.
84
+ if (vsize > TRUC_CHILD_MAX_VSIZE ) {
85
+ return strprintf (" version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
86
86
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (),
87
- vsize, V3_CHILD_MAX_VSIZE );
87
+ vsize, TRUC_CHILD_MAX_VSIZE );
88
88
}
89
89
90
90
// Exactly 1 parent exists, either in mempool or package. Find it.
@@ -107,7 +107,7 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
107
107
108
108
// If there is a parent, it must have the right version.
109
109
if (parent_info.m_version != TRUC_VERSION) {
110
- return strprintf (" v3 tx %s (wtxid=%s) cannot spend from non-v3 tx %s (wtxid=%s)" ,
110
+ return strprintf (" version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)" ,
111
111
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (),
112
112
parent_info.m_txid .ToString (), parent_info.m_wtxid .ToString ());
113
113
}
@@ -118,7 +118,7 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
118
118
119
119
for (auto & input : package_tx->vin ) {
120
120
// Fail if we find another tx with the same parent. We don't check whether the
121
- // sibling is to-be-replaced (done in SingleV3Checks ) because these transactions
121
+ // sibling is to-be-replaced (done in SingleTRUCChecks ) because these transactions
122
122
// are within the same package.
123
123
if (input.prevout .hash == parent_info.m_txid ) {
124
124
return strprintf (" tx %s (wtxid=%s) would exceed descendant count limit" ,
@@ -140,17 +140,17 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
140
140
}
141
141
}
142
142
} else {
143
- // Non-v3 transactions cannot have v3 parents.
143
+ // Non-TRUC transactions cannot have TRUC parents.
144
144
for (auto it : mempool_ancestors) {
145
145
if (it->GetTx ().version == TRUC_VERSION) {
146
- return strprintf (" non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)" ,
146
+ return strprintf (" non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)" ,
147
147
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (),
148
148
it->GetSharedTx ()->GetHash ().ToString (), it->GetSharedTx ()->GetWitnessHash ().ToString ());
149
149
}
150
150
}
151
151
for (const auto & index: in_package_parents) {
152
152
if (package.at (index)->version == TRUC_VERSION) {
153
- return strprintf (" non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)" ,
153
+ return strprintf (" non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)" ,
154
154
ptx->GetHash ().ToString (),
155
155
ptx->GetWitnessHash ().ToString (),
156
156
package.at (index)->GetHash ().ToString (),
@@ -161,52 +161,52 @@ std::optional<std::string> PackageV3Checks(const CTransactionRef& ptx, int64_t v
161
161
return std::nullopt;
162
162
}
163
163
164
- std::optional<std::pair<std::string, CTransactionRef>> SingleV3Checks (const CTransactionRef& ptx,
164
+ std::optional<std::pair<std::string, CTransactionRef>> SingleTRUCChecks (const CTransactionRef& ptx,
165
165
const CTxMemPool::setEntries& mempool_ancestors,
166
166
const std::set<Txid>& direct_conflicts,
167
167
int64_t vsize)
168
168
{
169
- // Check v3 and non-v3 inheritance.
169
+ // Check TRUC and non-TRUC inheritance.
170
170
for (const auto & entry : mempool_ancestors) {
171
171
if (ptx->version != TRUC_VERSION && entry->GetTx ().version == TRUC_VERSION) {
172
- return std::make_pair (strprintf (" non-v3 tx %s (wtxid=%s) cannot spend from v3 tx %s (wtxid=%s)" ,
172
+ return std::make_pair (strprintf (" non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)" ,
173
173
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (),
174
174
entry->GetSharedTx ()->GetHash ().ToString (), entry->GetSharedTx ()->GetWitnessHash ().ToString ()),
175
175
nullptr );
176
176
} else if (ptx->version == TRUC_VERSION && entry->GetTx ().version != TRUC_VERSION) {
177
- return std::make_pair (strprintf (" v3 tx %s (wtxid=%s) cannot spend from non-v3 tx %s (wtxid=%s)" ,
177
+ return std::make_pair (strprintf (" version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)" ,
178
178
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (),
179
179
entry->GetSharedTx ()->GetHash ().ToString (), entry->GetSharedTx ()->GetWitnessHash ().ToString ()),
180
180
nullptr );
181
181
}
182
182
}
183
183
184
184
// This function is specialized for these limits, and must be reimplemented if they ever change.
185
- static_assert (V3_ANCESTOR_LIMIT == 2 );
186
- static_assert (V3_DESCENDANT_LIMIT == 2 );
185
+ static_assert (TRUC_ANCESTOR_LIMIT == 2 );
186
+ static_assert (TRUC_DESCENDANT_LIMIT == 2 );
187
187
188
188
// The rest of the rules only apply to transactions with version=3.
189
189
if (ptx->version != TRUC_VERSION) return std::nullopt;
190
190
191
- if (vsize > V3_MAX_VSIZE ) {
192
- return std::make_pair (strprintf (" v3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
193
- ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (), vsize, V3_MAX_VSIZE ),
191
+ if (vsize > TRUC_MAX_VSIZE ) {
192
+ return std::make_pair (strprintf (" version=3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
193
+ ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (), vsize, TRUC_MAX_VSIZE ),
194
194
nullptr );
195
195
}
196
196
197
- // Check that V3_ANCESTOR_LIMIT would not be violated.
198
- if (mempool_ancestors.size () + 1 > V3_ANCESTOR_LIMIT ) {
197
+ // Check that TRUC_ANCESTOR_LIMIT would not be violated.
198
+ if (mempool_ancestors.size () + 1 > TRUC_ANCESTOR_LIMIT ) {
199
199
return std::make_pair (strprintf (" tx %s (wtxid=%s) would have too many ancestors" ,
200
200
ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString ()),
201
201
nullptr );
202
202
}
203
203
204
204
// Remaining checks only pertain to transactions with unconfirmed ancestors.
205
205
if (mempool_ancestors.size () > 0 ) {
206
- // If this transaction spends V3 parents, it cannot be too large.
207
- if (vsize > V3_CHILD_MAX_VSIZE ) {
208
- return std::make_pair (strprintf (" v3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
209
- ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (), vsize, V3_CHILD_MAX_VSIZE ),
206
+ // If this transaction spends TRUC parents, it cannot be too large.
207
+ if (vsize > TRUC_CHILD_MAX_VSIZE ) {
208
+ return std::make_pair (strprintf (" version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes" ,
209
+ ptx->GetHash ().ToString (), ptx->GetWitnessHash ().ToString (), vsize, TRUC_CHILD_MAX_VSIZE ),
210
210
nullptr );
211
211
}
212
212
@@ -217,14 +217,14 @@ std::optional<std::pair<std::string, CTransactionRef>> SingleV3Checks(const CTra
217
217
// possible through a reorg.
218
218
const auto & children = parent_entry->GetMemPoolChildrenConst ();
219
219
// 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.
222
222
const bool child_will_be_replaced = !children.empty () &&
223
223
std::any_of (children.cbegin (), children.cend (),
224
224
[&direct_conflicts](const CTxMemPoolEntry& child){return direct_conflicts.count (child.GetTx ().GetHash ()) > 0 ;});
225
- 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
225
+ if (parent_entry->GetCountWithDescendants () + 1 > TRUC_DESCENDANT_LIMIT && !child_will_be_replaced) {
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
228
228
// only permitting 1 descendant, as otherwise we would need to have logic for deciding
229
229
// which descendant to evict. Skip if this isn't true, e.g. if the transaction has
230
230
// multiple children or the sibling also has descendants due to a reorg.
0 commit comments