Skip to content

Commit 4ed8180

Browse files
author
MarcoFalke
committed
Merge #10600: Make feebumper class stateless
aed1d90 [wallet] Change feebumper from class to functions (Russell Yanofsky) 37bdcca [refactor] Make feebumper namespace (Russell Yanofsky) 7c4f009 [trivial] Rename feebumper variables according to project code style (Russell Yanofsky) Pull request description: Make feebumper methods static and remove stored state in the class. Having the results of feebumper calls persist in an object makes process separation between Qt and wallet awkward, because it means the feebumper object either has to be serialized back and forth between Qt and wallet processes between fee bump calls, or that the feebumper object needs to stay alive in the wallet process with an object reference passed back to Qt. It's simpler just to have fee bumper calls return their results immediately instead of storing them in an object with an extended lifetime. In addition to making feebumper methods static, also: - Move LOCK calls from Qt code to feebumper - Move TransactionCanBeBumped implementation from Qt code to feebumper - Rename CFeeBumper class to FeeBumper (every CFeeBumper reference had to be updated in this PR anyway so this doesn't increase the size of the diff) This change was originally part of bitcoin/bitcoin#10244 Tree-SHA512: bf75e0c741b4e9c8912e66cc1dedf0ff715f77ea65fc33f7020d97d9099b0f6448f5852236dac63eea649de7d6fc03b0b21492e2c5140fb7560a39cf085506fd
2 parents 927a1d7 + aed1d90 commit 4ed8180

File tree

4 files changed

+179
-195
lines changed

4 files changed

+179
-195
lines changed

src/qt/walletmodel.cpp

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -659,45 +659,39 @@ bool WalletModel::abandonTransaction(uint256 hash) const
659659

660660
bool WalletModel::transactionCanBeBumped(uint256 hash) const
661661
{
662-
LOCK2(cs_main, wallet->cs_wallet);
663-
const CWalletTx *wtx = wallet->GetWalletTx(hash);
664-
return wtx && SignalsOptInRBF(*(wtx->tx)) && !wtx->mapValue.count("replaced_by_txid");
662+
return feebumper::TransactionCanBeBumped(wallet, hash);
665663
}
666664

667665
bool WalletModel::bumpFee(uint256 hash)
668666
{
669-
std::unique_ptr<CFeeBumper> feeBump;
670-
{
671-
CCoinControl coin_control;
672-
coin_control.signalRbf = true;
673-
LOCK2(cs_main, wallet->cs_wallet);
674-
feeBump.reset(new CFeeBumper(wallet, hash, coin_control, 0));
675-
}
676-
if (feeBump->getResult() != BumpFeeResult::OK)
677-
{
667+
CCoinControl coin_control;
668+
coin_control.signalRbf = true;
669+
std::vector<std::string> errors;
670+
CAmount old_fee;
671+
CAmount new_fee;
672+
CMutableTransaction mtx;
673+
if (feebumper::CreateTransaction(wallet, hash, coin_control, 0 /* totalFee */, errors, old_fee, new_fee, mtx) != feebumper::Result::OK) {
678674
QMessageBox::critical(0, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +
679-
(feeBump->getErrors().size() ? QString::fromStdString(feeBump->getErrors()[0]) : "") +")");
675+
(errors.size() ? QString::fromStdString(errors[0]) : "") +")");
680676
return false;
681677
}
682678

683679
// allow a user based fee verification
684680
QString questionString = tr("Do you want to increase the fee?");
685681
questionString.append("<br />");
686-
CAmount oldFee = feeBump->getOldFee();
687-
CAmount newFee = feeBump->getNewFee();
688682
questionString.append("<table style=\"text-align: left;\">");
689683
questionString.append("<tr><td>");
690684
questionString.append(tr("Current fee:"));
691685
questionString.append("</td><td>");
692-
questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), oldFee));
686+
questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), old_fee));
693687
questionString.append("</td></tr><tr><td>");
694688
questionString.append(tr("Increase:"));
695689
questionString.append("</td><td>");
696-
questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), newFee - oldFee));
690+
questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), new_fee - old_fee));
697691
questionString.append("</td></tr><tr><td>");
698692
questionString.append(tr("New fee:"));
699693
questionString.append("</td><td>");
700-
questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), newFee));
694+
questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), new_fee));
701695
questionString.append("</td></tr></table>");
702696
SendConfirmationDialog confirmationDialog(tr("Confirm fee bump"), questionString);
703697
confirmationDialog.exec();
@@ -715,23 +709,15 @@ bool WalletModel::bumpFee(uint256 hash)
715709
}
716710

717711
// sign bumped transaction
718-
bool res = false;
719-
{
720-
LOCK2(cs_main, wallet->cs_wallet);
721-
res = feeBump->signTransaction(wallet);
722-
}
723-
if (!res) {
712+
if (!feebumper::SignTransaction(wallet, mtx)) {
724713
QMessageBox::critical(0, tr("Fee bump error"), tr("Can't sign transaction."));
725714
return false;
726715
}
727716
// commit the bumped transaction
728-
{
729-
LOCK2(cs_main, wallet->cs_wallet);
730-
res = feeBump->commit(wallet);
731-
}
732-
if(!res) {
717+
uint256 txid;
718+
if (feebumper::CommitTransaction(wallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
733719
QMessageBox::critical(0, tr("Fee bump error"), tr("Could not commit transaction") + "<br />(" +
734-
QString::fromStdString(feeBump->getErrors()[0])+")");
720+
QString::fromStdString(errors[0])+")");
735721
return false;
736722
}
737723
return true;

0 commit comments

Comments
 (0)