Search in sources :

Example 1 with SlotAndBlockRoot

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();
}
Also used : SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) BatchAssert.assertThatBatch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.BatchAssert.assertThatBatch) Batch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.Batch) Test(org.junit.jupiter.api.Test)

Example 2 with SlotAndBlockRoot

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);
}
Also used : SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) BatchAssert.assertThatBatch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.BatchAssert.assertThatBatch) Batch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.Batch) Test(org.junit.jupiter.api.Test)

Example 3 with SlotAndBlockRoot

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);
}
Also used : SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) BatchAssert.assertThatBatch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.BatchAssert.assertThatBatch) Batch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.Batch) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 4 with SlotAndBlockRoot

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);
}
Also used : SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) BatchAssert.assertThatBatch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.BatchAssert.assertThatBatch) Batch(tech.pegasys.teku.beacon.sync.forward.multipeer.batches.Batch) Test(org.junit.jupiter.api.Test)

Example 5 with SlotAndBlockRoot

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));
}
Also used : SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) Test(org.junit.jupiter.api.Test)

Aggregations

SlotAndBlockRoot (tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot)76 Test (org.junit.jupiter.api.Test)55 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)23 Bytes32 (org.apache.tuweni.bytes.Bytes32)13 Batch (tech.pegasys.teku.beacon.sync.forward.multipeer.batches.Batch)12 BatchAssert.assertThatBatch (tech.pegasys.teku.beacon.sync.forward.multipeer.batches.BatchAssert.assertThatBatch)12 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)10 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)10 TargetChain (tech.pegasys.teku.beacon.sync.forward.multipeer.chains.TargetChain)9 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)9 Optional (java.util.Optional)8 Spec (tech.pegasys.teku.spec.Spec)5 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)4 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)4 ArrayList (java.util.ArrayList)3 StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2