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

Interop: event handling utils and syntax sugar #10983

Closed
Tracked by #10865
protolambda opened this issue Jun 23, 2024 · 0 comments · Fixed by #11040
Closed
Tracked by #10865

Interop: event handling utils and syntax sugar #10983

protolambda opened this issue Jun 23, 2024 · 0 comments · Fixed by #11040
Assignees

Comments

@protolambda
Copy link
Contributor

protolambda commented Jun 23, 2024

Event helper functions

See review-discussion in: #10947 (review)

Instead of defining inline functions that help run an action-test until a certain event, we can use generics.

Example:

// in rollup package

// IsEventType is syntax-sugar to do a type check as a boolean function
func IsEventType[T Event](ev Event) bool {
	_, ok := ev.(T)
	return ok
}

// IsEventAny combines different event conditions into a single function
func IsEventAny(fns ...func(ev Event) bool) func(ev Event) bool {
	return func(ev Event) bool {
		for _, fn := range fns {
			if fn(ev) {
				return true
			}
		}
		return false
	}
}

// in action test package, example:

sequencer.ActL2EventsUntil(rollup.IsEventEny(rollup.IsEventType[derive.DeriverIdleEvent], rollup.IsEventType[engine.PendingSafeUpdateEvent]))

Generally the op-e2e tests, especially the action-test framework, can benefit from the new event system, and introducing some helper functions would improve future test writing.

Event metrics

We can add 2 counter metrics:

  • total emitted events
  • total processed events

And with the stringified event type (.String(), no need for reflection) as event label.

From these two we can then monitor a lot of the processing:

  • rate of events
  • backlogs (diff of emitted and processed)

All per event type, and the totals.

Event package

We can probably make this even more elegant, by putting all the event utils and types into its own event package:

  • helpers: event.Is, event.Any
  • main interface type: event.Event
  • relevant interfaces: event.Emitter, event.Deriver
  • core utils: event.Loop (the rollup.SynchronousEvents loop util)
  • future utils: event.System (the parallel processing system)
  • etc.

This way the type util/interface usage reads better.

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

Successfully merging a pull request may close this issue.

1 participant