use of tech.pegasys.teku.networking.eth2.peers.StubSyncSource in project teku by ConsenSys.
the class SyncSourceBatchTest method createBatch.
protected Batch createBatch(final long startSlot, final long count) {
final List<StubSyncSource> syncSources = new ArrayList<>();
final SyncSourceSelector syncSourceProvider = () -> {
final StubSyncSource source = new StubSyncSource();
syncSources.add(source);
return Optional.of(source);
};
final SyncSourceBatch batch = new SyncSourceBatch(eventThread, syncSourceProvider, conflictResolutionStrategy, targetChain, UInt64.valueOf(startSlot), UInt64.valueOf(count));
this.syncSources.put(batch, syncSources);
return batch;
}
use of tech.pegasys.teku.networking.eth2.peers.StubSyncSource in project teku by ConsenSys.
the class SyncSourceBatchTest method requestMoreBlocks_shouldResetAndSelectNewPeerAfterDisconnection.
@Test
void requestMoreBlocks_shouldResetAndSelectNewPeerAfterDisconnection() {
final Runnable callback = mock(Runnable.class);
final Batch batch = createBatch(70, 50);
batch.requestMoreBlocks(callback);
// First request returns some data, so the batch isn't in initial state
final StubSyncSource firstSyncSource = getSyncSource(batch);
firstSyncSource.receiveBlocks(dataStructureUtil.randomSignedBeaconBlock(72));
verify(callback).run();
batch.markFirstBlockConfirmed();
batch.markAsContested();
// Second request should go to the same source
batch.requestMoreBlocks(callback);
firstSyncSource.assertRequestedBlocks(73, 47);
assertThatBatch(batch).isNotEmpty();
// But this requests fails
firstSyncSource.failRequest(new PeerDisconnectedException());
// The request is complete, so should call the callback
verify(callback, times(2)).run();
// And the batch should be back in initial state
assertThatBatch(batch).isEmpty();
assertThatBatch(batch).isNotContested();
assertThatBatch(batch).hasUnconfirmedFirstBlock();
// Third request selects a new peer to request data from
batch.requestMoreBlocks(callback);
assertThat(syncSources.get(batch)).hasSize(2);
final StubSyncSource secondSyncSource = getSyncSource(batch);
assertThat(secondSyncSource).isNotSameAs(firstSyncSource);
secondSyncSource.assertRequestedBlocks(70, 50);
}
Aggregations