This PR is only a draft.
The description below will change over time.
This PR removes a potential circular dependency that was discovered in travis while building binaries for this PR #18827
The affected sources/includes in that PR are httprpc and rpc/server
My first “solution” was a forward declare of a single function in rpc/server.cpp. However, that merely defeats the linter and could not count as a proper solution.
After some discussion #18827#pullrequestreview-404116986 I tried to extract certain classes and function declarations into a new include file, rpc/interfaces.h
Now, the circular dependency in that PR is gone, but as this constitutes a much bigger change than the PR wanted to make, I think it should better get its own PR.
The following classes and functions got moved into a new source file pair rpc/interfaces.cpp and rpc/interfaces.h:
0class RPCTimerBase
1class RPCTimerInterface
2class CRPCCommand
3class CRPCTable
4
5void SetRPCWarmupStatus(const std::string& newStatus);
6void SetRPCWarmupFinished();
7
8bool RPCIsInWarmup(std::string *outStatus);
9bool IsRPCRunning();
10
11int64_t GetStartupTime();
12int RPCSerializationFlags();
13
14std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
15
16void RPCSetTimerInterface(RPCTimerInterface *iface);
17void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface);
18void RPCUnsetTimerInterface(RPCTimerInterface *iface);
19void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);
20
21bool IsDeprecatedRPCEnabled(const std::string& method);
In src/Makefile.am
there is a new library defined: LIBBITCOIN_SERVER_INTERFACES that contains the implementation and is linked with bitcoind
and bitcoin-qt
(test and bench libraries are linked as well).
The changes reduce the size of rpc/server.cpp
substantially. What remains there are pure server management functionalities:
0namespace RPCServer
1{
2 void OnStarted(std::function<void ()> slot);
3 void OnStopped(std::function<void ()> slot);
4}
5
6void StartRPC();
7void InterruptRPC();
8void StopRPC();
Another advantage coming from these changes is that we got rid of forward declarations like class CRPCTable
, class CRPCCommand
etc.
Possible future changes in class structure and function grouping
Although this PR isn’t aiming for more complex engineering changes, like introducing new classes and other structures, there might be some advantage if we’d in future group the “extracted” functions into new classes. Just like we have CRPCTable
that carries table-oriented functions, or CRPCCommand
, we could introduce a new class called CRPCTimer
:
0class CRPCTimer {
1public:
2 /** Set the factory function for timers */
3 void RPCSetTimerInterface(RPCTimerInterface *iface);
4 /** Set the factory function for timer, but only, if unset */
5 void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface);
6 /** Unset factory function for timers */
7 void RPCUnsetTimerInterface(RPCTimerInterface *iface);
8};
And server-status functions could be moved into a new class like this:
0class CRPCServerStatus {
1public:
2 void SetRPCWarmupStatus(const std::string& newStatus);
3 void SetRPCWarmupFinished();
4 bool RPCIsInWarmup(std::string *outStatus);
5 bool IsRPCRunning();
6 int64_t GetStartupTime();
7private:
8 [...here come mutexes, guards, atomics etc. ]
9};
Then we could give access to their instances the same way we do with CRPCtable tableRPC
now.
0extern CRPCTimer timerRPC;
1extern CRPCServerStatus statusRPC;