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
LNS: Work-around lns::generic_owner hashing bug in rpc #1095
Conversation
Doy-lee
commented
Mar 24, 2020
A |
Ouch, I see why the existing code even compiles -- because operator bool() const { ... } which is non- |
That explains everything :( |
|
Also a side note in passing: with |
26c3817
to
25017e2
Compare
25017e2
to
271a09a
Compare
Added explicit to operator bool(). Decided to keep the std::map and manually hash as its temporary, then deprecate in hard fork 16. |
This looks fine, except for this part:
With the Also yesterday I came across this variable and comment in daemon/core.h, committed more than 4 years ago: // TEMPORARY HACK - Yes, this creates a copy, but otherwise the original
// variable map could go out of scope before the run method is called
boost::program_options::variables_map const m_vm_HACK; These sorts of things have a way of unintentionally surviving. |
src/rpc/core_rpc_server.cpp
Outdated
@@ -3416,7 +3427,7 @@ namespace cryptonote | |||
if (exceeds_quantity_limit(ctx, error_resp, m_restricted, req.entries.size(), COMMAND_RPC_LNS_OWNERS_TO_NAMES::MAX_REQUEST_ENTRIES)) | |||
return false; | |||
|
|||
std::map<lns::generic_owner, size_t> owner_to_request_index; | |||
std::map<size_t, size_t> owner_to_request_index; |
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.
This should be an unordered_map (but keeping the std::hash
specialization). This isn't just an optimal data structure thing: using a map
here has a potential (if rare) data omission on collision. (And switching to an unordered_map
is a nearly trivial change).
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.
Ok, updated
Quoting from Jagerman's reason: With the std::hash specialization already here, an unordered_map here seems an obviously better choice: hash collisions won't be destructive (they are with std::map + hash as keys), the code is slightly simpler (you can eliminate the hash call), and performance is better (map is an insertion sorted container, thus O(NlogN) on N insertions). This isn't just an optimal data structure thing: using a map here has a potential (if rare) data omission on collision.