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

feat: added notifications for validators opted in #598

Merged
merged 7 commits into from
Feb 14, 2025

Conversation

Mikelle
Copy link
Member

@Mikelle Mikelle commented Feb 11, 2025

Describe your changes

This PR introduces scheduling notifications for validator opt-ins, and running periodic epoch-based processing.

1. Notifications Module Minor Update

Topic Update

In p2p/pkg/notifications/notifications.go, a small addition was made (e.g., to support additional notification topics such as TopicValidatorOptedIn).

2. Validator Service Enhancements

Service Initialization

In p2p/pkg/rpc/validator/service.go, the NewService function has been refactored to:

  • Return an error along with the service instance.
  • Accept an additional notifier parameter to manage notifications.

Genesis Time Fetching

The service now fetches the genesis time from the Beacon API (/eth/v1/beacon/genesis). This timestamp is crucial for calculating slot start times.

Notification Scheduling

A new method, scheduleNotificationForSlot, has been implemented. It:

  • Computes the start time of a slot based on the fetched genesis time and a defined slot duration.
  • Schedules a notification to be sent before the slot starts (using a configurable notify offset).
  • Sends a notification via the provided notifier, including key details such as epoch, slot, and BLS key.

Epoch Processing & Cron Job

  • The processEpoch method now processes proposer duties, checks each validator’s opt-in status, and schedules notifications accordingly.
  • A new Start method runs a background cron job that:
    • Calculates the upcoming epoch based on the genesis time and epoch duration.
    • Waits until the appropriate time (using a configurable fetch offset) to fetch and process the epoch.
    • Logs the scheduling and processing of epochs.

Checklist before requesting a review

  • I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation

@Mikelle Mikelle self-assigned this Feb 11, 2025
Copy link
Collaborator

@aloknerurkar aloknerurkar left a comment

Choose a reason for hiding this comment

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

I think for testing, we can follow the same approach as we did for the relay-emulator. We can add the APIs to the relay emulator or create a new beacon emulator and always return validators that are opted in. One additional thing would be that we might need to deploy the middleware contract and register some dummy public keys. The keys we register should be the ones returned from our API.

nextEpoch := currentEpoch + 1
nextEpochStart := s.genesisTime.Add(time.Duration(nextEpoch) * EpochDuration)
fetchTime := nextEpochStart.Add(-FetchOffset)
delay := time.Until(fetchTime)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

map[string]any{
"epoch": epoch,
"slot": slot,
"bls_key": info.BLSKey,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for the clients it would be better to give the execution block number in the notification as they will bid on that. Can we somehow compute this? Or maybe some API which can provide this?


func (s *Service) scheduleNotificationForSlot(epoch uint64, slot uint64, info *validatorapiv1.SlotInfo) {
slotStartTime := s.genesisTime.Add(time.Duration(slot) * SlotDuration)
notificationTime := slotStartTime.Add(-NotifyOffset)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think we need this delay. We already have the delay to query the duties. I think we can send this as soon as we get the info. In case of the notifications, users will be always subscribed ideally. So sooner they get it, sooner they can decide to bid.

If they miss this, they should be able to query the get validators endpoint right?

p2p/pkg/rpc/validator/service.go Outdated Show resolved Hide resolved
p2p/pkg/rpc/validator/service_test.go Outdated Show resolved Hide resolved
@Mikelle Mikelle requested a review from mrekucci February 13, 2025 19:11
@Mikelle Mikelle merged commit 471bb88 into main Feb 14, 2025
5 checks passed
@Mikelle Mikelle deleted the feat/validators-notif branch February 14, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants