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));
}
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())));
}
Aggregations