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

fix: actor events: read entries from event index in order of their insertion #11829

Closed
wants to merge 3 commits into from

Conversation

aarshkshah1992
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 commented Apr 4, 2024

Related Issues

Closes #11823

Proposed Changes

Event entries should be read from the event index in the order of their insertion

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@aarshkshah1992 aarshkshah1992 requested a review from a team as a code owner April 4, 2024 15:09
@aarshkshah1992 aarshkshah1992 changed the title fix:actor-events:order event entries after reading them fix: actor events:order event entries after reading them Apr 4, 2024
@aarshkshah1992 aarshkshah1992 changed the title fix: actor events:order event entries after reading them fix: actor events: read entries from event index in order of their insertion Apr 4, 2024
chain/events/filter/index.go Outdated Show resolved Hide resolved
chain/events/filter/index.go Outdated Show resolved Hide resolved
// create struct for holding EventEntry with ordering
type eventEntryWithOrdering struct {
types.EventEntry
ordering uint64
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to select this field, we just need to order by it when querying.

Copy link
Contributor Author

@aarshkshah1992 aarshkshah1992 Apr 4, 2024

Choose a reason for hiding this comment

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

@Stebalien For some reason, if I add this to the ordering, we get way more records than we want and the tests start failing. I spent time debugging it before giving up.

I had changed the current ordering to s += "ORDER BY event.height DESC, event_entry.ordering ASC".

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure the issue wasn't the removal of the space? Unless I'm mistaken, that should have worked.

// sort the entries in the collected event by ordering
for _, ce := range ces {
ce := ce
sort.Slice(ce.entries, func(i, j int) bool { return ce.entries[i].ordering < ce.entries[j].ordering })
Copy link
Member

Choose a reason for hiding this comment

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

Let's do this in the query.

@@ -672,8 +739,37 @@ func (ei *EventIndex) prefillFilter(ctx context.Context, f *eventFilter, exclude

// collected event list is in inverted order since we selected only the most recent events
// sort it into height order
sort.Slice(ces, func(i, j int) bool { return ces[i].Height < ces[j].Height })
f.setCollectedEvents(ces)
sort.Slice(ces, func(i, j int) bool { return ces[i].height < ces[j].height })
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why we bother with this at all...

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 agree. It was already here so didn't want to mess with it.

chain/events/filter/index.go Outdated Show resolved Hide resolved
// rollback the transaction (a no-op if the transaction was already committed)
defer tx.Rollback() //nolint:errcheck

if _, err = tx.ExecContext(ctx, "ALTER TABLE event_entry ADD COLUMN ordering INTEGER NOT NULL DEFAULT 0"); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to actually fill these (may be possible in a single statement?).

@aarshkshah1992
Copy link
Contributor Author

This should be closed once #11834 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ☑️ Done (Archive)
Development

Successfully merging this pull request may close these issues.

2 participants