Skip to content

Conversation

ryanofsky
Copy link
Contributor

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

@dcousens
Copy link
Contributor

dcousens commented Jun 16, 2017

Why bother with the class?
Practically a namespace at this point?

@ryanofsky
Copy link
Contributor Author

Why bother with the class?
Practically a namespace at this point?

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.

@ryanofsky ryanofsky force-pushed the pr/ipc-bump branch 2 times, most recently from 30d2100 to b937494 Compare July 18, 2017 19:49
@ryanofsky ryanofsky force-pushed the pr/ipc-bump branch 2 times, most recently from 893b4c4 to 1ea3597 Compare August 25, 2017 22:42
@sipa
Copy link
Member

sipa commented Aug 27, 2017

I agree that if all of a class's methods have become static it's better to turn it into a namespace of functions, but don't care strongly. If so, I don't think a file rename is necessary.

@ryanofsky
Copy link
Contributor Author

I agree that if all of a class's methods have become static it's better to turn it into a namespace of functions, but don't care strongly. If so, I don't think a file rename is necessary.

Thanks @sipa, removed class without renaming file.

Added commit 1ea3597 -> 47c5601 (pr/ipc-bump.6 -> pr/ipc-bump.7, compare)

@promag
Copy link
Contributor

promag commented Aug 28, 2017

because it means the feebumper object either has to be serialized back and forth between Qt and wallet processes between fee bump calls

That is a problem or inconvenient?

@ryanofsky
Copy link
Contributor Author

because it means the feebumper object either has to be serialized back and forth between Qt and wallet processes between fee bump calls

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.

{
LOCK2(cs_main, pWallet->cs_wallet);
Copy link
Contributor

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.

Copy link
Contributor Author

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).

BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet,
const uint256& txid,
const CCoinControl& coin_control,
CAmount totalFee,
Copy link
Contributor

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?

Copy link
Contributor Author

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

CAmount nOldFee;
CAmount nNewFee;
};
/* return whether transaction can be bumped */
Copy link
Contributor

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?

Copy link
Contributor Author

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

bool TransactionCanBeBumped(CWallet* pWallet, const uint256& txid);

/* create bumpfee transaction */
BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One line?

Copy link
Contributor Author

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.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Aug 29, 2017
Suggested by João Barbosa <joao.paulo.barbosa@gmail.com> in
bitcoin#10600 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Aug 29, 2017
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.
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
LOCK2(cs_main, pWallet->cs_wallet);
Copy link
Contributor Author

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).

bool TransactionCanBeBumped(CWallet* pWallet, const uint256& txid);

/* create bumpfee transaction */
BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet,
Copy link
Contributor Author

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.

CAmount nOldFee;
CAmount nNewFee;
};
/* return whether transaction can be bumped */
Copy link
Contributor Author

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

BumpFeeResult CreateBumpFeeTransaction(const CWallet* pWallet,
const uint256& txid,
const CCoinControl& coin_control,
CAmount totalFee,
Copy link
Contributor Author

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

Copy link
Contributor

@dcousens dcousens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

light utACK

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a 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.

@@ -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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

std::vector<std::string>& vErrors,
CAmount& nOldFee,
CAmount& nNewFee,
CAmount total_fee,
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 52301db

Copy link
Contributor Author

@ryanofsky ryanofsky left a 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

std::vector<std::string>& vErrors,
CAmount& nOldFee,
CAmount& nNewFee,
CAmount total_fee,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 52301db

@@ -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);
Copy link
Contributor Author

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.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Sep 7, 2017
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Sep 7, 2017
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Sep 7, 2017
@TheBlueMatt
Copy link
Contributor

utACK 2b2158a

@jnewbery
Copy link
Contributor

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.

@ryanofsky
Copy link
Contributor Author

Reset 2b2158a -> 510e19c (pr/ipc-bump.9 -> pr/ipc-bump.10)

New branch was written by @jnewbery. Has several changes:

  • Simplifies history so related changes are better grouped together.
  • Rebased on master
  • Reverts some unrelated changes suggested by previous reviewers which could go in separate PRs.
  • Other minor changes like declaring functions static instead of using an anonymous namespace.

@ryanofsky
Copy link
Contributor Author

Updated 510e19c -> 2db9e0a (pr/ipc-bump.10 -> pr/ipc-bump.11)

Another update from @jnewbery, adding to TransactionCanBeBumped to the namespace.

@jnewbery
Copy link
Contributor

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.

@maflcko
Copy link
Member

maflcko commented Nov 10, 2017

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
@jnewbery
Copy link
Contributor

rebased

Copy link
Contributor Author

@ryanofsky ryanofsky left a 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.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK aed1d90 (Also checked that 7c4f009 produces the same binaries on my arch, since it is not a scripted diff.)

res = feeBump->commit(wallet);
}
if(!res) {
uint256 txid;
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: total_fee

@maflcko maflcko merged commit aed1d90 into bitcoin:master Nov 15, 2017
maflcko pushed a commit that referenced this pull request Nov 15, 2017
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants