use of tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer in project teku by ConsenSys.
the class HistoricalBlockSyncServiceTest method shouldRetrieveGenesisWhenMissing.
@Test
public void shouldRetrieveGenesisWhenMissing() {
currentSyncState.set(SyncState.IN_SYNC);
// Setup chain
final int epochHeight = 10;
final SignedBlockAndState genesis = storageSystem.chainBuilder().generateGenesis();
storageSystem.chainBuilder().generateBlocksUpToSlot(6);
initializeChainAtEpoch(UInt64.ZERO);
final List<SignedBeaconBlock> expectedBlocks = List.of(genesis.getBlock());
// Set up a peer to respond
final RespondingEth2Peer peer = RespondingEth2Peer.create(spec, storageSystem.chainBuilder());
peer.updateStatus(new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO), new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO));
when(network.streamPeers()).thenAnswer(i -> Stream.of(peer));
startService();
// We should start sending requests to pull data
assertThat(peer.getOutstandingRequests()).isEqualTo(1);
finishSyncing(peer, expectedBlocks);
}
use of tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer in project teku by ConsenSys.
the class HistoricalBlockSyncServiceTest method shouldOnlySendOneRequestAtATime.
@Test
public void shouldOnlySendOneRequestAtATime() {
currentSyncState.set(SyncState.IN_SYNC);
// Setup chain
final long epochHeight = 10;
storageSystem.chainBuilder().generateGenesis();
storageSystem.chainBuilder().generateBlocksUpToSlot(slotsPerEpoch * epochHeight + 3);
final AnchorPoint anchor = initializeChainAtEpoch(storageSystem.chainBuilder().getLatestEpoch());
final List<SignedBeaconBlock> expectedBlocks = storageSystem.chainBuilder().streamBlocksAndStates(0, anchor.getBlockSlot().longValue()).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
// Set up a peer to respond
final RespondingEth2Peer peer = RespondingEth2Peer.create(spec, storageSystem.chainBuilder());
peer.updateStatus(new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO), new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO));
when(network.streamPeers()).thenAnswer(i -> Stream.of(peer));
startService();
final int maxRequests = storageSystem.chainBuilder().getLatestSlot().dividedBy(batchSize).plus(1).intValue();
int requestCount = 0;
while (service.isRunning() && requestCount <= maxRequests) {
// Trigger some sync events
updateSyncState(SyncState.SYNCING);
updateSyncState(SyncState.IN_SYNC);
// Peer should only have 1 outstanding request
assertThat(peer.getOutstandingRequests()).isEqualTo(1);
assertThat(asyncRunner.countDelayedActions()).isEqualTo(0);
peer.completePendingRequests();
requestCount++;
}
assertServiceFinished();
assertBlocksSaved(expectedBlocks);
}
use of tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer in project teku by ConsenSys.
the class HistoricalBlockSyncServiceTest method assertServiceNotActive.
private void assertServiceNotActive(final RespondingEth2Peer... peers) {
assertThat(service.isRunning()).isTrue();
assertThat(syncStateSubscribers.getSubscriberCount()).isEqualTo(1);
for (RespondingEth2Peer peer : peers) {
assertThat(peer.getOutstandingRequests()).isEqualTo(0);
}
assertThat(asyncRunner.countDelayedActions()).isEqualTo(0);
}
use of tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer in project teku by ConsenSys.
the class HistoricalBlockSyncServiceTest method shouldWaitToRunTillNodeIsInSync.
@Test
public void shouldWaitToRunTillNodeIsInSync() {
currentSyncState.set(SyncState.SYNCING);
// Setup chain
final long epochHeight = 10;
storageSystem.chainBuilder().generateGenesis();
storageSystem.chainBuilder().generateBlocksUpToSlot(slotsPerEpoch * epochHeight + 3);
final AnchorPoint anchor = initializeChainAtEpoch(storageSystem.chainBuilder().getLatestEpoch());
final List<SignedBeaconBlock> expectedBlocks = storageSystem.chainBuilder().streamBlocksAndStates(0, anchor.getBlockSlot().longValue()).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
// Set up a peer to respond
final RespondingEth2Peer peer = RespondingEth2Peer.create(spec, storageSystem.chainBuilder());
peer.updateStatus(new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO), new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO));
when(network.streamPeers()).thenAnswer(i -> Stream.of(peer));
startService();
// We should be waiting to actually start the historic sync
assertServiceNotActive(peer);
verify(storageUpdateChannel, never()).onFinalizedBlocks(any());
// When we switch to in sync, the service should run and complete
updateSyncState(SyncState.IN_SYNC);
// We should start sending requests to pull data
assertThat(peer.getOutstandingRequests()).isEqualTo(1);
finishSyncing(peer, expectedBlocks);
}
use of tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer in project teku by ConsenSys.
the class HistoricalBlockSyncServiceTest method assertServiceIsWaitingForPeers.
private void assertServiceIsWaitingForPeers(final RespondingEth2Peer... peers) {
assertThat(service.isRunning()).isTrue();
assertThat(syncStateSubscribers.getSubscriberCount()).isEqualTo(1);
for (RespondingEth2Peer peer : peers) {
assertThat(peer.getOutstandingRequests()).isEqualTo(0);
}
assertThat(asyncRunner.countDelayedActions()).isEqualTo(1);
}
Aggregations