use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method requestBlockBySlot_withDisparateVersionsEnabled_requestAltairBlocks.
@ParameterizedTest(name = "enableAltairLocally={0}, enableAltairRemotely={1}")
@MethodSource("altairVersioningOptions")
public void requestBlockBySlot_withDisparateVersionsEnabled_requestAltairBlocks(final boolean enableAltairLocally, final boolean enableAltairRemotely) throws Exception {
setupPeerStorage(true);
final Eth2Peer peer = createPeer(enableAltairLocally, enableAltairRemotely);
// Setup chain
peerStorage.chainUpdater().advanceChain(altairSlot.minus(1));
// Create altair blocks
final SignedBlockAndState block1 = peerStorage.chainUpdater().advanceChain();
final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
peerStorage.chainUpdater().updateBestBlock(block2);
assertThat(block1.getBlock().getMessage().getBody()).isInstanceOf(BeaconBlockBodyAltair.class);
assertThat(block2.getBlock().getMessage().getBody()).isInstanceOf(BeaconBlockBodyAltair.class);
peerStorage.chainUpdater().updateBestBlock(block2);
final List<SignedBeaconBlock> blocks = new ArrayList<>();
final SafeFuture<Void> res = peer.requestBlocksByRange(block1.getSlot(), UInt64.valueOf(2), UInt64.ONE, RpcResponseListener.from(blocks::add));
waitFor(() -> assertThat(res).isDone());
assertThat(peer.getOutstandingRequests()).isEqualTo(0);
if (enableAltairLocally && enableAltairRemotely) {
// We should receive a successful response
assertThat(res).isCompleted();
assertThat(blocks).containsExactly(block1.getBlock(), block2.getBlock());
} else if (!enableAltairLocally && enableAltairRemotely) {
// The peer should refuse to return any results because we're asking for altair blocks using
// a v1 request
assertThat(res).isCompletedExceptionally();
assertThatThrownBy(res::get).hasCauseInstanceOf(RpcException.class).hasMessageContaining("[Code 1] Must request altair blocks using v2 protocol");
} else {
// Remote only supports v1, we should get a v1 response back and error out trying to
// decode these blocks with a phase0 decoder
assertThat(res).isCompletedExceptionally();
assertThatThrownBy(res::get).hasCauseInstanceOf(DeserializationFailedException.class);
}
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method requestBlocksByRangeAfterPeerDisconnected.
@Test
public void requestBlocksByRangeAfterPeerDisconnected() throws Exception {
final Eth2Peer peer = createPeer();
// Setup chain
peerStorage.chainUpdater().advanceChain();
final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
peerStorage.chainUpdater().updateBestBlock(block2);
Waiter.waitFor(peer.disconnectCleanly(DisconnectReason.TOO_MANY_PEERS));
final List<SignedBeaconBlock> blocks = new ArrayList<>();
final SafeFuture<Void> res = peer.requestBlocksByRange(UInt64.ONE, UInt64.valueOf(10), UInt64.ONE, RpcResponseListener.from(blocks::add));
waitFor(() -> assertThat(res).isDone());
assertThat(res).isCompletedExceptionally();
assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
assertThat(blocks).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method requestBlocksByRangeAfterPeerDisconnectedImmediately.
@Test
public void requestBlocksByRangeAfterPeerDisconnectedImmediately() throws Exception {
final Eth2Peer peer = createPeer();
// Setup chain
peerStorage.chainUpdater().advanceChain();
final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
peerStorage.chainUpdater().updateBestBlock(block2);
peer.disconnectImmediately(Optional.empty(), false);
final List<SignedBeaconBlock> blocks = new ArrayList<>();
final SafeFuture<Void> res = peer.requestBlocksByRange(UInt64.ONE, UInt64.valueOf(10), UInt64.ONE, RpcResponseListener.from(blocks::add));
waitFor(() -> assertThat(res).isDone());
assertThat(res).isCompletedExceptionally();
assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
assertThat(blocks).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRootIntegrationTest method requestBlocksByRootAfterPeerDisconnectedImmediately.
@Test
public void requestBlocksByRootAfterPeerDisconnectedImmediately() throws RpcException {
final Eth2Peer peer = createPeer();
final SignedBeaconBlock block = addBlock();
final Bytes32 blockHash = block.getMessage().hashTreeRoot();
peer.disconnectImmediately(Optional.empty(), false);
final List<SignedBeaconBlock> blocks = new ArrayList<>();
final SafeFuture<Void> res = peer.requestBlocksByRoot(List.of(blockHash), RpcResponseListener.from(blocks::add));
waitFor(() -> assertThat(res).isDone());
assertThat(res).isCompletedExceptionally();
assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
assertThat(blocks).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRootIntegrationTest method shouldReturnMultipleLargeBlocksWhenAllRequestsMatch.
@Test
public void shouldReturnMultipleLargeBlocksWhenAllRequestsMatch() throws Exception {
final Eth2Peer peer = createPeer();
final List<SignedBeaconBlock> blocks = largeBlockSequence(3);
final List<Bytes32> blockRoots = blocks.stream().map(SignedBeaconBlock::getRoot).collect(toList());
final List<SignedBeaconBlock> response = requestBlocks(peer, blockRoots);
assertThat(response).containsExactlyElementsOf(blocks);
}
Aggregations