tx indexer: use different field separator for keys#5865
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5865 +/- ##
==========================================
- Coverage 60.08% 59.88% -0.21%
==========================================
Files 269 269
Lines 24499 24527 +28
==========================================
- Hits 14721 14687 -34
- Misses 8193 8237 +44
- Partials 1585 1603 +18
|
erikgrinaker
left a comment
There was a problem hiding this comment.
This code has some issues that I think follows from using a suboptimal key structure. If I'm understanding this correctly, there's nothing separating event keys from height keys, such that they're mixed together and we have to do weird things like skip erroring entries while we're iterating over them if they don't have the expected format.
I think it might make more sense to have unique prefixes for the two different key types such that we'll never encounter a different key type while iterating over one type. Then we can simply error on any unexpected key formats. Or is there an actual reason for mixing them together, like we want to query multiple key types during a single iterator pass?
|
The height key is, in a way, a type of event key with a defined composite prefix of "tx.height" and a value of it's height (hence why we have height repeated twice - once as a string and another as an int64). All other event keys are chosen by the application and could have for example a composite prefix of "account.name" and a value of "Callum". I was thinking that because tendermint already reserves the composite prefix "tx.height" that we want to check that the application doesn't also use it as an event. Other than that, the only place where keys could get shuffled together is with the hash key which has no prefix to it. For example if the hash of a tx just so happened to start with "tx.height" it would get inserted somewhere amongst the tx.height section. I was thinking we could add a "tx.hash" prefix to the hash key and reserve this composite prefix as well. |
Got it. Any reason for handling it as if it was some other key then? Can't we just have one key type? Also, storing it as a string prevents us from doing range scans on it. Not sure if that's relevant, just saying (e.g. if someone queries
That might make sense. In that case, shouldn't this be reserved, specified, and handled in the same place as e.g. |
I've sort of already made it one key. There is a function called I guess the problem with combining height with the event key and forcing it to have the same format is, as you say, at the loss of more performant range operations. Note that this is just for queries where
Yup turns out we already have tx.hash prefix but it isn't reserved (neither is tx.height for that matter), i.e. I could create an event called tx.height set a different value and the tx would also be saved there. Also the tx.hash key isn't actually used in the kvstore only as part of querying. I will change this. I guess in general there is a lot of thought that can be spent on this and probably lots of fully featured libraries that do a good job of parsing queries and implementing secondary indexes. It's quite interesting to me but I think I should save properly delving into it for a later time so for now I would ideally like to focus on just tweaking a small part of the keys |
Right, ok -- in that case we shouldn't really need all of the checks that skip erroring/invalid keys, since they should all be in a correct format. Makes sense to unify the
Yeah. Honestly, I don't really see any point in implementing this ourselves -- I'd just use SQLite and call it a day. |
Description
Implemented the
orderedcodelibrary for consistency and lexicographic ordering of keys.This also tackles the below issue of having a better escape mechanism using
0x00ffinstead of/Closes: #2907