Add a claim index for fast reference by id #110
No reviewers
Labels
No labels
area: devops
area: discovery
area: docs
area: livestream
area: proposal
consider soon
Epic
good first issue
hacktoberfest
hard fork
help wanted
icebox
Invalid
level: 0
level: 1
level: 2
level: 3
level: 4
needs: exploration
needs: grooming
needs: priority
needs: repro
needs: tech design
on hold
priority: blocker
priority: high
priority: low
priority: medium
resilience
soft fork
Tom's Wishlist
type: bug
type: discussion
type: improvement
type: new feature
type: refactor
type: task
type: testing
unplanned
work in progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
LBRYCommunity/lbrycrd!110
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claimindex"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
{
"name": "testy",
"value": "{"ver": "0.0.3", "description": "test", "license": "Creative Commons Attribution 4.0 International", "author": "test", "title": "test", "language": "en", "sources": {"lbry_sd_hash": "29ad218c61c599499b22c17228371b5fe9a6e725edc9ef691a7819b3e7406500467852920629fbcddbcacf13d31579d4"}, "content_type": "image/png", "nsfw": false}",
"claimId": "a607349ce83d3a86bac87a967ce7f9647e1ba736",
"txid": "a84cfc89c6169da6e0b63fe2b0adeed71464566bb1dab71f737a78d7711b2526",
"n": 1,
"amount": 1000000000,
"effective amount": 0,
"height": 94633
}
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:
This is how
dd622f534fb79af737e4edb8737a732ce74c45ffappears ongetclaimsforname test:Now being returned by
getclaimbyidon this branch rebased on master:As you can see, effective amount isn't considering the claim amount itself. While
getclaimsfornameconsiders it.However, this also happens on the current
getclaimbyidimplementation: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?
@lbrynaut No. At first I thought it was a discrepancy, then I found a bug and fixed in #123 but it turned out to be unrelated to this PR. Sorry for the confusion.
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
Rebased, updated, added unit test. @kaykurokawa Merge if ready.
This LGTM