use of tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot in project teku by ConsenSys.
the class BatchSyncTest method shouldRestartSyncFromCommonAncestorWhenNewChainShorterThanCurrentBatches.
@Test
void shouldRestartSyncFromCommonAncestorWhenNewChainShorterThanCurrentBatches() {
// Start sync to first chain
final SafeFuture<SyncResult> firstSyncResult = sync.syncToChain(targetChain);
assertThat(batches).hasSize(5);
final Batch batch0 = batches.get(0);
final Batch batch4 = batches.get(4);
batches.clearBatchList();
targetChain = chainWith(new SlotAndBlockRoot(batch4.getLastSlot().minus(2), dataStructureUtil.randomBytes32()), syncSource);
final SafeFuture<SyncResult> secondSyncResult = sync.syncToChain(targetChain);
assertThat(firstSyncResult).isCompletedWithValue(SyncResult.TARGET_CHANGED);
// There's no way the new chain extends the previous one so it should start from scratch
assertThat(batches).hasSize(5);
assertThat(batches.get(0)).isNotEqualTo(batch0);
assertThat(secondSyncResult).isNotDone();
}
use of tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot in project teku by ConsenSys.
the class BatchSyncTest method shouldContestBatchesWhenLastBlockDoesNotMatchTargetAndHasOnlyEmptyBatchesAfterIt.
@Test
void shouldContestBatchesWhenLastBlockDoesNotMatchTargetAndHasOnlyEmptyBatchesAfterIt() {
targetChain = chainWith(new SlotAndBlockRoot(BATCH_SIZE.times(2).minus(1), dataStructureUtil.randomBytes32()), syncSource);
assertThat(sync.syncToChain(targetChain)).isNotDone();
final Batch batch0 = batches.get(0);
final Batch batch1 = batches.get(1);
assertThatBatch(batch1).hasLastSlot(targetChain.getChainHead().getSlot());
// The last block we get doesn't match the target root, but then
batches.receiveBlocks(batch0, chainBuilder.generateBlockAtSlot(batch0.getLastSlot()).getBlock());
batches.receiveBlocks(batch1);
// We now have all the blocks but something doesn't match up so either the last block is wrong
// or the following empty batch shouldn't have been empty.
batches.assertMarkedContested(batch0);
batches.assertMarkedContested(batch1);
}
use of tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot in project teku by ConsenSys.
the class BatchSyncTest method shouldMarkBatchInvalidWhenSlotIsTargetHeadSlotAndRootDoesNotMatch.
@Test
void shouldMarkBatchInvalidWhenSlotIsTargetHeadSlotAndRootDoesNotMatch() {
final UInt64 lastSlot = UInt64.valueOf(2);
targetChain = chainWith(new SlotAndBlockRoot(lastSlot, dataStructureUtil.randomBytes32()), syncSource);
assertThat(sync.syncToChain(targetChain)).isNotDone();
final Batch batch0 = batches.get(0);
assertThatBatch(batch0).hasLastSlot(lastSlot);
// We get a block in the last slot which doesn't match the target root
// (it does match the starting point though)
batches.receiveBlocks(batch0, chainBuilder.generateBlockAtSlot(lastSlot).getBlock());
// So the batch must be invalid
batches.assertMarkedInvalid(batch0);
}
use of tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot in project teku by ConsenSys.
the class BatchSyncTest method shouldContestAllBatchesWhenEndSlotIsReachedWithNoBlocksReceived.
@Test
void shouldContestAllBatchesWhenEndSlotIsReachedWithNoBlocksReceived() {
targetChain = chainWith(new SlotAndBlockRoot(BATCH_SIZE.times(2).minus(1), dataStructureUtil.randomBytes32()), syncSource);
assertThat(sync.syncToChain(targetChain)).isNotDone();
assertThat(batches).hasSize(2);
final Batch batch0 = batches.get(0);
final Batch batch1 = batches.get(1);
assertThatBatch(batch1).hasLastSlot(targetChain.getChainHead().getSlot());
// The last block we get doesn't match the target root, but then
batches.receiveBlocks(batch0);
batches.receiveBlocks(batch1);
batches.assertMarkedContested(batch0);
batches.assertMarkedContested(batch1);
}
use of tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot in project teku by ConsenSys.
the class TargetChainsTest method onPeerStatus_shouldAddPeerToExistingChain.
@Test
void onPeerStatus_shouldAddPeerToExistingChain() {
final SlotAndBlockRoot chainHead = dataStructureUtil.randomSlotAndBlockRoot();
targetChains.onPeerStatusUpdated(peer1, chainHead);
targetChains.onPeerStatusUpdated(peer2, chainHead);
assertTargetChains(chainWith(chainHead, peer1, peer2));
}
Aggregations