Search in sources :

Example 1 with TargetPeerRange

use of tech.pegasys.teku.networking.p2p.connection.TargetPeerRange in project teku by ConsenSys.

the class Eth2P2PNetworkBuilder method buildNetwork.

protected DiscoveryNetwork<?> buildNetwork(final GossipEncoding gossipEncoding, final SubnetSubscriptionService syncCommitteeSubnetService) {
    final ReputationManager reputationManager = new ReputationManager(metricsSystem, timeProvider, Constants.REPUTATION_MANAGER_CAPACITY);
    PreparedGossipMessageFactory defaultMessageFactory = gossipEncoding.createPreparedGossipMessageFactory(recentChainData::getMilestoneByForkDigest);
    final GossipTopicFilter gossipTopicsFilter = new Eth2GossipTopicFilter(recentChainData, gossipEncoding, spec);
    final NetworkConfig networkConfig = config.getNetworkConfig();
    final DiscoveryConfig discoConfig = config.getDiscoveryConfig();
    final P2PNetwork<Peer> p2pNetwork = createLibP2PNetworkBuilder().asyncRunner(asyncRunner).metricsSystem(metricsSystem).config(networkConfig).privateKeyProvider(new LibP2PPrivateKeyLoader(keyValueStore, networkConfig.getPrivateKeySource())).reputationManager(reputationManager).rpcMethods(rpcMethods).peerHandlers(peerHandlers).preparedGossipMessageFactory(defaultMessageFactory).gossipTopicFilter(gossipTopicsFilter).build();
    final AttestationSubnetTopicProvider attestationSubnetTopicProvider = new AttestationSubnetTopicProvider(recentChainData, gossipEncoding);
    final SyncCommitteeSubnetTopicProvider syncCommitteeSubnetTopicProvider = new SyncCommitteeSubnetTopicProvider(recentChainData, gossipEncoding);
    final TargetPeerRange targetPeerRange = new TargetPeerRange(discoConfig.getMinPeers(), discoConfig.getMaxPeers(), discoConfig.getMinRandomlySelectedPeers());
    final SchemaDefinitionsSupplier currentSchemaDefinitions = () -> recentChainData.getCurrentSpec().getSchemaDefinitions();
    return createDiscoveryNetworkBuilder().metricsSystem(metricsSystem).asyncRunner(asyncRunner).kvStore(keyValueStore).p2pNetwork(p2pNetwork).peerSelectionStrategy(new Eth2PeerSelectionStrategy(targetPeerRange, network -> PeerSubnetSubscriptions.create(currentSchemaDefinitions, network, attestationSubnetTopicProvider, syncCommitteeSubnetTopicProvider, syncCommitteeSubnetService, config.getTargetSubnetSubscriberCount()), reputationManager, Collections::shuffle)).discoveryConfig(discoConfig).p2pConfig(networkConfig).spec(config.getSpec()).currentSchemaDefinitionsSupplier(currentSchemaDefinitions).build();
}
Also used : PreparedGossipMessageFactory(tech.pegasys.teku.networking.p2p.gossip.PreparedGossipMessageFactory) Eth2PeerSelectionStrategy(tech.pegasys.teku.networking.eth2.peers.Eth2PeerSelectionStrategy) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) NetworkConfig(tech.pegasys.teku.networking.p2p.network.config.NetworkConfig) AttestationSubnetTopicProvider(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationSubnetTopicProvider) TargetPeerRange(tech.pegasys.teku.networking.p2p.connection.TargetPeerRange) LibP2PPrivateKeyLoader(tech.pegasys.teku.networking.p2p.libp2p.LibP2PPrivateKeyLoader) Eth2GossipTopicFilter(tech.pegasys.teku.networking.eth2.gossip.topics.Eth2GossipTopicFilter) GossipTopicFilter(tech.pegasys.teku.networking.p2p.libp2p.gossip.GossipTopicFilter) Eth2GossipTopicFilter(tech.pegasys.teku.networking.eth2.gossip.topics.Eth2GossipTopicFilter) SchemaDefinitionsSupplier(tech.pegasys.teku.spec.schemas.SchemaDefinitionsSupplier) SyncCommitteeSubnetTopicProvider(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetTopicProvider) ReputationManager(tech.pegasys.teku.networking.p2p.reputation.ReputationManager) DiscoveryConfig(tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig) Collections(java.util.Collections)

Example 2 with TargetPeerRange

use of tech.pegasys.teku.networking.p2p.connection.TargetPeerRange in project teku by ConsenSys.

the class DiscoveryNetworkTest method shouldNotEnableDiscoveryWhenDiscoveryIsDisabled.

@Test
public void shouldNotEnableDiscoveryWhenDiscoveryIsDisabled() {
    final DiscoveryConfig discoveryConfig = DiscoveryConfig.builder().isDiscoveryEnabled(false).build();
    final NetworkConfig networkConfig = NetworkConfig.builder().build();
    final PeerSelectionStrategy peerSelectionStrategy = new SimplePeerSelectionStrategy(new TargetPeerRange(20, 30, 0));
    final DiscoveryNetwork<?> network = DiscoveryNetworkBuilder.create().metricsSystem(new NoOpMetricsSystem()).asyncRunner(DelayedExecutorAsyncRunner.create()).kvStore(new MemKeyValueStore<>()).p2pNetwork(p2pNetwork).peerSelectionStrategy(peerSelectionStrategy).discoveryConfig(discoveryConfig).p2pConfig(networkConfig).spec(spec).currentSchemaDefinitionsSupplier(spec::getGenesisSchemaDefinitions).build();
    assertThat(network.getEnr()).isEmpty();
}
Also used : NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) NetworkConfig(tech.pegasys.teku.networking.p2p.network.config.NetworkConfig) SimplePeerSelectionStrategy(tech.pegasys.teku.network.p2p.peer.SimplePeerSelectionStrategy) PeerSelectionStrategy(tech.pegasys.teku.networking.p2p.connection.PeerSelectionStrategy) SimplePeerSelectionStrategy(tech.pegasys.teku.network.p2p.peer.SimplePeerSelectionStrategy) TargetPeerRange(tech.pegasys.teku.networking.p2p.connection.TargetPeerRange) MemKeyValueStore(tech.pegasys.teku.storage.store.MemKeyValueStore) Test(org.junit.jupiter.api.Test)

Aggregations

TargetPeerRange (tech.pegasys.teku.networking.p2p.connection.TargetPeerRange)2 NetworkConfig (tech.pegasys.teku.networking.p2p.network.config.NetworkConfig)2 Collections (java.util.Collections)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 Test (org.junit.jupiter.api.Test)1 SimplePeerSelectionStrategy (tech.pegasys.teku.network.p2p.peer.SimplePeerSelectionStrategy)1 AttestationSubnetTopicProvider (tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationSubnetTopicProvider)1 SyncCommitteeSubnetTopicProvider (tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubnetTopicProvider)1 Eth2GossipTopicFilter (tech.pegasys.teku.networking.eth2.gossip.topics.Eth2GossipTopicFilter)1 Eth2PeerSelectionStrategy (tech.pegasys.teku.networking.eth2.peers.Eth2PeerSelectionStrategy)1 PeerSelectionStrategy (tech.pegasys.teku.networking.p2p.connection.PeerSelectionStrategy)1 DiscoveryConfig (tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig)1 PreparedGossipMessageFactory (tech.pegasys.teku.networking.p2p.gossip.PreparedGossipMessageFactory)1 LibP2PPrivateKeyLoader (tech.pegasys.teku.networking.p2p.libp2p.LibP2PPrivateKeyLoader)1 GossipTopicFilter (tech.pegasys.teku.networking.p2p.libp2p.gossip.GossipTopicFilter)1 Peer (tech.pegasys.teku.networking.p2p.peer.Peer)1 ReputationManager (tech.pegasys.teku.networking.p2p.reputation.ReputationManager)1 SchemaDefinitionsSupplier (tech.pegasys.teku.spec.schemas.SchemaDefinitionsSupplier)1 MemKeyValueStore (tech.pegasys.teku.storage.store.MemKeyValueStore)1