Search in sources :

Example 1 with SyncCommitteeSubnetSubscriptions

use of tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetSubscriptions in project teku by ConsenSys.

the class SubnetScorerTest method shouldScoreCandidatePeersOnSubnetsWithFewPeersMoreHighly.

@Test
void shouldScoreCandidatePeersOnSubnetsWithFewPeersMoreHighly() {
    final MockNodeId node1 = new MockNodeId(0);
    final MockNodeId node2 = new MockNodeId(1);
    final MockNodeId node3 = new MockNodeId(2);
    final SubnetScorer scorer = SubnetScorer.create(PeerSubnetSubscriptions.builder(() -> schemaDefinitions).attestationSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addRelevantSubnet(3).addRelevantSubnet(5).addSubscriber(1, node2).addSubscriber(3, node3)).syncCommitteeSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addSubscriber(1, node1).addSubscriber(1, node2).addSubscriber(1, node3)).build());
    assertCandidatePeerScores(scorer, entry(candidateWithSubnets(List.of(1, 3), List.of(1)), 562), entry(candidateWithSubnets(List.of(1), List.of(1)), 312), entry(candidateWithSubnets(List.of(2), List.of(1)), 1062), entry(candidateWithSubnets(List.of(3), List.of(1)), 312), entry(candidateWithSubnets(emptyList(), emptyList()), 0), entry(candidateWithSubnets(List.of(5), emptyList()), 1000), entry(candidateWithSubnets(List.of(4), emptyList()), 0), entry(candidateWithSubnets(emptyList(), List.of(2)), 1000), entry(candidateWithSubnets(emptyList(), List.of(3)), 0));
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) PeerScorer(tech.pegasys.teku.networking.eth2.peers.PeerScorer) Collections.emptyList(java.util.Collections.emptyList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) Assertions.entry(org.assertj.core.api.Assertions.entry) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Stream(java.util.stream.Stream) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Spec(tech.pegasys.teku.spec.Spec) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Test(org.junit.jupiter.api.Test)

Example 2 with SyncCommitteeSubnetSubscriptions

use of tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetSubscriptions in project teku by ConsenSys.

the class SubnetScorerTest method shouldScoreExistingPeersOnSubnetsWithFewPeersMoreHighly.

@Test
void shouldScoreExistingPeersOnSubnetsWithFewPeersMoreHighly() {
    final MockNodeId node1 = new MockNodeId(0);
    final MockNodeId node2 = new MockNodeId(1);
    final MockNodeId node3 = new MockNodeId(2);
    final MockNodeId node4 = new MockNodeId(3);
    final MockNodeId node5 = new MockNodeId(4);
    final SubnetScorer scorer = SubnetScorer.create(PeerSubnetSubscriptions.builder(() -> schemaDefinitions).attestationSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addRelevantSubnet(3).addRelevantSubnet(4).addSubscriber(1, node1).addSubscriber(1, node2).addSubscriber(1, node3).addSubscriber(1, node4).addSubscriber(2, node1).addSubscriber(2, node2).addSubscriber(3, node3).addSubscriber(5, node2)).syncCommitteeSubnetSubscriptions(b -> b.addRelevantSubnet(3).addSubscriber(3, node1).addSubscriber(3, node4).addSubscriber(2, node3)).build());
    assertExistingPeerScores(scorer, entry(node1, 562), entry(node2, 312), entry(node3, 1062), entry(node4, 312), entry(node5, 0));
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) PeerScorer(tech.pegasys.teku.networking.eth2.peers.PeerScorer) Collections.emptyList(java.util.Collections.emptyList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) Assertions.entry(org.assertj.core.api.Assertions.entry) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Stream(java.util.stream.Stream) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Spec(tech.pegasys.teku.spec.Spec) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Test(org.junit.jupiter.api.Test)

Example 3 with SyncCommitteeSubnetSubscriptions

use of tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetSubscriptions in project teku by ConsenSys.

the class GossipForkSubscriptionsAltair method addGossipManagers.

@Override
protected void addGossipManagers(final ForkInfo forkInfo) {
    super.addGossipManagers(forkInfo);
    final SchemaDefinitionsAltair schemaDefinitions = SchemaDefinitionsAltair.required(spec.atEpoch(getActivationEpoch()).getSchemaDefinitions());
    syncCommitteeContributionGossipManager = new SignedContributionAndProofGossipManager(recentChainData, schemaDefinitions, asyncRunner, discoveryNetwork, gossipEncoding, forkInfo, signedContributionAndProofOperationProcessor, getMessageMaxSize());
    addGossipManager(syncCommitteeContributionGossipManager);
    final SyncCommitteeSubnetSubscriptions syncCommitteeSubnetSubscriptions = new SyncCommitteeSubnetSubscriptions(spec, recentChainData, discoveryNetwork, gossipEncoding, schemaDefinitions, asyncRunner, syncCommitteeMessageOperationProcessor, forkInfo, getMessageMaxSize());
    syncCommitteeMessageGossipManager = new SyncCommitteeMessageGossipManager(metricsSystem, spec, new SyncCommitteeStateUtils(spec, recentChainData), syncCommitteeSubnetSubscriptions);
    addGossipManager(syncCommitteeMessageGossipManager);
}
Also used : SyncCommitteeStateUtils(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils) SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) SignedContributionAndProofGossipManager(tech.pegasys.teku.networking.eth2.gossip.SignedContributionAndProofGossipManager) SyncCommitteeSubnetSubscriptions(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetSubscriptions) SyncCommitteeMessageGossipManager(tech.pegasys.teku.networking.eth2.gossip.SyncCommitteeMessageGossipManager)

Aggregations

Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.entry (org.assertj.core.api.Assertions.entry)2 Test (org.junit.jupiter.api.Test)2 SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)2 PeerScorer (tech.pegasys.teku.networking.eth2.peers.PeerScorer)2 MockNodeId (tech.pegasys.teku.networking.p2p.mock.MockNodeId)2 NodeId (tech.pegasys.teku.networking.p2p.peer.NodeId)2 Spec (tech.pegasys.teku.spec.Spec)2 TestSpecFactory (tech.pegasys.teku.spec.TestSpecFactory)2 SchemaDefinitions (tech.pegasys.teku.spec.schemas.SchemaDefinitions)2 SignedContributionAndProofGossipManager (tech.pegasys.teku.networking.eth2.gossip.SignedContributionAndProofGossipManager)1 SyncCommitteeMessageGossipManager (tech.pegasys.teku.networking.eth2.gossip.SyncCommitteeMessageGossipManager)1 SyncCommitteeSubnetSubscriptions (tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetSubscriptions)1