Skip to content

Add provider address to event data structs - #286

Open
AntiD2ta wants to merge 3 commits into
masterfrom
add_event_provider
Open

Add provider address to event data structs#286
AntiD2ta wants to merge 3 commits into
masterfrom
add_event_provider

Conversation

@AntiD2ta

@AntiD2ta AntiD2ta commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Added Provider string field to all owned event data structs: HeadEvent, BlockEvent, ChainReorgEvent, FinalizedCheckpointEvent, BlobSidecarEvent, BlockGossipEvent, PayloadAttributesEvent, DataColumnSidecarEvent, and the generic Event container
  • Added WithProvider/Provider context helpers in api/v1 for universal provider extraction across all event types
  • HTTP and multi-client event handlers now populate the provider address on event data and context before forwarding to consumers

Note that seven event types use spec structs that model consensus data types (VersionedAttestation, AttesterSlashing, etc.) that should not carry a Provider field.

The context-based approach (apiv1.WithProvider/apiv1.Provider) provides a universal mechanism that works for all 15 event types, while the struct field is a convenience for the 9 types we own.

Example usage on Vouch

When the provider is available directly on the HeadEvent struct:

  func (s *Service) HandleHeadEvent(ctx context.Context, event *apiv1.HeadEvent) {
      // The provider address is embedded in the event data.
      provider := event.Provider // e.g. "http://localhost:5052"

      s.blockReceiptDelay.WithLabelValues(provider).Observe(delay.Seconds())
  }

For event types that use external spec structs (e.g. attestations), where the struct can't carry the field, we can extract it from context instead:

  func (s *Service) HandleAttestationEvent(ctx context.Context, event *spec.VersionedAttestation) {
      provider := apiv1.Provider(ctx) // universal mechanism, works for all event types

      // ...
  }

The context mechanism (apiv1.Provider(ctx)) works for all 15 event types, so Vouch could use it universally if preferred. The struct field is a convenience for the 8 owned types.

Allow consumers to identify which beacon node delivered each event.
@AntiD2ta AntiD2ta self-assigned this Mar 25, 2026
@AntiD2ta AntiD2ta added the enhancement New feature or request label Mar 25, 2026
@AntiD2ta
AntiD2ta requested a review from Bez625 March 25, 2026 16:51
@AntiD2ta
AntiD2ta force-pushed the add_event_provider branch from 880be93 to d5ed32d Compare March 25, 2026 16:58
Comment thread api/v1/provider.go Outdated
// This is the universal mechanism for obtaining the provider address
// across all event types. Event structs owned by this package also
// carry the address directly in their Provider field.
func WithProvider(ctx context.Context, provider string) context.Context {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of the provider being passed in the context. I looked at vouch and I can only see us using head and block event handlers. I think let's limit this to updating the *Event structs to have the Provider field and set them where possible. Given we have explicit types at the callsite for these, we know if they have the Provider or not so it's type safe / requires no validation.

I think if we want this behaviour on the other handlers we should look to find reasons and upgrade them to returning *Event types that explicitly set the Provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done 346dc29

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@AntiD2ta

Copy link
Copy Markdown
Contributor Author

Created #288 to address adding the Provider on consensus types event data structs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants