use of tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor 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));
}
use of tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor in project teku by ConsenSys.
the class VoluntaryExitGossipIntegrationTest method shouldGossipVoluntaryExitToPeers.
@Test
public void shouldGossipVoluntaryExitToPeers() throws Exception {
final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY;
final SpecConfig config = spec.getGenesisSpecConfig();
final UInt64 blockSlot = config.getShardCommitteePeriod().plus(2).times(config.getSlotsPerEpoch());
// Set up publishers & consumers
Set<SignedVoluntaryExit> receivedVoluntaryExits = new HashSet<>();
final OperationProcessor<SignedVoluntaryExit> operationProcessor = (voluntaryExit) -> {
receivedVoluntaryExits.add(voluntaryExit);
return SafeFuture.completedFuture(InternalValidationResult.ACCEPT);
};
// Setup network 1
final Consumer<Eth2P2PNetworkBuilder> networkBuilder = b -> b.gossipEncoding(gossipEncoding);
NodeManager node1 = createNodeManager(networkBuilder);
node1.chainUtil().setSlot(blockSlot);
// Setup network 2
final Consumer<Eth2P2PNetworkBuilder> networkBuilder2 = b -> b.gossipEncoding(gossipEncoding).gossipedVoluntaryExitProcessor(operationProcessor);
NodeManager node2 = createNodeManager(networkBuilder2);
node2.chainUtil().setSlot(blockSlot);
// 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 voluntary exit
final SignedBeaconBlock block = node1.chainUtil().createAndImportBlockAtSlot(blockSlot);
final SafeFuture<Optional<BeaconState>> stateFuture = node1.storageClient().getStore().retrieveBlockState(block.getRoot());
assertThat(stateFuture).isCompleted();
final BeaconState state = stateFuture.join().orElseThrow();
final VoluntaryExitGenerator exitGenerator = new VoluntaryExitGenerator(spec, node1.chainUtil().getValidatorKeys());
final SignedVoluntaryExit voluntaryExit = exitGenerator.valid(state, 0);
// Publish voluntary exit
node1.network().publishVoluntaryExit(voluntaryExit);
// Verify the expected exit was gossiped across the network
Waiter.waitFor(() -> assertThat(receivedVoluntaryExits).containsExactly(voluntaryExit));
}
use of tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor in project teku by ConsenSys.
the class AttesterSlashingGossipIntegrationTest method shouldGossipToPeers.
@Test
public void shouldGossipToPeers() throws Exception {
final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY;
// Set up publishers & consumers
Set<AttesterSlashing> receivedGossip = new HashSet<>();
final OperationProcessor<AttesterSlashing> 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).gossipedAttesterSlashingProcessor(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 AttesterSlashing slashing = dataStructureUtil.randomAttesterSlashing();
node1.network().publishAttesterSlashing(slashing);
// Verify the slashing was gossiped across the network
Waiter.waitFor(() -> {
assertThat(receivedGossip).containsExactly(slashing);
});
}
Aggregations