Skip to content

Commit fa47622

Browse files
committed
scripted-diff: rename variables in policy/rbf
"Fee Delta" is already a term used for prioritizing transactions: modified = base fees + delta Here, delta also means the difference between original and modified replacement fees: nDeltaFees = (original_base + original_delta) - (replacement_base + replacement_delta) This is insanely confusing. Also, since mempool is no longer a member of a class (MemPoolAccept.m_pool), the "m" prefix is unnecessary. The rest are clarity/style-focused changes to already-touched lines. -BEGIN VERIFY SCRIPT- ren() { sed -i "s/\<$1\>/$2/g" src/policy/rbf* ; } ren nDeltaFees additional_fees ren m_pool pool ren nSize replacement_vsize ren nModifiedFees replacement_fees ren nConflictingFees original_fees ren oldFeeRate original_feerate ren newFeeRate replacement_feerate ren setAncestors ancestors ren setIterConflicting iters_conflicting ren setConflictsParents parents_of_conflicts ren setConflicts direct_conflicts ren allConflicting all_conflicts sed -i "s/ hash\b/ txid/g" src/policy/rbf* -END VERIFY SCRIPT-
1 parent ac761f0 commit fa47622

File tree

2 files changed

+71
-71
lines changed

2 files changed

+71
-71
lines changed

src/policy/rbf.cpp

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
1313
{
1414
AssertLockHeld(pool.cs);
1515

16-
CTxMemPool::setEntries setAncestors;
16+
CTxMemPool::setEntries ancestors;
1717

1818
// First check the transaction itself.
1919
if (SignalsOptInRBF(tx)) {
@@ -31,9 +31,9 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
3131
uint64_t noLimit = std::numeric_limits<uint64_t>::max();
3232
std::string dummy;
3333
CTxMemPoolEntry entry = *pool.mapTx.find(tx.GetHash());
34-
pool.CalculateMemPoolAncestors(entry, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false);
34+
pool.CalculateMemPoolAncestors(entry, ancestors, noLimit, noLimit, noLimit, noLimit, dummy, false);
3535

36-
for (CTxMemPool::txiter it : setAncestors) {
36+
for (CTxMemPool::txiter it : ancestors) {
3737
if (SignalsOptInRBF(it->GetTx())) {
3838
return RBFTransactionState::REPLACEABLE_BIP125;
3939
}
@@ -48,43 +48,43 @@ RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx)
4848
}
4949

5050
std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx,
51-
CTxMemPool& m_pool,
52-
const CTxMemPool::setEntries& setIterConflicting,
53-
CTxMemPool::setEntries& allConflicting)
51+
CTxMemPool& pool,
52+
const CTxMemPool::setEntries& iters_conflicting,
53+
CTxMemPool::setEntries& all_conflicts)
5454
{
55-
AssertLockHeld(m_pool.cs);
56-
const uint256 hash = tx.GetHash();
55+
AssertLockHeld(pool.cs);
56+
const uint256 txid = tx.GetHash();
5757
uint64_t nConflictingCount = 0;
58-
for (const auto& mi : setIterConflicting) {
58+
for (const auto& mi : iters_conflicting) {
5959
nConflictingCount += mi->GetCountWithDescendants();
6060
// This potentially overestimates the number of actual descendants
6161
// but we just want to be conservative to avoid doing too much
6262
// work.
6363
if (nConflictingCount > MAX_BIP125_REPLACEMENT_CANDIDATES) {
6464
return strprintf("rejecting replacement %s; too many potential replacements (%d > %d)\n",
65-
hash.ToString(),
65+
txid.ToString(),
6666
nConflictingCount,
6767
MAX_BIP125_REPLACEMENT_CANDIDATES);
6868
}
6969
}
7070
// If not too many to replace, then calculate the set of
7171
// transactions that would have to be evicted
72-
for (CTxMemPool::txiter it : setIterConflicting) {
73-
m_pool.CalculateDescendants(it, allConflicting);
72+
for (CTxMemPool::txiter it : iters_conflicting) {
73+
pool.CalculateDescendants(it, all_conflicts);
7474
}
7575
return std::nullopt;
7676
}
7777

7878
std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
79-
const CTxMemPool& m_pool,
80-
const CTxMemPool::setEntries& setIterConflicting)
79+
const CTxMemPool& pool,
80+
const CTxMemPool::setEntries& iters_conflicting)
8181
{
82-
AssertLockHeld(m_pool.cs);
83-
std::set<uint256> setConflictsParents;
84-
for (const auto& mi : setIterConflicting) {
82+
AssertLockHeld(pool.cs);
83+
std::set<uint256> parents_of_conflicts;
84+
for (const auto& mi : iters_conflicting) {
8585
for (const CTxIn &txin : mi->GetTx().vin)
8686
{
87-
setConflictsParents.insert(txin.prevout.hash);
87+
parents_of_conflicts.insert(txin.prevout.hash);
8888
}
8989
}
9090

@@ -99,12 +99,12 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
9999
// this may break the CalculateMempoolAncestors RBF relaxation,
100100
// above. See the comment above the first CalculateMempoolAncestors
101101
// call for more info.
102-
if (!setConflictsParents.count(tx.vin[j].prevout.hash))
102+
if (!parents_of_conflicts.count(tx.vin[j].prevout.hash))
103103
{
104104
// Rather than check the UTXO set - potentially expensive -
105105
// it's cheaper to just check if the new input refers to a
106106
// tx that's in the mempool.
107-
if (m_pool.exists(tx.vin[j].prevout.hash)) {
107+
if (pool.exists(tx.vin[j].prevout.hash)) {
108108
return strprintf("replacement %s adds unconfirmed input, idx %d",
109109
tx.GetHash().ToString(), j);
110110
}
@@ -113,14 +113,14 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
113113
return std::nullopt;
114114
}
115115

116-
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& setAncestors,
117-
const std::set<uint256>& setConflicts,
116+
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,
117+
const std::set<uint256>& direct_conflicts,
118118
const uint256& txid)
119119
{
120-
for (CTxMemPool::txiter ancestorIt : setAncestors)
120+
for (CTxMemPool::txiter ancestorIt : ancestors)
121121
{
122122
const uint256 &hashAncestor = ancestorIt->GetTx().GetHash();
123-
if (setConflicts.count(hashAncestor))
123+
if (direct_conflicts.count(hashAncestor))
124124
{
125125
return strprintf("%s spends conflicting transaction %s",
126126
txid.ToString(),
@@ -130,11 +130,11 @@ std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries&
130130
return std::nullopt;
131131
}
132132

133-
std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& setIterConflicting,
134-
CFeeRate newFeeRate,
135-
const uint256& hash)
133+
std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& iters_conflicting,
134+
CFeeRate replacement_feerate,
135+
const uint256& txid)
136136
{
137-
for (const auto& mi : setIterConflicting) {
137+
for (const auto& mi : iters_conflicting) {
138138
// Don't allow the replacement to reduce the feerate of the
139139
// mempool.
140140
//
@@ -149,41 +149,41 @@ std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& s
149149
// mean high feerate children are ignored when deciding whether
150150
// or not to replace, we do require the replacement to pay more
151151
// overall fees too, mitigating most cases.
152-
CFeeRate oldFeeRate(mi->GetModifiedFee(), mi->GetTxSize());
153-
if (newFeeRate <= oldFeeRate)
152+
CFeeRate original_feerate(mi->GetModifiedFee(), mi->GetTxSize());
153+
if (replacement_feerate <= original_feerate)
154154
{
155155
return strprintf("rejecting replacement %s; new feerate %s <= old feerate %s",
156-
hash.ToString(),
157-
newFeeRate.ToString(),
158-
oldFeeRate.ToString());
156+
txid.ToString(),
157+
replacement_feerate.ToString(),
158+
original_feerate.ToString());
159159
}
160160
}
161161
return std::nullopt;
162162
}
163163

164-
std::optional<std::string> PaysForRBF(CAmount nConflictingFees,
165-
CAmount nModifiedFees,
166-
size_t nSize,
167-
const uint256& hash)
164+
std::optional<std::string> PaysForRBF(CAmount original_fees,
165+
CAmount replacement_fees,
166+
size_t replacement_vsize,
167+
const uint256& txid)
168168
{
169169
// The replacement must pay greater fees than the transactions it
170170
// replaces - if we did the bandwidth used by those conflicting
171171
// transactions would not be paid for.
172-
if (nModifiedFees < nConflictingFees)
172+
if (replacement_fees < original_fees)
173173
{
174174
return strprintf("rejecting replacement %s, less fees than conflicting txs; %s < %s",
175-
hash.ToString(), FormatMoney(nModifiedFees), FormatMoney(nConflictingFees));
175+
txid.ToString(), FormatMoney(replacement_fees), FormatMoney(original_fees));
176176
}
177177

178178
// Finally in addition to paying more fees than the conflicts the
179179
// new transaction must pay for its own bandwidth.
180-
CAmount nDeltaFees = nModifiedFees - nConflictingFees;
181-
if (nDeltaFees < ::incrementalRelayFee.GetFee(nSize))
180+
CAmount additional_fees = replacement_fees - original_fees;
181+
if (additional_fees < ::incrementalRelayFee.GetFee(replacement_vsize))
182182
{
183183
return strprintf("rejecting replacement %s, not enough additional fees to relay; %s < %s",
184-
hash.ToString(),
185-
FormatMoney(nDeltaFees),
186-
FormatMoney(::incrementalRelayFee.GetFee(nSize)));
184+
txid.ToString(),
185+
FormatMoney(additional_fees),
186+
FormatMoney(::incrementalRelayFee.GetFee(replacement_vsize)));
187187
}
188188
return std::nullopt;
189189
}

src/policy/rbf.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,61 +35,61 @@ enum class RBFTransactionState {
3535
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
3636
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx);
3737

38-
/** Get all descendants of setIterConflicting. Also enforce BIP125 Rule #5, "The number of original
38+
/** Get all descendants of iters_conflicting. Also enforce BIP125 Rule #5, "The number of original
3939
* transactions to be replaced and their descendant transactions which will be evicted from the
4040
* mempool must not exceed a total of 100 transactions." Quit as early as possible. There cannot be
4141
* more than MAX_BIP125_REPLACEMENT_CANDIDATES potential entries.
42-
* @param[in] setIterConflicting The set of iterators to mempool entries.
43-
* @param[out] allConflicting Populated with all the mempool entries that would be replaced,
44-
* which includes descendants of setIterConflicting. Not cleared at
42+
* @param[in] iters_conflicting The set of iterators to mempool entries.
43+
* @param[out] all_conflicts Populated with all the mempool entries that would be replaced,
44+
* which includes descendants of iters_conflicting. Not cleared at
4545
* the start; any existing mempool entries will remain in the set.
4646
* @returns an error message if Rule #5 is broken, otherwise a std::nullopt.
4747
*/
48-
std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx, CTxMemPool& m_pool,
49-
const CTxMemPool::setEntries& setIterConflicting,
50-
CTxMemPool::setEntries& allConflicting)
51-
EXCLUSIVE_LOCKS_REQUIRED(m_pool.cs);
48+
std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx, CTxMemPool& pool,
49+
const CTxMemPool::setEntries& iters_conflicting,
50+
CTxMemPool::setEntries& all_conflicts)
51+
EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
5252

5353
/** BIP125 Rule #2: "The replacement transaction may only include an unconfirmed input if that input
5454
* was included in one of the original transactions."
5555
* @returns error message if Rule #2 is broken, otherwise std::nullopt. */
56-
std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx, const CTxMemPool& m_pool,
57-
const CTxMemPool::setEntries& setIterConflicting)
58-
EXCLUSIVE_LOCKS_REQUIRED(m_pool.cs);
56+
std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx, const CTxMemPool& pool,
57+
const CTxMemPool::setEntries& iters_conflicting)
58+
EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
5959

6060
/** Check the intersection between two sets of transactions (a set of mempool entries and a set of
6161
* txids) to make sure they are disjoint.
62-
* @param[in] setAncestors Set of mempool entries corresponding to ancestors of the
62+
* @param[in] ancestors Set of mempool entries corresponding to ancestors of the
6363
* replacement transactions.
64-
* @param[in] setConflicts Set of txids corresponding to the mempool conflicts
64+
* @param[in] direct_conflicts Set of txids corresponding to the mempool conflicts
6565
* (candidates to be replaced).
6666
* @param[in] txid Transaction ID, included in the error message if violation occurs.
6767
* @returns error message if the sets intersect, std::nullopt if they are disjoint.
6868
*/
69-
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& setAncestors,
70-
const std::set<uint256>& setConflicts,
69+
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,
70+
const std::set<uint256>& direct_conflicts,
7171
const uint256& txid);
7272

7373
/** Check that the feerate of the replacement transaction(s) is higher than the feerate of each
74-
* of the transactions in setIterConflicting.
75-
* @param[in] setIterConflicting The set of mempool entries.
74+
* of the transactions in iters_conflicting.
75+
* @param[in] iters_conflicting The set of mempool entries.
7676
* @returns error message if fees insufficient, otherwise std::nullopt.
7777
*/
78-
std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& setIterConflicting,
79-
CFeeRate newFeeRate, const uint256& hash);
78+
std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& iters_conflicting,
79+
CFeeRate replacement_feerate, const uint256& txid);
8080

8181
/** Enforce BIP125 Rule #3 "The replacement transaction pays an absolute fee of at least the sum
8282
* paid by the original transactions." Enforce BIP125 Rule #4 "The replacement transaction must also
8383
* pay for its own bandwidth at or above the rate set by the node's minimum relay fee setting."
84-
* @param[in] nConflictingFees Total modified fees of original transaction(s).
85-
* @param[in] nModifiedFees Total modified fees of replacement transaction(s).
86-
* @param[in] nSize Total virtual size of replacement transaction(s).
87-
* @param[in] hash Transaction ID, included in the error message if violation occurs.
84+
* @param[in] original_fees Total modified fees of original transaction(s).
85+
* @param[in] replacement_fees Total modified fees of replacement transaction(s).
86+
* @param[in] replacement_vsize Total virtual size of replacement transaction(s).
87+
* @param[in] txid Transaction ID, included in the error message if violation occurs.
8888
* @returns error string if fees are insufficient, otherwise std::nullopt.
8989
*/
90-
std::optional<std::string> PaysForRBF(CAmount nConflictingFees,
91-
CAmount nModifiedFees,
92-
size_t nSize,
93-
const uint256& hash);
90+
std::optional<std::string> PaysForRBF(CAmount original_fees,
91+
CAmount replacement_fees,
92+
size_t replacement_vsize,
93+
const uint256& txid);
9494

9595
#endif // BITCOIN_POLICY_RBF_H

0 commit comments

Comments
 (0)