Skip to content

RPC: cleanups in rpc/server#9845

Closed
jtimon wants to merge 1 commit intobitcoin:masterfrom
jtimon:0.15-extern-rpc-server
Closed

RPC: cleanups in rpc/server#9845
jtimon wants to merge 1 commit intobitcoin:masterfrom
jtimon:0.15-extern-rpc-server

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Feb 23, 2017

There's no reason to declare the following functions in rpc/server.h when they're defined in wallet/rpcwallet.cpp. They can be declared in wallet/rpcwallet.h instead:

HelpRequiringPassphrase
EnsureWalletIsAvailable
EnsureWalletIsUnlocked

Also, there's no reason to use extern for functions declared in rpc/server.h. It is really never needed (see http://stackoverflow.com/questions/11712707/extern-functions-in-c-vs-c/11712820#11712820 ), but it seems more strange when those functions are also defined in rpc/server.cpp (in the same module).

@sipa
Copy link
Member

sipa commented Feb 24, 2017

utACK

@kallewoof
Copy link
Contributor

utACK 073613b

Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

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

utACK 073613b36a8780dd720e2a17f1314980173e200d

@paveljanik
Copy link
Contributor

utACK 073613b

@laanwj
Copy link
Member

laanwj commented Feb 24, 2017

Good idea, rpcserver is supposed to be bitcoin-agnostic, those methods don't belong there.

@jtimon
Copy link
Contributor Author

jtimon commented Feb 24, 2017

There's also GetDifficulty (declared in rpc/server.h, defined in rpc/blockchain.cpp, used in several rpc places) which isn't taken care of here. I wasn't sure what to do with it.

@NicolasDorier
Copy link
Contributor

utACK 073613b36a8780dd720e2a17f1314980173e200d

1 similar comment
@maflcko
Copy link
Member

maflcko commented Feb 28, 2017

utACK 073613b36a8780dd720e2a17f1314980173e200d

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

tested ACK. Looks good.

There's also GetDifficulty (declared in rpc/server.h, defined in rpc/blockchain.cpp, used in several rpc places) which isn't taken care of here

Could that become a member function of CBlockIndex in chain.cpp?

src/rpc/server.h Outdated
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 also move nWalletUnlockTime to rpcwallet.h as an extern declaration? You'll need to #include wallet/rpcwallet.h in rpc/misc.cpp, protected by #ifdef ENABLE_WALLET

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. Agreed.

@laanwj
Copy link
Member

laanwj commented Mar 5, 2017

Needs rebase (and last nit-fix)

@laanwj laanwj self-assigned this Mar 5, 2017
@jtimon jtimon force-pushed the 0.15-extern-rpc-server branch from 073613b to 24b2c40 Compare March 6, 2017 21:58
@jtimon
Copy link
Contributor Author

jtimon commented Mar 6, 2017

Rebased.
Rebasing makes the first commit unnecessary after #8775 "a4356328 Move wallet RPC declarations to rpcwallet.h" . It seems nWalletUnlockTime was moved in #8775 too (see "2e518e31 Move nWalletUnlockTime to CWallet::nRelockTime, and name timed task unique per CWallet" ).
This leaves the PR to a single commit removing the unnecessary 'extern' in functions, trivial to review.

@maflcko
Copy link
Member

maflcko commented Mar 6, 2017 via email

@jtimon
Copy link
Contributor Author

jtimon commented Mar 6, 2017

@MarcoFalke I guess at that point I should create another PR since the tittle "RPC: cleanups in rpc/server" wouldn't fit anymore. I'm not planning to do that in the short term, but you are right. I would happily ACK such a PR to replace this one if anybody does it. I was just working on rpcwallet and rpc/server and saw easy things to fix without knowing about #8775 . I may end up doing it myself if nobody else jumps at it, but for now I'll just leave this PR open as it is.

@laanwj
Copy link
Member

laanwj commented Mar 7, 2017

I think there are other functions with 'extern'. You might as well do it for the whole code base.

For whoever does that: do add instruction in developer-notes.md on when to use extern and when not to. It seems safe to add extern to these cases, just redundant, so I'd see this as quite low priority.


CAmount AmountFromValue(const UniValue& value);
UniValue ValueFromAmount(const CAmount& amount);
double GetDifficulty(const CBlockIndex* blockindex = NULL);
Copy link
Member

Choose a reason for hiding this comment

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

Why is GetDifficulty still here? :-)

@jtimon
Copy link
Contributor Author

jtimon commented Mar 21, 2017

extern should never be used for functions, but I'm not sure that is worth to add "please don't add extern to functions because it doesn't do anything" to the developer notes, at least not more than "please don't add variables that aren't used".
Agreed removing extern is low priority, as said, the most interesting parts of this PR were already done by #8775

Should we merge this anyway (since it's trivial, has been reviewed and it's not disruptive) or should I just close it?

@jtimon
Copy link
Contributor Author

jtimon commented Mar 23, 2017

Closing, it seems at this point would be preferable to remove extern from all functions from the project at once (I bet they're not that many, but I didn't looked yet) as @MarcoFalke suggests.
In some way, all utACKs for this were just partial acks for merged #8775

@jtimon jtimon closed this Mar 23, 2017
@laanwj
Copy link
Member

laanwj commented Mar 24, 2017

I think removing GetDifficulty from server.h would have made a lot of sense here, along with the other cleanups as those lines were touched anyway, but indeed it's very low priority.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 25, 2017

Well, as said I wasn't sure what to do with GetDifficulty, so this PR never moved it.

@laanwj
Copy link
Member

laanwj commented Mar 27, 2017

No need to be clever here, if it's defined in src/rpc/blockchain.cpp the interface should be declared in src/rpc/blockchain.h. Will file a PR, see #10095.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.