-
Notifications
You must be signed in to change notification settings - Fork 37.8k
[Modularization] add possibility to extend or overwrite RPC calls #5744
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
2e08088
to
ea66fb4
Compare
According to bitcoin#3440 it would make sense to decouple the wallet and the miner (and maybe other things) from the init-/shutdown-process, etc. This is related to bitcoin#5686, bitcoin#5744, bitcoin#5745
ut ACK |
void CRPCTable::AddOrReplaceCommand(const CRPCCommand command) | ||
{ | ||
// search after existing key in hashmap and remove it | ||
map<string, const CRPCCommand*>::iterator it = mapCommands.find(command.name); |
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.
Why is this lookup needed? You can just overwrite using the line you have below?
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... yes. Should be sufficient to just overwrite. Will change this.
Hey @jonasschnelli, this is a very interesting idea. I faced some issues (segfaults and std::bad_alloc exceptions), probably related to object lifetime, and ended up passing From a practical perspective, value conversion is also a relevant topic, and editing |
@dexX7 Indeed. The |
@dexX7 i played around with your We could get rid of the conversion via |
Good point, I didn't really intend to replace the old system, but it was more like a quick workaround-ish solution, although I have to admit, I don't like having a conversion table and still be required specify data types (e.g. I pushed three more conservative and similar, but slightly different each, approaches:
As you may see, I'm a bit lost and undecided, design wise, but I hope it helps to push this further. :) |
pulled in @dexX7 conversion table work. Fixed code nits mentioned by @sipa . A flexible RPC interface is required if we like to add capability to switch on/off certain modules. |
- this will allow a upcomming modularization of the wallet or other components
- add method to insert custom conversion entries Conflicts: src/test/rpc_tests.cpp
f5a0e15
to
bbee2eb
Compare
Adding new commands is still an issue for me, if the scope is left. For example: https://gist.github.com/dexX7/32accc4b04cb2e7dd496 |
@dexX7 Thanks for the response. Yes. Bad memory management. Will have a look at it. |
@dexX7 i reviewed you gist https://gist.github.com/dexX7/32accc4b04cb2e7dd496. I would say the PR is acting correct. I think one need to take the same approach to add commands to the This is not perfect but would give a RPC flexibility with a diff-size of +82/−2. |
* add or replace a CRPCCommand to the dispatch table | ||
* @param command rpc command to add or replace | ||
*/ | ||
void AddOrReplaceCommand(const CRPCCommand command); |
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.
The devil is in the details here, I think. :) const CRPCCommand command
creates copy of the original command, and the caller can maintain the original for the whole execution lifetime, but it would still break (try: the updated gist).
It's a slightly different story with RPCAddConversion(const std::string& method, int idx)
, because the lifetime the method name seems to be extended, where Temporary object lifetime, note 1 appears to apply to my understanding.
Upfront: using const CRPCCommand& command
works, but the caller must still take care of the lifetime, which is not very intuitive imho, as one might be tempted to believe it's behavior is similar to the const std::string& s
case, thus my comment about passing a pointer const CRPCCommand*
instead, which makes it very clear that it's the caller's responsibility (in code: dexX7@57b252e).
Messing around with object lifetime and pointers is a bit cumbersome and error prone in general in my opinion, so it might be worth to overthink the whole approach of storing pointers in mapCommands
, but on the other hand, keeping changes minimal and doing it step by step probably yields results more quickly.
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.
You are totally right. It must be const CRPCCommand& command
(passing pointers). I just pulled in your commit.
I'm also aware that this pointer-passing-approche is not intuitive. But i'm still trying to keep the changeset-size at minimum. I also think a rpc calls will be added when the app starts (modules get loaded) then they stay alive until the app detects a shutdown so the lifetime management tend to be not so complex.
Using pointers signals the responsibility of managing object lifetime is in the hand of the caller.
Needs rebase. |
This will allow a upcomming modularization of the wallet or other components.
Currently there is no use of the flexible RPC dispatch table.
Because #5686 is getting to big, it might be a better approach to slice out independent changes which can be easily reviewed and tested.