Skip to content

Conversation

AgeManning
Copy link
Member

This PR address the following spec change: ethereum/consensus-specs#3312

Instead of subscribing to a long-lived subnet for every attached validator to a beacon node, all beacon nodes will subscribe to SUBNETS_PER_NODE long-lived subnets. This is currently set to 2 for mainnet.

This PR does not include any scoring or advanced discovery mechanisms. A future PR will improve discovery and we can implement scoring after the next hard fork when we expect all client teams and all implementations to respect this spec change.

This will be a significant change in the subnet network structure for consensus clients and we will likely have to monitor and tweak our peer management logic.

@AgeManning AgeManning added the ready-for-review The code is ready for review label May 18, 2023
pub subnets_per_node: u8,
pub epochs_per_subnet_subscription: u64,
attestation_subnet_extra_bits: u8,
pub attestation_subnet_extra_bits: u8,
Copy link
Contributor

Choose a reason for hiding this comment

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

this was private since it's a calculated field. Why make it public?

Copy link
Member Author

Choose a reason for hiding this comment

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

The extra bits is no longer a calculated field. The attestation_subnet_prefix_bits is now calculated from attestation_subnet_extra_bits and attestation_subnet_count.

With that said, I'm not sure we reference it explicitly anywhere, so made it pub more for consistency.

Comment on lines +93 to +97
// Calculate at which epoch this node needs to re-evaluate
let valid_until_epoch = epoch.as_u64()
+ subscription_duration
.saturating_sub((epoch.as_u64() + node_offset) % subscription_duration);

Copy link
Contributor

Choose a reason for hiding this comment

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

if the epoch is 0 and the offset is 1 for a subscription duration of 10 this means the offset is backwards?
Here the valid_until_epoch is 0 + 10 - (0 + 1) = 9 I would have expected this to be 1. Not claiming this to be wrong, just making sure this is the intended use

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah had me worried here for a bit. Intuitively I'd agree with you.
After a bit of thought, it works like this:
The node-offset is always added to the epoch to shift the transition. It shouldn't be thought of as the epoch at which the subnet changes. i.e it wont shift at epoch 1 (like we intuitively expect).

Note that we shift epochs once: (epoch + node_offset) % subscription_duration == 0.

So in your example, we have one subnet at ( 0 + 1) % 10.
Then it will take another 9 more epochs before we hit that threshold and have to change subnets.

A better way to visualize is, is to set the node_offset to 0 and epoch to 1. We get the same result, have to wait 9 epochs.

#[cfg(test)]
mod tests {
use super::*;

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how hard it is to craft an easy test case, but I think it would be beneficial to test the validity of valid_until_epoch. This means testing that the range [valid_until_epoch-subscription_duration, valid_until_epoch) produce the same subnets as the expected subnets of the tested epoch

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a few tests, where i tested against the pyspec. It's not in the rust code, but what I did was, create a for-loop in python and just go through every epoch and return the epoch when the pyspec tells us that we should be on a new spec. The test compares this fixed python result, with the calculated version in rust.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I did the tests in the range [epoch, valid_until_epoch) checking the valid_epoch doesn't change and the subnets don't change either. Also tested that in valid_during_epoch the results change. I'm therefore convinced this is legit

Copy link
Contributor

@divagant-martian divagant-martian left a comment

Choose a reason for hiding this comment

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

I'm convinced this is fine plus it's great to finally see the legacy code removed 🚀

@divagant-martian
Copy link
Contributor

This is for later, since I don't want to delay merging this PR
There is #3960, could you later test this with

diff --git a/beacon_node/network/src/subnet_service/tests/mod.rs b/beacon_node/network/src/subnet_service/tests/mod.rs
index 3b8c89a44..e9b91f3bf 100644
--- a/beacon_node/network/src/subnet_service/tests/mod.rs
+++ b/beacon_node/network/src/subnet_service/tests/mod.rs
@@ -176,7 +176,6 @@ async fn get_events<S: Stream<Item = SubnetServiceMessage> + Unpin>(
 
 mod attestation_service {
 
-    #[cfg(not(windows))]
     use crate::subnet_service::attestation_subnets::MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD;
 
     use super::*;
@@ -291,7 +290,6 @@ mod attestation_service {
     }
 
     /// Test to verify that we are not unsubscribing to a subnet before a required subscription.
-    #[cfg(not(windows))]
     #[tokio::test]
     async fn test_same_subnet_unsubscription() {
         // subscription config
@@ -536,7 +534,6 @@ mod attestation_service {
         assert_eq!(unexpected_msg_count, 0);
     }
 
-    #[cfg(not(windows))]
     #[tokio::test]
     async fn test_subscribe_same_subnet_several_slots_apart() {
         // subscription config
@@ -814,4 +811,4 @@ mod sync_committee_service {
         // Should be unsubscribed at the end.
         assert_eq!(sync_committee_service.subscription_count(), 1);
     }
-}
+}
\ No newline at end of file

@divagant-martian divagant-martian added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels May 27, 2023
@divagant-martian
Copy link
Contributor

@AgeManning just noticed the feature flag is still declared in the Cargo.toml
You'll find it with a quick rg deterministic_long_lived_attnets

@divagant-martian divagant-martian added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-merge This PR is ready to merge. labels May 29, 2023
@AgeManning AgeManning added ready-for-merge This PR is ready to merge. and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels May 30, 2023
@michaelsproul
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request May 30, 2023
This PR address the following spec change: ethereum/consensus-specs#3312

Instead of subscribing to a long-lived subnet for every attached validator to a beacon node, all beacon nodes will subscribe to `SUBNETS_PER_NODE` long-lived subnets. This is currently set to 2 for mainnet. 

This PR does not include any scoring or advanced discovery mechanisms. A future PR will improve discovery and we can implement scoring after the next hard fork when we expect all client teams and all implementations to respect this spec change.

This will be a significant change in the subnet network structure for consensus clients and we will likely have to monitor and tweak our peer management logic.
@bors
Copy link

bors bot commented May 30, 2023

Pull request successfully merged into unstable.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title Shift subnet backbone structure (attnets revamp) [Merged by Bors] - Shift subnet backbone structure (attnets revamp) May 30, 2023
@bors bors bot closed this May 30, 2023
divagant-martian pushed a commit to divagant-martian/lighthouse that referenced this pull request Jun 7, 2023
This PR address the following spec change: ethereum/consensus-specs#3312

Instead of subscribing to a long-lived subnet for every attached validator to a beacon node, all beacon nodes will subscribe to `SUBNETS_PER_NODE` long-lived subnets. This is currently set to 2 for mainnet. 

This PR does not include any scoring or advanced discovery mechanisms. A future PR will improve discovery and we can implement scoring after the next hard fork when we expect all client teams and all implementations to respect this spec change.

This will be a significant change in the subnet network structure for consensus clients and we will likely have to monitor and tweak our peer management logic.
ghost pushed a commit to oone-world/lighthouse that referenced this pull request Jul 13, 2023
This PR address the following spec change: ethereum/consensus-specs#3312

Instead of subscribing to a long-lived subnet for every attached validator to a beacon node, all beacon nodes will subscribe to `SUBNETS_PER_NODE` long-lived subnets. This is currently set to 2 for mainnet. 

This PR does not include any scoring or advanced discovery mechanisms. A future PR will improve discovery and we can implement scoring after the next hard fork when we expect all client teams and all implementations to respect this spec change.

This will be a significant change in the subnet network structure for consensus clients and we will likely have to monitor and tweak our peer management logic.
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
This PR address the following spec change: ethereum/consensus-specs#3312

Instead of subscribing to a long-lived subnet for every attached validator to a beacon node, all beacon nodes will subscribe to `SUBNETS_PER_NODE` long-lived subnets. This is currently set to 2 for mainnet. 

This PR does not include any scoring or advanced discovery mechanisms. A future PR will improve discovery and we can implement scoring after the next hard fork when we expect all client teams and all implementations to respect this spec change.

This will be a significant change in the subnet network structure for consensus clients and we will likely have to monitor and tweak our peer management logic.
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
This PR address the following spec change: ethereum/consensus-specs#3312

Instead of subscribing to a long-lived subnet for every attached validator to a beacon node, all beacon nodes will subscribe to `SUBNETS_PER_NODE` long-lived subnets. This is currently set to 2 for mainnet.

This PR does not include any scoring or advanced discovery mechanisms. A future PR will improve discovery and we can implement scoring after the next hard fork when we expect all client teams and all implementations to respect this spec change.

This will be a significant change in the subnet network structure for consensus clients and we will likely have to monitor and tweak our peer management logic.
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants