Search in sources :

Example 1 with HeadEvent

use of tech.pegasys.teku.storage.api.TrackingChainHeadChannel.HeadEvent in project teku by ConsenSys.

the class RecentChainDataTest method updateHead_calculateDependentRootCorrectly.

@Test
public void updateHead_calculateDependentRootCorrectly() {
    initPostGenesis();
    recentChainData.getStore().getForkChoiceStrategy().setPruneThreshold(0);
    storageSystem.chainUpdater().finalizeCurrentChain();
    final List<HeadEvent> headEvents = storageSystem.chainHeadChannel().getHeadEvents();
    assertThat(headEvents).isNotEmpty();
    headEvents.forEach(this::verifyDependentRoots);
    headEvents.clear();
    assertProtoArrayHasNoFinalizedBlocks();
    final SignedBlockAndState latestBlockAndState = storageSystem.chainUpdater().advanceChain();
    recentChainData.updateHead(latestBlockAndState.getRoot(), latestBlockAndState.getSlot());
    assertThat(headEvents).hasSize(1);
    verifyDependentRoots(headEvents.get(0));
    // Head reverts to the justified checkpoint (really is possible though quirky)
    final SignedBeaconBlock justifiedBlock = chainBuilder.getBlock(recentChainData.getJustifiedCheckpoint().orElseThrow().getRoot()).orElseThrow();
    recentChainData.updateHead(justifiedBlock.getRoot(), justifiedBlock.getSlot());
    assertThat(headEvents).hasSize(2);
    verifyDependentRoots(headEvents.get(1));
}
Also used : HeadEvent(tech.pegasys.teku.storage.api.TrackingChainHeadChannel.HeadEvent) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Test(org.junit.jupiter.api.Test)

Example 2 with HeadEvent

use of tech.pegasys.teku.storage.api.TrackingChainHeadChannel.HeadEvent in project teku by ConsenSys.

the class RecentChainDataTest method updateHead_validUpdate.

@Test
public void updateHead_validUpdate() {
    initPostGenesis();
    // Ensure the current and previous target root blocks are different
    chainBuilder.generateBlockAtSlot(genesisSpecConfig.getSlotsPerEpoch() - 1);
    chainBuilder.generateBlockAtSlot(genesisSpecConfig.getSlotsPerEpoch() * 2L - 1);
    final SignedBlockAndState bestBlock = chainBuilder.generateNextBlock();
    chainBuilder.streamBlocksAndStates().forEach(blockAndState -> saveBlock(recentChainData, blockAndState));
    recentChainData.updateHead(bestBlock.getRoot(), bestBlock.getSlot());
    assertThat(recentChainData.getChainHead().map(MinimalBeaconBlockSummary::getRoot)).contains(bestBlock.getRoot());
    assertThat(this.storageSystem.chainHeadChannel().getHeadEvents()).contains(new HeadEvent(bestBlock.getSlot(), bestBlock.getStateRoot(), bestBlock.getRoot(), true, true, spec.getBeaconStateUtil(bestBlock.getSlot()).getPreviousDutyDependentRoot(bestBlock.getState()), spec.getBeaconStateUtil(bestBlock.getSlot()).getCurrentDutyDependentRoot(bestBlock.getState())));
}
Also used : HeadEvent(tech.pegasys.teku.storage.api.TrackingChainHeadChannel.HeadEvent) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)2 HeadEvent (tech.pegasys.teku.storage.api.TrackingChainHeadChannel.HeadEvent)2 MinimalBeaconBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary)1 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)1