Skip to content

Conversation

jmalicevic
Copy link
Contributor

@jmalicevic jmalicevic commented Mar 24, 2023

Closes #571 .

Removes the event function type identifier form the event key. Earlier having this in the key made sense as it differentiated between BeginBlock and EndBlock events. With FinalizeBlock it will always be the same and has no point.

The only issue is that we need to support data indexed with old versions where the key has the function identifier key (see util.go:L123.

Note: I am piggybacking updates to the tests because there were duplicate UTs and UTs refering to match_events which do not exist in this version.


PR checklist

  • Tests written/updated
  • Backwards compatibility test
  • Run e2e upgrading test
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@jmalicevic jmalicevic added this to the 2023-Q1 milestone Mar 24, 2023
@jmalicevic jmalicevic self-assigned this Mar 24, 2023
@jmalicevic jmalicevic linked an issue Mar 24, 2023 that may be closed by this pull request
2 tasks
@jmalicevic jmalicevic marked this pull request as ready for review March 27, 2023 11:19
@jmalicevic jmalicevic requested a review from a team as a code owner March 27, 2023 11:19
@jmalicevic jmalicevic marked this pull request as draft March 29, 2023 13:19
@jmalicevic jmalicevic added the backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x label Apr 4, 2023
@jmalicevic jmalicevic marked this pull request as ready for review April 4, 2023 08:20
Comment on lines -232 to -235
"query return all events from a height - exact - no match.events": {
q: query.MustCompile("block.height = 1"),
results: []int64{1},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why these test cases are no longer needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BEcause they are the exact duplicate of the existing tests - they were there because we used to test with and without the match-events keywords and then when I fixed the tests for not use the keyword, I did not delete the duplicate ones.

if err != nil { // If it cannot parse the event function type, it could be 1
remaining, err2 := orderedcode.Parse(string(key), &compositeKey, &eventValue, &height, &eventSeq)
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq
return 0, fmt.Errorf("failed to parse event key: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also want to report err2?

} else {
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If 2, , retrieve the eventSeq, otherwise ignore
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq
return 0, fmt.Errorf("failed to parse event key: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Report err2?

}

} else {
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If 2, , retrieve the eventSeq, otherwise ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

What does "If 2, ," mean?
Also, how do we ignore here? (I see we're returning the error if err2 is not nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If 2 - the case under number 2. above , that have both an event sequence and event type.
I will rephrase this, but essentially ignore means, that we do not have the event sequence, but rather just the event function type (case 3.), and we will ignore. Err2 should still be returned.

q: "account.number <= 2 AND account.owner CONTAINS '/Iv' AND account.owner CONTAINS 'an' AND tx.height = 1",
resultsLength: 1,
},
" Match range with match events contains": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we testing all "if" branches in the changes to file state/indexer/block/kv/util.go above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not think of how to test the cases with UTs because those if branches are handling events indexed using old versions of the indexer. Unless we create different indexing options in our UTs. We could provide a custom indexing function to generate the event key differently and then test. That is basically what i did manually. And I did this with the backwards compatibility tests when running on top of data indexed with old versions.

Comment on lines 136 to 141
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If the event follows the scenario in 2.,
// retrieve the eventSeq, otherwise, there should be no remainder
// and no error and this parsing has no effect.
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq if in 2.
return 0, fmt.Errorf("failed to parse event key: %w", err2)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // If the event follows the scenario in 2.,
// retrieve the eventSeq, otherwise, there should be no remainder
// and no error and this parsing has no effect.
if err2 != nil || len(remaining) != 0 { // We should not have anything else after the eventSeq if in 2.
return 0, fmt.Errorf("failed to parse event key: %w", err2)
}
if len(remaining2) != 0 { // Are we in case 2 or 3
remaining, err2 := orderedcode.Parse(remaining2, &eventSeq) // the event follows the scenario in 2.,
// retrieve the eventSeq
// there should be no error
if err2 != nil { // We should not have anything else after the eventSeq if in 2.
return 0, fmt.Errorf("failed to parse event key: %w", err2)
}
}

I'm suggesting this, because I don't clearly see the path taken by scenario 3 in the present code.
I also see two main advantages with my suggestion:

  • Easier to distinguish paths followed by scenarios 2 and 3
  • You don't call Parse unless you're sure you need to call it (cleaner)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am fine with the chaneg but we still need to check whether len(remaining) != 0 because that is invalid. I will push a change including both. Let me know if you agree.

@thanethomson thanethomson modified the milestones: 2023-Q1, 2023-Q2 Apr 13, 2023
Comment on lines 1 to 2
- `[kvindex]` Remove event function type from event key in kvindexer. The function type is not always `FinalizeBlock`.
([\#581](https://github.com/cometbft/cometbft/pull/581))
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the impact here on the user? If there's no direct impact on the user, it's not clear to me that we'd need a changelog entry. If the overall goal is to reduce storage consumption, then I'd recommend rewording to something that explicitly highlights that. Users may not understand what this changelog entry means for them otherwise.

Also, if it's being backported to v0.38, then the PR to main shouldn't have a changelog entry - only the backport PR should have a changelog entry (from a user's perspective, they'd be receiving this change in the v0.38 release series, so there'd be no need to also be notified about it in the v0.39 series).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I will remove the changelog entry here. As for the impact on the user, there is no direct impact as far as I can see. We have info on this in the upgrading docs for 0.38 because the format of data on disk changes. However, people who have forks that play with the indexer, they might be impacted.

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 for the refactoring of the intricate code!

@jmalicevic
Copy link
Contributor Author

Thank you guys for improving it! @lasarojc , let me know if you are happy with the changes and I can merge this :)

@jmalicevic jmalicevic merged commit e9e9cf3 into main Apr 28, 2023
@jmalicevic jmalicevic deleted the jasmina/571-kvindexer-remove-event-type branch April 28, 2023 19:47
mergify bot pushed a commit that referenced this pull request Apr 28, 2023
* Applied @serigo-menas PR comments

* Removed changelog entry

* Refactored code according to suggestion from @lasarojc

---------

Co-authored-by: Sergio Mena <sergio@informal.systems>
Co-authored-by: Lásaro Camargos <lasaro@informal.systems>
(cherry picked from commit e9e9cf3)
jmalicevic added a commit that referenced this pull request May 3, 2023
…kport #581) (#774)

* kvindexer: Removing event function type as it is always the same (#581)

* Applied @serigo-menas PR comments

* Removed changelog entry

* Refactored code according to suggestion from @lasarojc

---------

Co-authored-by: Sergio Mena <sergio@informal.systems>
Co-authored-by: Lásaro Camargos <lasaro@informal.systems>
(cherry picked from commit e9e9cf3)

* Added changelog

* Update .changelog/unreleased/breaking-changes/774-state-indexerevent-remove-function-type.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

---------

Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
thanethomson pushed a commit that referenced this pull request May 6, 2023

* Applied @serigo-menas PR comments

* Removed changelog entry

* Refactored code according to suggestion from @lasarojc

---------

Co-authored-by: Sergio Mena <sergio@informal.systems>
Co-authored-by: Lásaro Camargos <lasaro@informal.systems>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x indexer storage
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

kvindexer: Remove event type from block event
4 participants