-
Notifications
You must be signed in to change notification settings - Fork 76
Implement book_changes RPC #300
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
* Port book_changes RPC call from rippled * Refactor for readability and modern cpp
natenichols
left a comment
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.
Only requesting changes because I'd like to look into a way to do this without using const_cast.
If it turns out that we have to do that, I won't die on this hill, but I'd prefer it if we found a different way.
|
|
||
| class BookChangesHandler | ||
| { | ||
| std::reference_wrapper<Context const> context_; |
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.
If you've deleted copy assignment, you can probably just use Context const&
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.
I'd rather not have const/ref members ever, no matter what
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 do we want to avoid ref members?
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.
@cjcobb23 for me personally it's enough that it's a core guideline. I understand it's ok if you know what you are doing but i'd try to avoid it most of the time. using reference_wrapper is totally fine - it's just a pointer inside and basically a zero-cost abstraction.
| inline void | ||
| reset() noexcept | ||
| { | ||
| tally_.clear(); |
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 do we need reset() .
If the class is instantiated each time we handle, couldn't we just put this functionality in the constructor.
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.
Just because in my code i don't reuse it does not mean one could not reuse it some day later. So this is for correctness sake and it also does nothing on the first call to it as far as i understand
src/rpc/handlers/BookChanges.cpp
Outdated
| class BookChangesHandler | ||
| { | ||
| std::reference_wrapper<Context const> context_; | ||
| std::map<std::string, BookChange> tally_; |
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.
These aren't initialized until we call reset.
can we just initialize these here with = {}. I don't think it will change anything, I just prefer explicitly instantiating member variables.
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 would that be?
Just because i'm not explicitly setting a value in initialization list nor in the members section does not mean default constructor will not be called for a user defined type.
See https://godbolt.org/z/ovnW6erx3
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.
Having that said we can absolutely do the = {} thingy for good measure :)
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.
Yea, these are exactly the same functionally.
I prefer explicitly calling the default constructor w/ = {} or Foo foo{} because its more explicit, but that's just me.
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.
Up to you here.
src/rpc/handlers/BookChanges.cpp
Outdated
| !node.isFieldPresent(sfPreviousFields)) | ||
| return; | ||
|
|
||
| auto& finalFields = (const_cast<STObject&>(node)) |
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.
Vetoing const_cast.
Why do we need const cast here. There's got to be a way to do this without requiring this. Look in STObject.h in rippled to see if there's a way that doesn't require this.
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.
Oh god i did not even notice it tbh. - this was copied as is from the original implementation in rippled. I'll definitely try to find a way around this - thanks
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.
How did const_cast get into the rippled implementation. Has this been merged yet.
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.
Yea it was. I'll submit a patch to rippled later - no worries.
* Port book_changes RPC call from rippled * Refactor for readability and modern cpp
* Port book_changes RPC call from rippled * Refactor for readability and modern cpp
* Port book_changes RPC call from rippled * Refactor for readability and modern cpp
Fixes #284
book_changesrpc call fromrippled.book_changessupport intest.pyTo try you can execute something like this:
./test.py --ip 127.0.0.1 --port 51233 --ledger 74256240 book_changesExample output:
There is also currently no unit-tests for this. We should add it at some point when we have refactored for testability.