Skip to content

Commit 7c4f009

Browse files
ryanofskyjnewbery
authored andcommitted
[trivial] Rename feebumper variables according to project code style
Future PRs will completely refactor this translation unit and touch all this code so we rename the variables to follow project stlye guidelines in this preparation commit. Don't use m_ prefixes for member variables since we're going to remove the class entirely in the next commits.
1 parent 05a7619 commit 7c4f009

File tree

4 files changed

+102
-102
lines changed

4 files changed

+102
-102
lines changed

src/qt/walletmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,12 @@ bool WalletModel::transactionCanBeBumped(uint256 hash) const
666666

667667
bool WalletModel::bumpFee(uint256 hash)
668668
{
669-
std::unique_ptr<CFeeBumper> feeBump;
669+
std::unique_ptr<FeeBumper> feeBump;
670670
{
671671
CCoinControl coin_control;
672672
coin_control.signalRbf = true;
673673
LOCK2(cs_main, wallet->cs_wallet);
674-
feeBump.reset(new CFeeBumper(wallet, hash, coin_control, 0));
674+
feeBump.reset(new FeeBumper(wallet, hash, coin_control, 0));
675675
}
676676
if (feeBump->getResult() != BumpFeeResult::OK)
677677
{

src/wallet/feebumper.cpp

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -23,123 +23,123 @@
2323
// calculation, but we should be able to refactor after priority is removed).
2424
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should
2525
// be IsAllFromMe).
26-
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *pWallet)
26+
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet)
2727
{
2828
CMutableTransaction txNew(tx);
2929
std::vector<CInputCoin> vCoins;
3030
// Look up the inputs. We should have already checked that this transaction
3131
// IsAllFromMe(ISMINE_SPENDABLE), so every input should already be in our
3232
// wallet, with a valid index into the vout array.
3333
for (auto& input : tx.vin) {
34-
const auto mi = pWallet->mapWallet.find(input.prevout.hash);
35-
assert(mi != pWallet->mapWallet.end() && input.prevout.n < mi->second.tx->vout.size());
34+
const auto mi = wallet->mapWallet.find(input.prevout.hash);
35+
assert(mi != wallet->mapWallet.end() && input.prevout.n < mi->second.tx->vout.size());
3636
vCoins.emplace_back(CInputCoin(&(mi->second), input.prevout.n));
3737
}
38-
if (!pWallet->DummySignTx(txNew, vCoins)) {
38+
if (!wallet->DummySignTx(txNew, vCoins)) {
3939
// This should never happen, because IsAllFromMe(ISMINE_SPENDABLE)
4040
// implies that we can sign for every input.
4141
return -1;
4242
}
4343
return GetVirtualTransactionSize(txNew);
4444
}
4545

46-
bool CFeeBumper::preconditionChecks(const CWallet *pWallet, const CWalletTx& wtx) {
47-
if (pWallet->HasWalletSpend(wtx.GetHash())) {
48-
vErrors.push_back("Transaction has descendants in the wallet");
49-
currentResult = BumpFeeResult::INVALID_PARAMETER;
46+
bool FeeBumper::preconditionChecks(const CWallet *wallet, const CWalletTx& wtx) {
47+
if (wallet->HasWalletSpend(wtx.GetHash())) {
48+
errors.push_back("Transaction has descendants in the wallet");
49+
current_result = BumpFeeResult::INVALID_PARAMETER;
5050
return false;
5151
}
5252

5353
{
5454
LOCK(mempool.cs);
5555
auto it_mp = mempool.mapTx.find(wtx.GetHash());
5656
if (it_mp != mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1) {
57-
vErrors.push_back("Transaction has descendants in the mempool");
58-
currentResult = BumpFeeResult::INVALID_PARAMETER;
57+
errors.push_back("Transaction has descendants in the mempool");
58+
current_result = BumpFeeResult::INVALID_PARAMETER;
5959
return false;
6060
}
6161
}
6262

6363
if (wtx.GetDepthInMainChain() != 0) {
64-
vErrors.push_back("Transaction has been mined, or is conflicted with a mined transaction");
65-
currentResult = BumpFeeResult::WALLET_ERROR;
64+
errors.push_back("Transaction has been mined, or is conflicted with a mined transaction");
65+
current_result = BumpFeeResult::WALLET_ERROR;
6666
return false;
6767
}
6868
return true;
6969
}
7070

71-
CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoinControl& coin_control, CAmount totalFee)
71+
FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinControl& coin_control, CAmount total_fee)
7272
:
73-
txid(std::move(txidIn)),
74-
nOldFee(0),
75-
nNewFee(0)
73+
txid(std::move(txid_in)),
74+
old_fee(0),
75+
new_fee(0)
7676
{
77-
vErrors.clear();
78-
bumpedTxid.SetNull();
79-
AssertLockHeld(pWallet->cs_wallet);
80-
auto it = pWallet->mapWallet.find(txid);
81-
if (it == pWallet->mapWallet.end()) {
82-
vErrors.push_back("Invalid or non-wallet transaction id");
83-
currentResult = BumpFeeResult::INVALID_ADDRESS_OR_KEY;
77+
errors.clear();
78+
bumped_txid.SetNull();
79+
AssertLockHeld(wallet->cs_wallet);
80+
auto it = wallet->mapWallet.find(txid);
81+
if (it == wallet->mapWallet.end()) {
82+
errors.push_back("Invalid or non-wallet transaction id");
83+
current_result = BumpFeeResult::INVALID_ADDRESS_OR_KEY;
8484
return;
8585
}
8686
const CWalletTx& wtx = it->second;
8787

88-
if (!preconditionChecks(pWallet, wtx)) {
88+
if (!preconditionChecks(wallet, wtx)) {
8989
return;
9090
}
9191

9292
if (!SignalsOptInRBF(*wtx.tx)) {
93-
vErrors.push_back("Transaction is not BIP 125 replaceable");
94-
currentResult = BumpFeeResult::WALLET_ERROR;
93+
errors.push_back("Transaction is not BIP 125 replaceable");
94+
current_result = BumpFeeResult::WALLET_ERROR;
9595
return;
9696
}
9797

9898
if (wtx.mapValue.count("replaced_by_txid")) {
99-
vErrors.push_back(strprintf("Cannot bump transaction %s which was already bumped by transaction %s", txid.ToString(), wtx.mapValue.at("replaced_by_txid")));
100-
currentResult = BumpFeeResult::WALLET_ERROR;
99+
errors.push_back(strprintf("Cannot bump transaction %s which was already bumped by transaction %s", txid.ToString(), wtx.mapValue.at("replaced_by_txid")));
100+
current_result = BumpFeeResult::WALLET_ERROR;
101101
return;
102102
}
103103

104104
// check that original tx consists entirely of our inputs
105105
// if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
106-
if (!pWallet->IsAllFromMe(*wtx.tx, ISMINE_SPENDABLE)) {
107-
vErrors.push_back("Transaction contains inputs that don't belong to this wallet");
108-
currentResult = BumpFeeResult::WALLET_ERROR;
106+
if (!wallet->IsAllFromMe(*wtx.tx, ISMINE_SPENDABLE)) {
107+
errors.push_back("Transaction contains inputs that don't belong to this wallet");
108+
current_result = BumpFeeResult::WALLET_ERROR;
109109
return;
110110
}
111111

112112
// figure out which output was change
113113
// if there was no change output or multiple change outputs, fail
114114
int nOutput = -1;
115115
for (size_t i = 0; i < wtx.tx->vout.size(); ++i) {
116-
if (pWallet->IsChange(wtx.tx->vout[i])) {
116+
if (wallet->IsChange(wtx.tx->vout[i])) {
117117
if (nOutput != -1) {
118-
vErrors.push_back("Transaction has multiple change outputs");
119-
currentResult = BumpFeeResult::WALLET_ERROR;
118+
errors.push_back("Transaction has multiple change outputs");
119+
current_result = BumpFeeResult::WALLET_ERROR;
120120
return;
121121
}
122122
nOutput = i;
123123
}
124124
}
125125
if (nOutput == -1) {
126-
vErrors.push_back("Transaction does not have a change output");
127-
currentResult = BumpFeeResult::WALLET_ERROR;
126+
errors.push_back("Transaction does not have a change output");
127+
current_result = BumpFeeResult::WALLET_ERROR;
128128
return;
129129
}
130130

131131
// Calculate the expected size of the new transaction.
132132
int64_t txSize = GetVirtualTransactionSize(*(wtx.tx));
133-
const int64_t maxNewTxSize = CalculateMaximumSignedTxSize(*wtx.tx, pWallet);
133+
const int64_t maxNewTxSize = CalculateMaximumSignedTxSize(*wtx.tx, wallet);
134134
if (maxNewTxSize < 0) {
135-
vErrors.push_back("Transaction contains inputs that cannot be signed");
136-
currentResult = BumpFeeResult::INVALID_ADDRESS_OR_KEY;
135+
errors.push_back("Transaction contains inputs that cannot be signed");
136+
current_result = BumpFeeResult::INVALID_ADDRESS_OR_KEY;
137137
return;
138138
}
139139

140140
// calculate the old fee and fee-rate
141-
nOldFee = wtx.GetDebit(ISMINE_SPENDABLE) - wtx.tx->GetValueOut();
142-
CFeeRate nOldFeeRate(nOldFee, txSize);
141+
old_fee = wtx.GetDebit(ISMINE_SPENDABLE) - wtx.tx->GetValueOut();
142+
CFeeRate nOldFeeRate(old_fee, txSize);
143143
CFeeRate nNewFeeRate;
144144
// The wallet uses a conservative WALLET_INCREMENTAL_RELAY_FEE value to
145145
// future proof against changes to network wide policy for incremental relay
@@ -149,26 +149,26 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
149149
walletIncrementalRelayFee = ::incrementalRelayFee;
150150
}
151151

152-
if (totalFee > 0) {
152+
if (total_fee > 0) {
153153
CAmount minTotalFee = nOldFeeRate.GetFee(maxNewTxSize) + ::incrementalRelayFee.GetFee(maxNewTxSize);
154-
if (totalFee < minTotalFee) {
155-
vErrors.push_back(strprintf("Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
154+
if (total_fee < minTotalFee) {
155+
errors.push_back(strprintf("Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
156156
FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxNewTxSize)), FormatMoney(::incrementalRelayFee.GetFee(maxNewTxSize))));
157-
currentResult = BumpFeeResult::INVALID_PARAMETER;
157+
current_result = BumpFeeResult::INVALID_PARAMETER;
158158
return;
159159
}
160160
CAmount requiredFee = GetRequiredFee(maxNewTxSize);
161-
if (totalFee < requiredFee) {
162-
vErrors.push_back(strprintf("Insufficient totalFee (cannot be less than required fee %s)",
161+
if (total_fee < requiredFee) {
162+
errors.push_back(strprintf("Insufficient totalFee (cannot be less than required fee %s)",
163163
FormatMoney(requiredFee)));
164-
currentResult = BumpFeeResult::INVALID_PARAMETER;
164+
current_result = BumpFeeResult::INVALID_PARAMETER;
165165
return;
166166
}
167-
nNewFee = totalFee;
168-
nNewFeeRate = CFeeRate(totalFee, maxNewTxSize);
167+
new_fee = total_fee;
168+
nNewFeeRate = CFeeRate(total_fee, maxNewTxSize);
169169
} else {
170-
nNewFee = GetMinimumFee(maxNewTxSize, coin_control, mempool, ::feeEstimator, nullptr /* FeeCalculation */);
171-
nNewFeeRate = CFeeRate(nNewFee, maxNewTxSize);
170+
new_fee = GetMinimumFee(maxNewTxSize, coin_control, mempool, ::feeEstimator, nullptr /* FeeCalculation */);
171+
nNewFeeRate = CFeeRate(new_fee, maxNewTxSize);
172172

173173
// New fee rate must be at least old rate + minimum incremental relay rate
174174
// walletIncrementalRelayFee.GetFeePerK() should be exact, because it's initialized
@@ -177,53 +177,53 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
177177
// add 1 satoshi to the result, because it may have been rounded down.
178178
if (nNewFeeRate.GetFeePerK() < nOldFeeRate.GetFeePerK() + 1 + walletIncrementalRelayFee.GetFeePerK()) {
179179
nNewFeeRate = CFeeRate(nOldFeeRate.GetFeePerK() + 1 + walletIncrementalRelayFee.GetFeePerK());
180-
nNewFee = nNewFeeRate.GetFee(maxNewTxSize);
180+
new_fee = nNewFeeRate.GetFee(maxNewTxSize);
181181
}
182182
}
183183

184184
// Check that in all cases the new fee doesn't violate maxTxFee
185-
if (nNewFee > maxTxFee) {
186-
vErrors.push_back(strprintf("Specified or calculated fee %s is too high (cannot be higher than maxTxFee %s)",
187-
FormatMoney(nNewFee), FormatMoney(maxTxFee)));
188-
currentResult = BumpFeeResult::WALLET_ERROR;
185+
if (new_fee > maxTxFee) {
186+
errors.push_back(strprintf("Specified or calculated fee %s is too high (cannot be higher than maxTxFee %s)",
187+
FormatMoney(new_fee), FormatMoney(maxTxFee)));
188+
current_result = BumpFeeResult::WALLET_ERROR;
189189
return;
190190
}
191191

192192
// check that fee rate is higher than mempool's minimum fee
193193
// (no point in bumping fee if we know that the new tx won't be accepted to the mempool)
194194
// This may occur if the user set TotalFee or paytxfee too low, if fallbackfee is too low, or, perhaps,
195195
// in a rare situation where the mempool minimum fee increased significantly since the fee estimation just a
196-
// moment earlier. In this case, we report an error to the user, who may use totalFee to make an adjustment.
196+
// moment earlier. In this case, we report an error to the user, who may use total_fee to make an adjustment.
197197
CFeeRate minMempoolFeeRate = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
198198
if (nNewFeeRate.GetFeePerK() < minMempoolFeeRate.GetFeePerK()) {
199-
vErrors.push_back(strprintf(
199+
errors.push_back(strprintf(
200200
"New fee rate (%s) is lower than the minimum fee rate (%s) to get into the mempool -- "
201201
"the totalFee value should be at least %s or the settxfee value should be at least %s to add transaction",
202202
FormatMoney(nNewFeeRate.GetFeePerK()),
203203
FormatMoney(minMempoolFeeRate.GetFeePerK()),
204204
FormatMoney(minMempoolFeeRate.GetFee(maxNewTxSize)),
205205
FormatMoney(minMempoolFeeRate.GetFeePerK())));
206-
currentResult = BumpFeeResult::WALLET_ERROR;
206+
current_result = BumpFeeResult::WALLET_ERROR;
207207
return;
208208
}
209209

210210
// Now modify the output to increase the fee.
211211
// If the output is not large enough to pay the fee, fail.
212-
CAmount nDelta = nNewFee - nOldFee;
212+
CAmount nDelta = new_fee - old_fee;
213213
assert(nDelta > 0);
214214
mtx = *wtx.tx;
215215
CTxOut* poutput = &(mtx.vout[nOutput]);
216216
if (poutput->nValue < nDelta) {
217-
vErrors.push_back("Change output is too small to bump the fee");
218-
currentResult = BumpFeeResult::WALLET_ERROR;
217+
errors.push_back("Change output is too small to bump the fee");
218+
current_result = BumpFeeResult::WALLET_ERROR;
219219
return;
220220
}
221221

222222
// If the output would become dust, discard it (converting the dust to fee)
223223
poutput->nValue -= nDelta;
224224
if (poutput->nValue <= GetDustThreshold(*poutput, ::dustRelayFee)) {
225225
LogPrint(BCLog::RPC, "Bumping fee and discarding dust output\n");
226-
nNewFee += poutput->nValue;
226+
new_fee += poutput->nValue;
227227
mtx.vout.erase(mtx.vout.begin() + nOutput);
228228
}
229229

@@ -234,63 +234,63 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
234234
}
235235
}
236236

237-
currentResult = BumpFeeResult::OK;
237+
current_result = BumpFeeResult::OK;
238238
}
239239

240-
bool CFeeBumper::signTransaction(CWallet *pWallet)
240+
bool FeeBumper::signTransaction(CWallet *wallet)
241241
{
242-
return pWallet->SignTransaction(mtx);
242+
return wallet->SignTransaction(mtx);
243243
}
244244

245-
bool CFeeBumper::commit(CWallet *pWallet)
245+
bool FeeBumper::commit(CWallet *wallet)
246246
{
247-
AssertLockHeld(pWallet->cs_wallet);
248-
if (!vErrors.empty() || currentResult != BumpFeeResult::OK) {
247+
AssertLockHeld(wallet->cs_wallet);
248+
if (!errors.empty() || current_result != BumpFeeResult::OK) {
249249
return false;
250250
}
251-
auto it = txid.IsNull() ? pWallet->mapWallet.end() : pWallet->mapWallet.find(txid);
252-
if (it == pWallet->mapWallet.end()) {
253-
vErrors.push_back("Invalid or non-wallet transaction id");
254-
currentResult = BumpFeeResult::MISC_ERROR;
251+
auto it = txid.IsNull() ? wallet->mapWallet.end() : wallet->mapWallet.find(txid);
252+
if (it == wallet->mapWallet.end()) {
253+
errors.push_back("Invalid or non-wallet transaction id");
254+
current_result = BumpFeeResult::MISC_ERROR;
255255
return false;
256256
}
257257
CWalletTx& oldWtx = it->second;
258258

259259
// make sure the transaction still has no descendants and hasn't been mined in the meantime
260-
if (!preconditionChecks(pWallet, oldWtx)) {
260+
if (!preconditionChecks(wallet, oldWtx)) {
261261
return false;
262262
}
263263

264-
CWalletTx wtxBumped(pWallet, MakeTransactionRef(std::move(mtx)));
264+
CWalletTx wtxBumped(wallet, MakeTransactionRef(std::move(mtx)));
265265
// commit/broadcast the tx
266-
CReserveKey reservekey(pWallet);
266+
CReserveKey reservekey(wallet);
267267
wtxBumped.mapValue = oldWtx.mapValue;
268268
wtxBumped.mapValue["replaces_txid"] = oldWtx.GetHash().ToString();
269269
wtxBumped.vOrderForm = oldWtx.vOrderForm;
270270
wtxBumped.strFromAccount = oldWtx.strFromAccount;
271271
wtxBumped.fTimeReceivedIsTxTime = true;
272272
wtxBumped.fFromMe = true;
273273
CValidationState state;
274-
if (!pWallet->CommitTransaction(wtxBumped, reservekey, g_connman.get(), state)) {
274+
if (!wallet->CommitTransaction(wtxBumped, reservekey, g_connman.get(), state)) {
275275
// NOTE: CommitTransaction never returns false, so this should never happen.
276-
vErrors.push_back(strprintf("The transaction was rejected: %s", state.GetRejectReason()));
276+
errors.push_back(strprintf("The transaction was rejected: %s", state.GetRejectReason()));
277277
return false;
278278
}
279279

280-
bumpedTxid = wtxBumped.GetHash();
280+
bumped_txid = wtxBumped.GetHash();
281281
if (state.IsInvalid()) {
282282
// This can happen if the mempool rejected the transaction. Report
283283
// what happened in the "errors" response.
284-
vErrors.push_back(strprintf("The transaction was rejected: %s", FormatStateMessage(state)));
284+
errors.push_back(strprintf("The transaction was rejected: %s", FormatStateMessage(state)));
285285
}
286286

287287
// mark the original tx as bumped
288-
if (!pWallet->MarkReplaced(oldWtx.GetHash(), wtxBumped.GetHash())) {
288+
if (!wallet->MarkReplaced(oldWtx.GetHash(), wtxBumped.GetHash())) {
289289
// TODO: see if JSON-RPC has a standard way of returning a response
290290
// along with an exception. It would be good to return information about
291291
// wtxBumped to the caller even if marking the original transaction
292292
// replaced does not succeed for some reason.
293-
vErrors.push_back("Created new bumpfee transaction but could not mark the original transaction as replaced");
293+
errors.push_back("Created new bumpfee transaction but could not mark the original transaction as replaced");
294294
}
295295
return true;
296296
}

0 commit comments

Comments
 (0)