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

chore(events): improve perf for parallel event filter matching #12603

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Oct 16, 2024

Blocked until #12421 is merged and we can do this against master.

I started writing up a good-first-issue ticket for this but it eneded up being easier to write the code than describe what needed doing.

  1. Cache address look-ups for the given tipset across filters
  2. Run the filters in an errgroup
  3. Removed the bool return argument and just use address.Undef, I believe there's no case where this is an acceptable value

Filters can be installed via eth_newFilter, eth_subscribe and SubscribeActorEventsRaw. All filters installed have CollectEvents run on them for each new tipset and revert. So this can get expensive if you're an RPC provider who allows users to install these things and watch for live events.

@BigLep
Copy link
Member

BigLep commented Oct 28, 2024

@rvagg : is this something you're hoping to see land for 1.31.0?

@rvagg
Copy link
Member Author

rvagg commented Oct 28, 2024

Yes, but I'd like chainindexer to land first, this can go in separately. Like #12623 I think they deserve separate call-outs in the CHANGELOG.

Base automatically changed from feat/msg-eth-tx-index to master October 31, 2024 09:58
@rvagg rvagg force-pushed the rvagg/parallel-event-filters branch 2 times, most recently from 35a9852 to e01d209 Compare November 4, 2024 02:58
@rjan90
Copy link
Contributor

rjan90 commented Nov 11, 2024

@rvagg should we land this now, given that we are looking at release v1.31.0-rc1 tomorrow?

@rvagg rvagg requested a review from masih November 18, 2024 02:57
1. Cache address look-ups for the given tipset across filters
2. Run the filters in an errgroup
@rvagg rvagg force-pushed the rvagg/parallel-event-filters branch from e01d209 to db90330 Compare November 18, 2024 02:59
@rvagg
Copy link
Member Author

rvagg commented Nov 18, 2024

Tagging @masih who would be a good person to review this change.

@@ -28,7 +29,10 @@ func isIndexedValue(b uint8) bool {
return b&(types.EventFlagIndexedKey|types.EventFlagIndexedValue) > 0
}

type AddressResolver func(context.Context, abi.ActorID, *types.TipSet) (address.Address, bool)
// AddressResolver is a function that resolves an actor ID to an address. If the
// actor ID cannot be resolved to an address, the function should return
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// actor ID cannot be resolved to an address, the function should return
// actor ID cannot be resolved to an address, the function must return

...because the code correctness depends on it?

if err := f.CollectEvents(ctx, tse, false, m.AddressResolver); err != nil {
return err
}
f := f
Copy link
Member

Choose a reason for hiding this comment

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

Redundant now that this module depends on Go 1.22.

Suggested change
f := f

if err := f.CollectEvents(ctx, tse, true, m.AddressResolver); err != nil {
return err
}
f := f
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

}

return nil
}

func (m *EventFilterManager) createTipSetCachedAddressResolver() func(ctx context.Context, emitter abi.ActorID, ts *types.TipSet) address.Address {
Copy link
Member

Choose a reason for hiding this comment

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

Subjective:

  • This could be a function (in FP sense): takes an address resolver and returns a cached version of it.

Then:

  • One could wrap the struct field resolver with it at EventFilterManager.
  • This would avoid multiple calls to createTipSetCachedAddressResolver in favour of singular cached address resolver for the lifetime of event filter manager (assuming this is desirable for performance reasons, though watch out for unbounded map size growth).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✔️ Approved by reviewer
Development

Successfully merging this pull request may close these issues.

4 participants