Add a claim index for fast reference by id#110
Conversation
src/claimtrie.cpp
Outdated
| } | ||
| current->children[name[name.size()-1]] = node; | ||
|
|
||
| // NOTE: add all claims if we want non-winning claims in the claim |
There was a problem hiding this comment.
all claims should go into the index, even nonwinning ones. When I run getclaimbyid, it doesn't care about whether that claim is winning.
|
Updated |
|
@kaykurokawa can you please review at your earliest convenience, thanks! (Reached out on DM via Slack too) |
|
Hmm, kind of getting bizarre results , for example winning claim for "test" is a607349ce83d3a86bac87a967ce7f9647e1ba736 , try: ./lbrycrd-cli getvalueforname test And when I do : ./lbrycrd-cli getclaimbyid a607349ce83d3a86bac87a967ce7f9647e1ba736 { Observer that the name above is "testy" not "test" Also I checked the debug log for "addToClaimIndex:" and the name that's being added seems to be off ? Seems like some names have an extra junk letter added to the end.. The code looks correct so maybe the serialization of CClaimIndexElement.name isn't handled properly? Not sure. |
|
Interesting, will take a look. |
|
@kaykurokawa Can you give another example? I don't see this issue and the above passes correctly here. For now, do a fresh sync for testing (i.e. rm -rf ~/.lbrycrd, assuming no meaningful wallet) to make sure the index is built properly. |
|
@kaykurokawa Ok, scratch that. I can now see the issue, after a restart. I see why you suspect the serialization. |
|
Ok cool, I tried the command again after reindex-ing and the above problem went away btw. |
|
@kaykurokawa Fixed. Please re-test, across restarts as well. |
|
I see the fix you made ( by getting the substring of name..) but I don't understand why that is necessary to fix it , do you have any insight into this? |
|
If you look at that method, everything referring to the name truncates/ignores the last character, including the main iteration loop. Why that is, I'm not sure yet, but that's how it comes back from disk. Whatever it is (intentional or not), it appears to have been there a long time. |
|
I will look over this again and merge |
|
I think this solves #74 |
|
it does. @kaykurokawa please take a look and merge :-) |
|
I think (not yet sure) I've found another bug: Now being returned by As you can see, effective amount isn't considering the claim amount itself. While However, this also happens on the current Maybe the fix for #33 wasn't applied here? |
|
Should be fixed in #123 and isn't related to code touched by this PR. |
|
@shyba Not sure I'm following. This code replaces the existing getclaimbyid in a way that improves performance by using a claim index that's built and maintained by this (PR) code. Are you seeing a discrepancy between the master branch and this one? |
src/claimtrie.cpp
Outdated
| claim = itClaim->second.claim; | ||
| return true; | ||
| } | ||
|
|
There was a problem hiding this comment.
Hmm, the part that comes after this, where it checks the db does not seem necessary..
Correct me if I'm wrong but there should never be a case where if it's not found in claimIndex but its found in leveldb.
|
Other than the one comment I left above, I think this is good to merge. Also, reminder that this feature will require a reindex for it to work, this should be noted once a release is made. |
|
Actually two more thing: Is it even necessary to keep and maintain claimIndex ? We could just query leveldb directly and we wouldn't have to worry about claimIndex growing unbounded. Since its just used for RPC calls, maybe its ok that its slow? When we call BatchWriteClaimIndex, we are not deleting abandoned claims from leveldb even though we are deleting them from claimIndex using removeFromClaimIndex. Is that the behavior we want? Victor pointed out that before this PR, getclaimbyid would not return abandoned claims, but now it does, because it is stored in leveldb. |
|
@kaykurokawa Both good points. I'll compare the performance and see if it's acceptable. As for the abandoned claims, either way. I'll remove since that's how the previous code worked. |
|
Updated |
slightly higher latency calls to leveldb Add a simple claim by id test
|
Rebased, updated, added unit test. @kaykurokawa Merge if ready. |
|
This LGTM |
No description provided.