Skip to content
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

state/kvindexer: associate event attributes with events #9759

Merged
merged 39 commits into from
Dec 14, 2022

Conversation

jmalicevic
Copy link
Contributor

@jmalicevic jmalicevic commented Nov 23, 2022

Closes #9712

This PR changes the way keys are generated for block events, and how they are stored in the database. Namely,
in previous versions, for each event attribute, there was a different entry in the kvstore. Users can query the events and get the corresponding height where an attribute occurred, but cannot correlate attributes to the actual events which they belong to.

We expand the key with the event information, allowing a user to query for attributes that happened within the same height AND the same event.

To achieve this behaviour, users have to add a match_event=true keyword to their RPC query. Otherwise, the index search system falls back to the original behaviour.


PR checklist

  • Tests written/updated, or no tests needed
  • CHANGELOG_PENDING.md updated, or no changelog entry needed
  • Updated relevant documentation (docs/) and code comments, or no
    documentation updates needed

@jmalicevic jmalicevic added the C:indexer Component: Indexer label Nov 23, 2022
@jmalicevic jmalicevic self-assigned this Nov 23, 2022
@jmalicevic jmalicevic marked this pull request as ready for review November 25, 2022 12:22
@jmalicevic jmalicevic requested a review from ebuchman as a code owner November 25, 2022 12:22
@jmalicevic jmalicevic requested a review from a team November 25, 2022 12:22
@ancazamfir
Copy link
Contributor

To achieve this behaviour, users have to add a match.event keyword to their query. Otherwise, the index search system falls back to the original behaviour.

To clarify, if match.events=1 is present in a query sent to an old tendermint version, the query will not behave like before. The implication for hermes is that it needs to format the query based on the version of the chain the query is sent to. We are trying to avoid this and wondering if there is a backwards compatible solution.

On current version (without your changes) this returns two blocks:

http://provider-sentry-01.goc.earthball.xyz:27001/block_search?query="send_packet.packet_sequence='890' AND send_packet.packet_src_channel='channel-2'"

While this finds 0 blocks:

http://provider-sentry-01.goc.earthball.xyz:27001/block_search?query="send_packet.packet_sequence='890' AND send_packet.packet_src_channel='channel-2' AND match.events = 1"

cc @romac who brought this up: Is it possible to change the RPC to add an extra argument or option, something like:
http://provider-sentry-01.goc.earthball.xyz:27001/block_search?query=_&page=_&per_page=_&order_by=_&match_events
(with default false if new flag not present).

This currently works on old version and returns the two blocks:

http://provider-sentry-01.goc.earthball.xyz:27001/block_search?query="send_packet.packet_sequence='890' AND send_packet.packet_src_channel='channel-2'"&match_events=true"

Can we make it work within your PR branch? Or is this something that's already handled here? If it is, can you write one unit test for it?

@jmalicevic
Copy link
Contributor Author

To clarify, if match.events=1 is present in a query sent to an old tendermint version, the query will not behave like before.

You are issuing the match.events=1 to and old tendermint version that does not support this? That is probably why the result has 0 blocks. What I did preserve is that the new Tendermint version will be able to process data that was indexed with an old version but it will obviously not be able to differentiate between different events in that case. That is, the event identifier field will be set to the same value for any entry in the kvstore that was indexed w/o it. But essentially you want to avoid older versions not returning anything when seeing the keyword. The only way I currently see to avoid this is making this behvaiour (with match.events=1 currently) default and having users explicitly use match.events=0 if they want the old behaviour. This would not change the behaviour for old versions but users of a new version would have to be aware of this.

This currently works on old version and returns the two blocks:

http://provider-sentry-01.goc.earthball.xyz:27001/block_search?query="send_packet.packet_sequence='890' AND send_packet.packet_src_channel='channel-2'"&match_events=true"

match_events should be with a . instead of _ unless you internally parse it. On old versions however, this flag is basically ignored as it will always return two blocks - there is no way to know to which even an attribute belongs.

I am currently running local tests using two TM versions to evaluate the behaviour of the indexer when upgrading from an old to a new version.

@ancazamfir an additional question, can you tell me whether you expect the same behaviour from the transaction indexer or is the block indexer your main concern?

@ancazamfir
Copy link
Contributor

http://provider-sentry-01.goc.earthball.xyz:27001/block_search?query="send_packet.packet_sequence='890' AND send_packet.packet_src_channel='channel-2'"&match_events=true

there was an extra "..i removed

match_events should be with a . instead of _ unless you internally parse it. On old versions however, this flag is basically ignored as it will always return two blocks - there is no way to know to which even an attribute belongs.

this is proposing a new flag, outside the query string. This would be a better solution for hermes as would work in a backwards compatible way.

, can you tell me whether you expect the same behaviour from the transaction indexer or is the block indexer your main concern?

ah, I thought the problem is not present in the tx_indexer. I need to test this. will get back to you.

@jmalicevic
Copy link
Contributor Author

@ancazamfir it is present and this PR has a solution for it too, but making it backwards compatible seems to be a bigger feat then I'd expected.

Copy link
Contributor

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jmalicevic for this nice work.
Please be sure to address any outstanding comment from other reviewers.

light/proxy/routes.go Show resolved Hide resolved
rpc/core/blocks.go Outdated Show resolved Hide resolved
state/txindex/kv/kv.go Outdated Show resolved Hide resolved
state/txindex/kv/kv.go Outdated Show resolved Hide resolved
state/indexer/block/kv/kv.go Outdated Show resolved Hide resolved
rpc/core/blocks.go Outdated Show resolved Hide resolved
rpc/core/tx.go Outdated Show resolved Hide resolved
docs/app-dev/indexing-transactions.md Outdated Show resolved Hide resolved
}

func NewApplication() *Application {
state := loadState(dbm.NewMemDB())
return &Application{state: state}
}

func (app *Application) SetGenBlockEvents() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method ever used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used atm but should be used if we want to turn on the generation of Blockevents.

rpc/core/blocks.go Outdated Show resolved Hide resolved
Copy link
Contributor

@thanethomson thanethomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks @jmalicevic! Great work! 🎉

And thanks for adding in the extra unit tests 🙂

state/indexer/block/kv/util.go Outdated Show resolved Hide resolved
state/indexer/block/kv/util.go Outdated Show resolved Hide resolved
Co-authored-by: Thane Thomson <connect@thanethomson.com>
@jmalicevic jmalicevic merged commit 94a5fdf into v0.34.x Dec 14, 2022
@jmalicevic jmalicevic deleted the jasmina/block-indexer-q branch December 14, 2022 09:34
@jmalicevic jmalicevic restored the jasmina/block-indexer-q branch December 14, 2022 09:37
@jmalicevic jmalicevic deleted the jasmina/block-indexer-q branch December 14, 2022 09:39
jmalicevic added a commit that referenced this pull request Dec 14, 2022
* Updated event sequencing and added query keyword

* code cosmetics

* Documentation update

* Added per event indexing and querying to txindexer

* rpc test fix

* Added support for older versions where event sequencing is not supported

* Added support for old versions to tx indexer

* Added RPC match flag, fixed bugs in tx indexer, added tests

* Removed reference to match.events from the docs

* Openapi update

* Added height deduplication
Co-authored-by: Thane Thomson <connect@thanethomson.com>

Co-authored-by: Anca Zamfir <zamfiranca@gmail.com>
Co-authored-by: Sergio Mena <sergio@informal.systems>
Co-authored-by: Romain Ruetschi <romain.ruetschi@gmail.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
@jmalicevic jmalicevic restored the jasmina/block-indexer-q branch December 14, 2022 12:40
thanethomson added a commit to informalsystems/tendermint that referenced this pull request Feb 3, 2023
* Revert "Fixed ordering of match.events in light client RPC (tendermint#9877)"

* Revert "state/kvindexer: associate event attributes with events (tendermint#9759)"

* Revert "consensus: correctly save reference to previous height precommits (backport tendermint#9760) (tendermint#9776)"

* add peer gossip sleep (tendermint#241) (tendermint#245)

* add peer gossip sleep

* add changelog

* Update .changelog/unreleased/bug-fixes/4-busy-loop-send-block-part.md

Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>

* Update .changelog/unreleased/bug-fixes/4-busy-loop-send-block-part.md

---------

Co-authored-by: jhernandezb <contact@jhernandez.me>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
(cherry picked from commit 5954e75)

Co-authored-by: Sergio Mena <sergio@informal.systems>

* Build changelog for v0.34.25 release

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Bump version

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
faddat pushed a commit to notional-labs/tendermint that referenced this pull request Apr 3, 2023
* v0.37.x:state/kvindexer: port 0.34 query fix (#77)
Backport of #77 from 0.37 and #382 to handle slashes
* state/kvindexer: associate event attributes with events (tendermint#9759)
* By event search is now default behaviour. Including fixes from PRs added to 0.34

---------

Co-authored-by: Lasaro <lasaro@gmail.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Sergio Mena <sergio@informal.systems>
adrianbrink pushed a commit to heliaxdev/tendermint that referenced this pull request May 23, 2023
* state/kvindexer: associate event attributes with events (tendermint#9759)
Co-authored-by: Anca Zamfir <zamfiranca@gmail.com>
Co-authored-by: Sergio Mena <sergio@informal.systems>
Co-authored-by: Romain Ruetschi <romain.ruetschi@gmail.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>

* Backport kvindexer fix

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Callum Waters <cmwaters19@gmail.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>

* By event search is now default behaviour. Including fixes from PRs added to 0.34

Co-authored-by: Lasaro <lasaro@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:indexer Component: Indexer
Projects
Status: Done/Merged
Development

Successfully merging this pull request may close these issues.

5 participants