Search in sources :

Example 1 with DiscoveryConfig

use of tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig 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 DiscoveryConfig

use of tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig in project teku by ConsenSys.

the class P2POptionsTest method p2pDiscoveryEnabled_shouldNotRequireAValue.

@Test
public void p2pDiscoveryEnabled_shouldNotRequireAValue() {
    TekuConfiguration tekuConfiguration = getTekuConfigurationFromArguments("--p2p-discovery-enabled");
    final DiscoveryConfig config = tekuConfiguration.discovery();
    assertThat(config.isDiscoveryEnabled()).isTrue();
    assertThat(createConfigBuilder().discovery(b -> b.isDiscoveryEnabled(true)).build()).usingRecursiveComparison().isEqualTo(tekuConfiguration);
}
Also used : TekuConfiguration(tech.pegasys.teku.config.TekuConfiguration) DiscoveryConfig(tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Example 3 with DiscoveryConfig

use of tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig in project teku by ConsenSys.

the class P2POptionsTest method shouldReadFromConfigurationFile.

@Test
public void shouldReadFromConfigurationFile() {
    final TekuConfiguration tekuConfig = getTekuConfigurationFromFile("P2POptions_config.yaml");
    final P2PConfig p2pConfig = tekuConfig.p2p();
    assertThat(p2pConfig.getTargetSubnetSubscriberCount()).isEqualTo(5);
    final DiscoveryConfig discoConfig = tekuConfig.discovery();
    assertThat(discoConfig.isDiscoveryEnabled()).isTrue();
    assertThat(discoConfig.getMinPeers()).isEqualTo(70);
    assertThat(discoConfig.getMaxPeers()).isEqualTo(85);
    assertThat(discoConfig.getMinRandomlySelectedPeers()).isEqualTo(1);
    assertThat(discoConfig.getStaticPeers()).isEqualTo(List.of("127.1.0.1", "127.1.1.1"));
    final NetworkConfig networkConfig = tekuConfig.network();
    assertThat(networkConfig.isEnabled()).isTrue();
    assertThat(networkConfig.getAdvertisedIp()).isEqualTo("127.200.0.1");
    assertThat(networkConfig.getNetworkInterface()).isEqualTo("127.100.0.1");
    assertThat(networkConfig.getListenPort()).isEqualTo(4321);
    assertThat(networkConfig.getPrivateKeySource()).containsInstanceOf(FilePrivateKeySource.class);
    assertThat(((FilePrivateKeySource) networkConfig.getPrivateKeySource().get()).getFileName()).isEqualTo("/the/file");
}
Also used : P2PConfig(tech.pegasys.teku.networking.eth2.P2PConfig) TekuConfiguration(tech.pegasys.teku.config.TekuConfiguration) NetworkConfig(tech.pegasys.teku.networking.p2p.network.config.NetworkConfig) DiscoveryConfig(tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig) FilePrivateKeySource(tech.pegasys.teku.networking.p2p.network.config.NetworkConfig.FilePrivateKeySource) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Example 4 with DiscoveryConfig

use of tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig in project teku by ConsenSys.

the class BeaconChainController method initP2PNetwork.

protected void initP2PNetwork() {
    LOG.debug("BeaconChainController.initP2PNetwork()");
    if (!beaconConfig.p2pConfig().getNetworkConfig().isEnabled()) {
        this.p2pNetwork = new NoOpEth2P2PNetwork(spec);
        return;
    }
    DiscoveryConfig discoveryConfig = beaconConfig.p2pConfig().getDiscoveryConfig();
    final Optional<Integer> maybeUdpPort = discoveryConfig.isDiscoveryEnabled() ? Optional.of(discoveryConfig.getListenUdpPort()) : Optional.empty();
    PortAvailability.checkPortsAvailable(beaconConfig.p2pConfig().getNetworkConfig().getListenPort(), maybeUdpPort);
    final KeyValueStore<String, Bytes> keyValueStore = new FileKeyValueStore(beaconDataDirectory.resolve(KEY_VALUE_STORE_SUBDIRECTORY));
    this.p2pNetwork = createEth2P2PNetworkBuilder().config(beaconConfig.p2pConfig()).eventChannels(eventChannels).recentChainData(recentChainData).gossipedBlockProcessor(blockManager::validateAndImportBlock).gossipedAttestationProcessor(attestationManager::addAttestation).gossipedAggregateProcessor(attestationManager::addAggregate).gossipedAttesterSlashingProcessor(attesterSlashingPool::add).gossipedProposerSlashingProcessor(proposerSlashingPool::add).gossipedVoluntaryExitProcessor(voluntaryExitPool::add).gossipedSignedContributionAndProofProcessor(syncCommitteeContributionPool::add).gossipedSyncCommitteeMessageProcessor(syncCommitteeMessagePool::add).processedAttestationSubscriptionProvider(attestationManager::subscribeToAttestationsToSend).historicalChainData(eventChannels.getPublisher(StorageQueryChannel.class, beaconAsyncRunner)).metricsSystem(metricsSystem).timeProvider(timeProvider).asyncRunner(networkAsyncRunner).keyValueStore(keyValueStore).requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()).specProvider(spec).build();
    syncCommitteeMessagePool.subscribeOperationAdded(new OperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeMessage));
    syncCommitteeContributionPool.subscribeOperationAdded(new OperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeContribution));
    proposerSlashingPool.subscribeOperationAdded(new OperationAcceptedFilter<>(p2pNetwork::publishProposerSlashing));
    attesterSlashingPool.subscribeOperationAdded(new OperationAcceptedFilter<>(p2pNetwork::publishAttesterSlashing));
    voluntaryExitPool.subscribeOperationAdded(new OperationAcceptedFilter<>(p2pNetwork::publishVoluntaryExit));
}
Also used : FileKeyValueStore(tech.pegasys.teku.storage.store.FileKeyValueStore) Bytes(org.apache.tuweni.bytes.Bytes) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) NoOpEth2P2PNetwork(tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork) DiscoveryConfig(tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig)

Aggregations

DiscoveryConfig (tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig)4 Test (org.junit.jupiter.api.Test)2 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)2 TekuConfiguration (tech.pegasys.teku.config.TekuConfiguration)2 NetworkConfig (tech.pegasys.teku.networking.p2p.network.config.NetworkConfig)2 Collections (java.util.Collections)1 Bytes (org.apache.tuweni.bytes.Bytes)1 P2PConfig (tech.pegasys.teku.networking.eth2.P2PConfig)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 NoOpEth2P2PNetwork (tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork)1 Eth2PeerSelectionStrategy (tech.pegasys.teku.networking.eth2.peers.Eth2PeerSelectionStrategy)1 TargetPeerRange (tech.pegasys.teku.networking.p2p.connection.TargetPeerRange)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 FilePrivateKeySource (tech.pegasys.teku.networking.p2p.network.config.NetworkConfig.FilePrivateKeySource)1 Peer (tech.pegasys.teku.networking.p2p.peer.Peer)1 ReputationManager (tech.pegasys.teku.networking.p2p.reputation.ReputationManager)1