Skip to content

Fix subnet unsubscription time #6890

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

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

pawanjay176
Copy link
Member

Issue Addressed

Hopefully fixes #6732

Proposed Changes

In our scheduled_subscriptions, we were setting unsubscription slot to be current_slot + 1. Given that we were subscribing to the subnet at duty.slot - 1, the unsubscription slot ended up being duty.slot. So we were unsubscribing to the subnet at the beginning of the duty slot which is insane.

Fixes the scheduled_subscriptions to unsubscribe at duty.slot + 1.

Additional Info

Running this on kurtosis made me realise that we do not send subscriptions for the first couple of slots because of https://github.com/sigp/lighthouse/blob/unstable/validator_client/validator_services/src/duties_service.rs#L79-L85

Not sure if we want to handle that.

@pawanjay176 pawanjay176 requested a review from jxs as a code owner January 30, 2025 22:11
Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Nice find!

The fix makes sense to me.

The testnet case is interesting, but I think a fix for that can wait for another PR. I guess we might want to special-case the VC's/BN's handling of the first ~2 slots of a network (feels kind of dumb), or remove the loud warnings for late subscriptions from the BN and just track them with a metric.

@michaelsproul
Copy link
Member

Looks like one of the tests is failing. It might actually be expecting the old behaviour 👀

@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. v7.0.0-beta.0 New release c. Q1 2025 labels Jan 30, 2025
@pawanjay176
Copy link
Member Author

I fixed the failing test according to my understanding.
I think prior to #6146 , the test was checking if we bundled multiple unsubscriptions together into a single one (e.g. if we need to unsubscribe from subnet X at slot 9 and 12, then skip the unsubscribe at 9).

After the refactor, we decide to extend the unsubscription only in subscribe_to_subnet_immediately 1 slot before the subscription. So multiple unsubscriptions will get bundled together only in the case where there's overlap between an existing subscription and the new one (e.g. if we are subscribing at slot 11 and there's a planned unsubscription event at slot 12, then we just extend the subscription).

TL;DR: the test test_subscribe_same_subnet_several_slots_apart wasn't refactored with the logic change in #6146 , and started failing when we fixed a bug. cbf7dca refactors the test.

@pawanjay176 pawanjay176 added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Jan 31, 2025
Copy link
Member

@jimmygchen jimmygchen left a comment

Choose a reason for hiding this comment

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

Nice find! 👍

let current_slot = self.beacon_chain.slot_clock.now().unwrap_or_default();
if let Err(e) = self.subscribe_to_subnet_immediately(subnet, current_slot + 1) {
let ExactSubnet { subnet, slot } = exact_subnet;
if let Err(e) = self.subscribe_to_subnet_immediately(subnet, slot + 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should add some comments referencing the issue and the reason for slot + 1 in the code. Useful if we ever refactor this and git blame breaks

@pawanjay176 pawanjay176 force-pushed the fix-unsubscription-time branch from 1f7c612 to 53fb5ea Compare February 1, 2025 00:38
Copy link
Collaborator

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

LGTM

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Feb 3, 2025
mergify bot added a commit that referenced this pull request Feb 3, 2025
Copy link

mergify bot commented Feb 3, 2025

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@michaelsproul
Copy link
Member

Fix for CI failure:

Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

Yeah nice catch.

I wouldn't have imagined this would change the density of subscribed subnets between 5.3 and 6.0?

@jimmygchen
Copy link
Member

@mergify requeue

Copy link

mergify bot commented Feb 3, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

mergify bot added a commit that referenced this pull request Feb 3, 2025
@mergify mergify bot merged commit a088b0b into sigp:unstable Feb 3, 2025
31 checks passed
@jimmygchen
Copy link
Member

Yeah nice catch.

I wouldn't have imagined this would change the density of subscribed subnets between 5.3 and 6.0?

Looks like this was introduced in #6146 which was part of the 6.0 release (My bad, I missed this in the review!).

The old logic was good and same as the fix in this PR:
https://github.com/sigp/lighthouse/blob/08e8b92e5032044f253a7357aaf0a7c74f9f8b80/beacon_node/network/src/subnet_service/attestation_subnets.rs#L644-L647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge. v7.0.0-beta.0 New release c. Q1 2025
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants