-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Make feebumper class stateless #10600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Why bother with the class? |
I don't see a problem with using a class as a namespace, but happy to change if you think it is in bad taste and have a different suggestion. Note that the files are called feebumper.h/cpp so if you want to replace the class with something else, it might involve file renames. This PR is really more concerned with simplifying Qt code and moving code that doesn't belong there out. |
30d2100
to
b937494
Compare
893b4c4
to
1ea3597
Compare
I agree that if all of a class's methods have become |
Thanks @sipa, removed class without renaming file. Added commit 1ea3597 -> 47c5601 (pr/ipc-bump.6 -> pr/ipc-bump.7, compare) |
That is a problem or inconvenient? |
These should just be plain function calls because there are no advantages to having a stateful FeeBumper object. Making the feebumper class serializable is dumb because it will add new code that send extra data that isn't always needed. |
src/wallet/feebumper.cpp
Outdated
{ | ||
LOCK2(cs_main, pWallet->cs_wallet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in the original code, but is it necessary to lock cs_main
? The same applies for other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in the original code, but is it necessary to lock cs_main? The same applies for other functions.
Good catch! Fixed in 6a01316. In the other places cs_main is required for preconditionChecks. Note that in #10973, I replace accesses to cs_main
global throughout wallet code with ipc_locked
locals, so it is immediately obvious where locking is and isn't required and mistakes like this will not happen in the future (see ipc_locked
in https://github.com/ryanofsky/bitcoin/blob/pr/wipc-sep/src/wallet/feebumper.cpp).
src/wallet/feebumper.h
Outdated
BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet, | ||
const uint256& txid, | ||
const CCoinControl& coin_control, | ||
CAmount totalFee, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the headers we could fix to snake_case, it doesn't make the patch bigger. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the headers we could fix to snake_case, it doesn't make the patch bigger. WDYT?
Done in db134b4
src/wallet/feebumper.h
Outdated
CAmount nOldFee; | ||
CAmount nNewFee; | ||
}; | ||
/* return whether transaction can be bumped */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use doxygen compatible comments as per developer notes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use doxygen compatible comments as per developer notes?
Done in db134b4
src/wallet/feebumper.h
Outdated
bool TransactionCanBeBumped(CWallet* pWallet, const uint256& txid); | ||
|
||
/* create bumpfee transaction */ | ||
BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line?
I use clang-format for everything, and avoid manual formatting, so that's where this comes from. Would prefer not to change unless someone thinks this is a problem.
Suggested by João Barbosa <joao.paulo.barbosa@gmail.com> in bitcoin#10600 (comment)
Switch to doxgygen comments and snake_case as suggested by João Barbosa <joao.paulo.barbosa@gmail.com> in bitcoin#10600 (comment) and bitcoin#10600 (comment). Other minor edits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 2 commits 47c5601 -> db134b4 (pr/ipc-bump.7 -> pr/ipc-bump.8, compare)
src/wallet/feebumper.cpp
Outdated
{ | ||
LOCK2(cs_main, pWallet->cs_wallet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in the original code, but is it necessary to lock cs_main? The same applies for other functions.
Good catch! Fixed in 6a01316. In the other places cs_main is required for preconditionChecks. Note that in #10973, I replace accesses to cs_main
global throughout wallet code with ipc_locked
locals, so it is immediately obvious where locking is and isn't required and mistakes like this will not happen in the future (see ipc_locked
in https://github.com/ryanofsky/bitcoin/blob/pr/wipc-sep/src/wallet/feebumper.cpp).
src/wallet/feebumper.h
Outdated
bool TransactionCanBeBumped(CWallet* pWallet, const uint256& txid); | ||
|
||
/* create bumpfee transaction */ | ||
BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line?
I use clang-format for everything, and avoid manual formatting, so that's where this comes from. Would prefer not to change unless someone thinks this is a problem.
src/wallet/feebumper.h
Outdated
CAmount nOldFee; | ||
CAmount nNewFee; | ||
}; | ||
/* return whether transaction can be bumped */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use doxygen compatible comments as per developer notes?
Done in db134b4
src/wallet/feebumper.h
Outdated
BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet, | ||
const uint256& txid, | ||
const CCoinControl& coin_control, | ||
CAmount totalFee, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the headers we could fix to snake_case, it doesn't make the patch bigger. WDYT?
Done in db134b4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
light utACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yea, I think I'd prefer leaving the BumpFee:: functions in a namespace. I find BumpFee::* to be cleaner than *BumpFee.
src/wallet/feebumper.cpp
Outdated
@@ -70,7 +70,7 @@ BumpFeeResult PreconditionChecks(const CWallet* pWallet, const CWalletTx& wtx, s | |||
|
|||
bool TransactionCanBeBumped(CWallet* pWallet, const uint256& txid) | |||
{ | |||
LOCK2(cs_main, pWallet->cs_wallet); | |||
LOCK(pWallet->cs_wallet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document the exact locking requirements in GetWalletTx in wallet.h or wallet.cpp just to make sure someone doesnt do some crazy-ass change in the future and blow up the lockorder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document the exact locking requirements in GetWalletTx in wallet.h or wallet.cpp just to make sure someone doesnt do some crazy-ass change in the future and blow up the lockorder?
Done in 3a7c0df. I could go further and assert cs_wallet lock is held in GetWalletTx, though that is getting pretty far afield. Could open a separate PR.
src/wallet/feebumper.h
Outdated
std::vector<std::string>& vErrors, | ||
CAmount& nOldFee, | ||
CAmount& nNewFee, | ||
CAmount total_fee, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please do this, but also please keep names consistent between the cpp and h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 52301db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 3 commits db134b4 -> 2b2158a (pr/ipc-bump.8 -> pr/ipc-bump.9, compare)
Hmm, yea, I think I'd prefer leaving the BumpFee:: functions in a namespace. I find BumpFee::* to be cleaner than *BumpFee.
Added in 2b2158a
src/wallet/feebumper.h
Outdated
std::vector<std::string>& vErrors, | ||
CAmount& nOldFee, | ||
CAmount& nNewFee, | ||
CAmount total_fee, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 52301db
src/wallet/feebumper.cpp
Outdated
@@ -70,7 +70,7 @@ BumpFeeResult PreconditionChecks(const CWallet* pWallet, const CWalletTx& wtx, s | |||
|
|||
bool TransactionCanBeBumped(CWallet* pWallet, const uint256& txid) | |||
{ | |||
LOCK2(cs_main, pWallet->cs_wallet); | |||
LOCK(pWallet->cs_wallet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document the exact locking requirements in GetWalletTx in wallet.h or wallet.cpp just to make sure someone doesnt do some crazy-ass change in the future and blow up the lockorder?
Done in 3a7c0df. I could go further and assert cs_wallet lock is held in GetWalletTx, though that is getting pretty far afield. Could open a separate PR.
Suggested by Matt Corallo bitcoin#10600 (comment)
Suggested by Matt Corallo bitcoin#10600 (comment)
Suggested by Matt Corallo bitcoin#10600 (review)
utACK 2b2158a |
I like this, but the commits are structured in a way that makes it more difficult to review than necessary. I think you can remove the first commit that changes all the functions to static (since you're removing the class entirely in a later commit). I also think some of the intermediate commits could perhaps be squashed, although I haven't looked to closely at them. If you're not interested in maintaining this branch, I can take it. |
2b2158a
to
510e19c
Compare
Reset 2b2158a -> 510e19c (pr/ipc-bump.9 -> pr/ipc-bump.10) New branch was written by @jnewbery. Has several changes:
|
510e19c
to
2db9e0a
Compare
Updated 510e19c -> 2db9e0a (pr/ipc-bump.10 -> pr/ipc-bump.11) Another update from @jnewbery, adding to TransactionCanBeBumped to the namespace. |
Tested ACK 2db9e0a. This should be trivially reviewable now. The first two commits in particular are just mechanical changes. The third commit changes the feebumper from a stateful class to stateless function calls, but the code change is minimal (the only real change is the way that errors are propagated back to the caller). @promag - I've left out your suggested simplification to the locking, since I think that can be done in a follow-up PR. |
Needs rebase |
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.
Future commit will remove the FeeBumper class. This commit simply places everything into a feebumper namespace, and changes the enum class name from BumpeFeeResult to feebumper::Result.
Change feebumper from a stateful class into a namespace of stateless functions. 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 stateless, also: - Move LOCK calls from Qt code to feebumper - Move TransactionCanBeBumped implementation from Qt code to feebumper
2db9e0a
to
aed1d90
Compare
rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK aed1d90. Only change since last review was the rebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res = feeBump->commit(wallet); | ||
} | ||
if(!res) { | ||
uint256 txid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: txid_dummy
?
CAmount old_fee; | ||
CAmount new_fee; | ||
CMutableTransaction mtx; | ||
if (feebumper::CreateTransaction(wallet, hash, coin_control, 0 /* totalFee */, errors, old_fee, new_fee, mtx) != feebumper::Result::OK) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: total_fee
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 #10244 Tree-SHA512: bf75e0c741b4e9c8912e66cc1dedf0ff715f77ea65fc33f7020d97d9099b0f6448f5852236dac63eea649de7d6fc03b0b21492e2c5140fb7560a39cf085506fd
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:
updated in this PR anyway so this doesn't increase the size of the diff)
This change was originally part of #10244