Search in sources :

Example 1 with Eth2P2PNetworkBuilder

use of tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder in project teku by ConsenSys.

the class TekuConfigurationTest method beaconChainControllerFactory_useCustomFactories.

@Test
void beaconChainControllerFactory_useCustomFactories() {
    AtomicBoolean customDiscoveryBuilderMethodCalled = new AtomicBoolean();
    AtomicBoolean customLibP2PBuilderMethodCalled = new AtomicBoolean();
    AtomicBoolean customGossipNetworkBuilderCalled = new AtomicBoolean();
    DiscoveryNetworkBuilder customDiscoveryNetworkBuilder = new DiscoveryNetworkBuilder() {

        @Override
        public DiscoveryNetwork<?> build() {
            customDiscoveryBuilderMethodCalled.set(true);
            return super.build();
        }
    };
    LibP2PGossipNetworkBuilder customGossipNetworkBuilder = new LibP2PGossipNetworkBuilder() {

        @Override
        public LibP2PGossipNetwork build() {
            customGossipNetworkBuilderCalled.set(true);
            return super.build();
        }
    };
    LibP2PNetworkBuilder customLibP2PNetworkBuilder = new LibP2PNetworkBuilder() {

        @Override
        public P2PNetwork<Peer> build() {
            customLibP2PBuilderMethodCalled.set(true);
            return super.build();
        }

        @Override
        protected LibP2PGossipNetworkBuilder createLibP2PGossipNetworkBuilder() {
            return customGossipNetworkBuilder;
        }
    };
    Eth2P2PNetworkBuilder customEth2P2PNetworkBuilder = new Eth2P2PNetworkBuilder() {

        @Override
        protected DiscoveryNetworkBuilder createDiscoveryNetworkBuilder() {
            return customDiscoveryNetworkBuilder;
        }

        @Override
        protected LibP2PNetworkBuilder createLibP2PNetworkBuilder() {
            return customLibP2PNetworkBuilder;
        }
    };
    BeaconChainControllerFactory customControllerFactory = (serviceConfig, beaconConfig) -> new BeaconChainController(serviceConfig, beaconConfig) {

        @Override
        protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() {
            return customEth2P2PNetworkBuilder;
        }
    };
    TekuConfiguration tekuConfiguration = TekuConfiguration.builder().data(b -> b.dataBasePath(tempDir)).beaconChainControllerFactory(customControllerFactory).build();
    try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) {
        assertThat(beaconNode).isNotNull();
        assertThat(customDiscoveryBuilderMethodCalled).isTrue();
        assertThat(customLibP2PBuilderMethodCalled).isTrue();
        assertThat(customGossipNetworkBuilderCalled).isTrue();
    }
}
Also used : TempDirUtils(tech.pegasys.teku.cli.TempDirUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoveryNetwork(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetwork) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryNetworkBuilder(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetworkBuilder) LibP2PNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNetworkBuilder) BeaconChainController(tech.pegasys.teku.services.beaconchain.BeaconChainController) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) BeaconChainControllerFactory(tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory) LibP2PGossipNetwork(tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetwork) P2PNetwork(tech.pegasys.teku.networking.p2p.network.P2PNetwork) LibP2PGossipNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder) BeaconNodeFacade(tech.pegasys.teku.BeaconNodeFacade) TekuFacade(tech.pegasys.teku.TekuFacade) Path(java.nio.file.Path) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryNetworkBuilder(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetworkBuilder) BeaconChainControllerFactory(tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder) LibP2PGossipNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) BeaconChainController(tech.pegasys.teku.services.beaconchain.BeaconChainController) BeaconNodeFacade(tech.pegasys.teku.BeaconNodeFacade) LibP2PNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNetworkBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with Eth2P2PNetworkBuilder

use of tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder in project teku by ConsenSys.

the class GossipMessageHandlerIntegrationTest method shouldNotGossipAttestationsWhenPeerDeregistersFromTopic.

@Test
public void shouldNotGossipAttestationsWhenPeerDeregistersFromTopic() throws Exception {
    final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY;
    List<ValidateableAttestation> node2attestations = new ArrayList<>();
    Subscribers<ProcessedAttestationListener> processedAttestationSubscribers = Subscribers.create(false);
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder1 = b -> {
        b.gossipEncoding(gossipEncoding);
        b.gossipedAttestationProcessor((__) -> SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
        b.processedAttestationSubscriptionProvider(processedAttestationSubscribers::subscribe);
    };
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder2 = b -> {
        b.gossipEncoding(gossipEncoding);
        b.gossipedAttestationProcessor((attestation) -> {
            node2attestations.add(attestation);
            return SafeFuture.completedFuture(InternalValidationResult.ACCEPT);
        });
    };
    // Setup network 1
    final NodeManager node1 = createNodeManager(networkBuilder1);
    final Eth2P2PNetwork network1 = node1.network();
    // Setup network 2
    final NodeManager node2 = createNodeManager(networkBuilder2);
    final Eth2P2PNetwork network2 = node2.network();
    // Connect networks 1 -> 2
    waitFor(node1.connect(node2));
    // Wait for connections to get set up
    Waiter.waitFor(() -> {
        assertThat(network1.getPeerCount()).isEqualTo(1);
        assertThat(network2.getPeerCount()).isEqualTo(1);
    });
    // Propagate attestation from network 1
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary bestBlockAndState = getChainHead(node1);
    Attestation attestation = attestationGenerator.validAttestation(bestBlockAndState);
    final int subnetId = spec.computeSubnetForAttestation(bestBlockAndState.getState(), attestation);
    ValidateableAttestation validAttestation = ValidateableAttestation.fromNetwork(spec, attestation, subnetId);
    node1.network().subscribeToAttestationSubnetId(subnetId);
    node2.network().subscribeToAttestationSubnetId(subnetId);
    waitForTopicRegistration();
    processedAttestationSubscribers.forEach(s -> s.accept(validAttestation));
    waitForMessageToBeDelivered();
    assertThat(node2attestations.size()).isEqualTo(1);
    assertThat(node2attestations.get(0)).isEqualTo(validAttestation);
    node1.network().unsubscribeFromAttestationSubnetId(subnetId);
    node2.network().unsubscribeFromAttestationSubnetId(subnetId);
    waitForTopicDeregistration();
    processedAttestationSubscribers.forEach(s -> s.accept(validAttestation));
    ensureConditionRemainsMet(() -> {
        assertThat(node2attestations.size()).isEqualTo(1);
        assertThat(node2attestations.get(0)).isEqualTo(validAttestation);
    });
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Subscribers(tech.pegasys.teku.infrastructure.subscribers.Subscribers) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) ProcessedAttestationListener(tech.pegasys.teku.spec.datastructures.attestation.ProcessedAttestationListener) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Waiter.ensureConditionRemainsMet(tech.pegasys.teku.infrastructure.async.Waiter.ensureConditionRemainsMet) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) Set(java.util.Set) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Waiter.waitFor(tech.pegasys.teku.infrastructure.async.Waiter.waitFor) Waiter(tech.pegasys.teku.infrastructure.async.Waiter) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) BLSKeyGenerator(tech.pegasys.teku.bls.BLSKeyGenerator) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SafeFutureAssert.safeJoin(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.safeJoin) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) ArrayList(java.util.ArrayList) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ProcessedAttestationListener(tech.pegasys.teku.spec.datastructures.attestation.ProcessedAttestationListener) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Test(org.junit.jupiter.api.Test)

Example 3 with Eth2P2PNetworkBuilder

use of tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder in project teku by ConsenSys.

the class GossipMessageHandlerIntegrationTest method shouldNotGossipAttestationsAcrossPeersThatAreNotOnTheSameSubnet.

@Test
public void shouldNotGossipAttestationsAcrossPeersThatAreNotOnTheSameSubnet() throws Exception {
    final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY;
    List<ValidateableAttestation> node2attestations = new ArrayList<>();
    Subscribers<ProcessedAttestationListener> processedAttestationSubscribers = Subscribers.create(false);
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder1 = b -> {
        b.gossipEncoding(gossipEncoding);
        b.processedAttestationSubscriptionProvider(processedAttestationSubscribers::subscribe);
    };
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder2 = b -> {
        b.gossipEncoding(gossipEncoding);
        b.gossipedAttestationProcessor((attestation) -> {
            node2attestations.add(attestation);
            return SafeFuture.completedFuture(InternalValidationResult.ACCEPT);
        });
    };
    // Setup network 1
    final NodeManager node1 = createNodeManager(networkBuilder1);
    final Eth2P2PNetwork network1 = node1.network();
    // Setup network 2
    final NodeManager node2 = createNodeManager(networkBuilder2);
    final Eth2P2PNetwork network2 = node2.network();
    // Connect networks 1 -> 2
    waitFor(node1.connect(node2));
    // Wait for connections to get set up
    Waiter.waitFor(() -> {
        assertThat(network1.getPeerCount()).isEqualTo(1);
        assertThat(network2.getPeerCount()).isEqualTo(1);
    });
    // Propagate attestation from network 1
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary bestBlockAndState = getChainHead(node1);
    Attestation validAttestation = attestationGenerator.validAttestation(bestBlockAndState);
    processedAttestationSubscribers.forEach(s -> s.accept(ValidateableAttestation.from(spec, validAttestation)));
    ensureConditionRemainsMet(() -> assertThat(node2attestations).isEmpty());
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Subscribers(tech.pegasys.teku.infrastructure.subscribers.Subscribers) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) ProcessedAttestationListener(tech.pegasys.teku.spec.datastructures.attestation.ProcessedAttestationListener) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Waiter.ensureConditionRemainsMet(tech.pegasys.teku.infrastructure.async.Waiter.ensureConditionRemainsMet) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) Set(java.util.Set) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Waiter.waitFor(tech.pegasys.teku.infrastructure.async.Waiter.waitFor) Waiter(tech.pegasys.teku.infrastructure.async.Waiter) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) BLSKeyGenerator(tech.pegasys.teku.bls.BLSKeyGenerator) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SafeFutureAssert.safeJoin(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.safeJoin) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) ArrayList(java.util.ArrayList) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ProcessedAttestationListener(tech.pegasys.teku.spec.datastructures.attestation.ProcessedAttestationListener) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Test(org.junit.jupiter.api.Test)

Example 4 with Eth2P2PNetworkBuilder

use of tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder in project teku by ConsenSys.

the class SyncingNodeManager method create.

@SuppressWarnings("FutureReturnValueIgnored")
public static SyncingNodeManager create(final AsyncRunner asyncRunner, Eth2P2PNetworkFactory networkFactory, final List<BLSKeyPair> validatorKeys, Consumer<Eth2P2PNetworkBuilder> configureNetwork) throws Exception {
    final Spec spec = TestSpecFactory.createMinimalPhase0();
    final EventChannels eventChannels = EventChannels.createSyncChannels(TEST_EXCEPTION_HANDLER, new NoOpMetricsSystem());
    final RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
    final BeaconChainUtil chainUtil = BeaconChainUtil.create(spec, recentChainData, validatorKeys);
    chainUtil.initializeStorage();
    final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
    ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
    BlockImporter blockImporter = new BlockImporter(spec, eventChannels.getPublisher(BlockImportNotifications.class), recentChainData, forkChoice, WeakSubjectivityFactory.lenientValidator(), new StubExecutionEngineChannel(spec));
    BlockValidator blockValidator = new BlockValidator(spec, recentChainData);
    final PendingPool<SignedBeaconBlock> pendingBlocks = PendingPool.createForBlocks(spec);
    final FutureItems<SignedBeaconBlock> futureBlocks = FutureItems.create(SignedBeaconBlock::getSlot);
    BlockManager blockManager = new BlockManager(recentChainData, blockImporter, pendingBlocks, futureBlocks, blockValidator);
    eventChannels.subscribe(SlotEventsChannel.class, blockManager).subscribe(BlockImportChannel.class, blockManager).subscribe(BlockImportNotifications.class, blockManager).subscribe(FinalizedCheckpointChannel.class, pendingBlocks);
    final Eth2P2PNetworkBuilder networkBuilder = networkFactory.builder().spec(spec).eventChannels(eventChannels).recentChainData(recentChainData).gossipedBlockProcessor(blockManager::validateAndImportBlock);
    configureNetwork.accept(networkBuilder);
    final Eth2P2PNetwork eth2P2PNetwork = networkBuilder.startNetwork();
    SyncManager syncManager = SyncManager.create(asyncRunner, eth2P2PNetwork, recentChainData, blockImporter, new NoOpMetricsSystem(), spec);
    ForwardSyncService syncService = new SinglePeerSyncService(syncManager, recentChainData);
    final FetchRecentBlocksService recentBlockFetcher = FetchRecentBlocksService.create(asyncRunner, eth2P2PNetwork, pendingBlocks, syncService);
    recentBlockFetcher.subscribeBlockFetched(blockManager::importBlock);
    blockManager.subscribeToReceivedBlocks((block, executionOptimistic) -> recentBlockFetcher.cancelRecentBlockRequest(block.getRoot()));
    recentBlockFetcher.start().join();
    blockManager.start().join();
    syncService.start().join();
    return new SyncingNodeManager(eventChannels, recentChainData, chainUtil, eth2P2PNetwork, syncService);
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) SlotEventsChannel(tech.pegasys.teku.ethereum.events.SlotEventsChannel) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) BlockValidator(tech.pegasys.teku.statetransition.validation.BlockValidator) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) FetchRecentBlocksService(tech.pegasys.teku.beacon.sync.gossip.FetchRecentBlocksService) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) SinglePeerSyncService(tech.pegasys.teku.beacon.sync.forward.singlepeer.SinglePeerSyncService) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) SyncManager(tech.pegasys.teku.beacon.sync.forward.singlepeer.SyncManager) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ForwardSyncService(tech.pegasys.teku.beacon.sync.forward.ForwardSyncService) BlockManager(tech.pegasys.teku.statetransition.block.BlockManager) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) Spec(tech.pegasys.teku.spec.Spec) Eth2P2PNetwork(tech.pegasys.teku.networking.eth2.Eth2P2PNetwork)

Example 5 with Eth2P2PNetworkBuilder

use of tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder in project teku by ConsenSys.

the class ProposerSlashingGossipIntegrationTest method shouldGossipToPeers.

@Test
public void shouldGossipToPeers() throws Exception {
    final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY;
    // Set up publishers & consumers
    Set<ProposerSlashing> receivedGossip = new HashSet<>();
    final OperationProcessor<ProposerSlashing> operationProcessor = (slashing) -> {
        receivedGossip.add(slashing);
        return SafeFuture.completedFuture(InternalValidationResult.ACCEPT);
    };
    // Setup network 1
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder = b -> b.gossipEncoding(gossipEncoding);
    NodeManager node1 = createNodeManager(networkBuilder);
    // Setup network 2
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder2 = b -> b.gossipEncoding(gossipEncoding).gossipedProposerSlashingProcessor(operationProcessor);
    NodeManager node2 = createNodeManager(networkBuilder2);
    // Connect networks 1 -> 2
    waitFor(node1.connect(node2));
    // Wait for connections to get set up
    Waiter.waitFor(() -> {
        assertThat(node1.network().getPeerCount()).isEqualTo(1);
        assertThat(node2.network().getPeerCount()).isEqualTo(1);
    });
    // Wait for subscriptions to complete (jvm-libp2p does this asynchronously)
    Thread.sleep(2000);
    // Create and publish slashing
    final ProposerSlashing slashing = dataStructureUtil.randomProposerSlashing();
    node1.network().publishProposerSlashing(slashing);
    // Verify the slashing was gossiped across the network
    Waiter.waitFor(() -> assertThat(receivedGossip).containsExactly(slashing));
}
Also used : Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationProcessor(tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor) Set(java.util.Set) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Waiter.waitFor(tech.pegasys.teku.infrastructure.async.Waiter.waitFor) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) Waiter(tech.pegasys.teku.infrastructure.async.Waiter) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Spec(tech.pegasys.teku.spec.Spec) BLSKeyGenerator(tech.pegasys.teku.bls.BLSKeyGenerator) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Eth2P2PNetworkBuilder (tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 AfterEach (org.junit.jupiter.api.AfterEach)8 Test (org.junit.jupiter.api.Test)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Set (java.util.Set)7 Consumer (java.util.function.Consumer)7 BLSKeyGenerator (tech.pegasys.teku.bls.BLSKeyGenerator)7 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)7 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)7 Waiter (tech.pegasys.teku.infrastructure.async.Waiter)7 Waiter.waitFor (tech.pegasys.teku.infrastructure.async.Waiter.waitFor)7 GossipEncoding (tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding)7 Spec (tech.pegasys.teku.spec.Spec)7 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)7 TestSpecFactory (tech.pegasys.teku.spec.TestSpecFactory)6 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 ArrayList (java.util.ArrayList)4