Search in sources :

Example 1 with RpcMethod

use of tech.pegasys.teku.networking.p2p.rpc.RpcMethod in project teku by ConsenSys.

the class PingIntegrationTest method testManualPingTimeout.

@Test
public void testManualPingTimeout() throws Exception {
    // sending PING manually to check eth2RpcOutstandingPingThreshold works correctly
    Duration pingPeriod = Duration.ofDays(1);
    network1 = networkFactory.builder().eth2RpcPingInterval(pingPeriod).eth2RpcOutstandingPingThreshold(2).rpcMethodsModifier(m -> Stream.of(m).filter(t -> t.getIds().stream().noneMatch(id -> id.contains("/ping"))).map(n -> ((RpcMethod<?, ?, ?>) n))).startNetwork();
    network2 = networkFactory.builder().eth2RpcPingInterval(pingPeriod).eth2RpcOutstandingPingThreshold(2).peer(network1).startNetwork();
    peer1 = network2.getPeer(network1.getNodeId()).orElseThrow();
    peer2 = network1.getPeer(network2.getNodeId()).orElseThrow();
    Eth2PeerManagerAccess.invokeSendPeriodicPing(getPeerManager(network2), peer1);
    assertThat(peer1.isConnected()).isTrue();
    Eth2PeerManagerAccess.invokeSendPeriodicPing(getPeerManager(network2), peer1);
    assertThat(peer1.isConnected()).isTrue();
    // the 3rd ping attempt should disconnect the peer since there are 2 unanswered PING requests
    Eth2PeerManagerAccess.invokeSendPeriodicPing(getPeerManager(network2), peer1);
    waitFor(() -> assertThat(peer1.isConnected()).isFalse());
}
Also used : SszBitvectorSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) RpcMethod(tech.pegasys.teku.networking.p2p.rpc.RpcMethod) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Stream(java.util.stream.Stream) Eth2PeerManagerAccess(tech.pegasys.teku.networking.eth2.peers.Eth2PeerManagerAccess) Waiter.waitFor(tech.pegasys.teku.infrastructure.async.Waiter.waitFor) Eth2PeerManager(tech.pegasys.teku.networking.eth2.peers.Eth2PeerManager) Duration(java.time.Duration) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Constants(tech.pegasys.teku.spec.config.Constants) MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Example 2 with RpcMethod

use of tech.pegasys.teku.networking.p2p.rpc.RpcMethod in project teku by ConsenSys.

the class Eth2P2PNetworkBuilder method build.

public Eth2P2PNetwork build() {
    validate();
    // Setup eth2 handlers
    final SubnetSubscriptionService attestationSubnetService = new SubnetSubscriptionService();
    final SubnetSubscriptionService syncCommitteeSubnetService = new SubnetSubscriptionService();
    final RpcEncoding rpcEncoding = RpcEncoding.createSszSnappyEncoding(spec.isMilestoneSupported(SpecMilestone.BELLATRIX) ? MAX_CHUNK_SIZE_BELLATRIX : MAX_CHUNK_SIZE);
    final Eth2PeerManager eth2PeerManager = Eth2PeerManager.create(asyncRunner, recentChainData, historicalChainData, metricsSystem, attestationSubnetService, syncCommitteeSubnetService, rpcEncoding, requiredCheckpoint, eth2RpcPingInterval, eth2RpcOutstandingPingThreshold, eth2StatusUpdateInterval, timeProvider, config.getPeerRateLimit(), config.getPeerRequestLimit(), spec);
    final Collection<RpcMethod<?, ?, ?>> eth2RpcMethods = eth2PeerManager.getBeaconChainMethods().all();
    rpcMethods.addAll(eth2RpcMethods);
    peerHandlers.add(eth2PeerManager);
    final GossipEncoding gossipEncoding = config.getGossipEncoding();
    // Build core network and inject eth2 handlers
    final DiscoveryNetwork<?> network = buildNetwork(gossipEncoding, syncCommitteeSubnetService);
    final GossipForkManager gossipForkManager = buildGossipForkManager(gossipEncoding, network);
    return new ActiveEth2P2PNetwork(config.getSpec(), asyncRunner, network, eth2PeerManager, gossipForkManager, eventChannels, recentChainData, attestationSubnetService, syncCommitteeSubnetService, gossipEncoding, config.getGossipConfigurator(), processedAttestationSubscriptionProvider);
}
Also used : GossipForkManager(tech.pegasys.teku.networking.eth2.gossip.forks.GossipForkManager) RpcMethod(tech.pegasys.teku.networking.p2p.rpc.RpcMethod) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) Eth2PeerManager(tech.pegasys.teku.networking.eth2.peers.Eth2PeerManager) RpcEncoding(tech.pegasys.teku.networking.eth2.rpc.core.encodings.RpcEncoding)

Aggregations

Eth2PeerManager (tech.pegasys.teku.networking.eth2.peers.Eth2PeerManager)2 RpcMethod (tech.pegasys.teku.networking.p2p.rpc.RpcMethod)2 Duration (java.time.Duration)1 List (java.util.List)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Test (org.junit.jupiter.api.Test)1 Waiter.waitFor (tech.pegasys.teku.infrastructure.async.Waiter.waitFor)1 SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)1 SszBitvectorSchema (tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 GossipEncoding (tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding)1 GossipForkManager (tech.pegasys.teku.networking.eth2.gossip.forks.GossipForkManager)1 Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)1 Eth2PeerManagerAccess (tech.pegasys.teku.networking.eth2.peers.Eth2PeerManagerAccess)1 RpcEncoding (tech.pegasys.teku.networking.eth2.rpc.core.encodings.RpcEncoding)1 Constants (tech.pegasys.teku.spec.config.Constants)1