use of tech.pegasys.teku.spec.datastructures.hashtree.HashTree in project teku by ConsenSys.
the class StateGeneratorTest method regenerateStateForBlock_regenerateBaseStateWhenBlockIsMissing.
@Test
public void regenerateStateForBlock_regenerateBaseStateWhenBlockIsMissing() {
// Build a small chain
final SignedBlockAndState genesis = chainBuilder.generateGenesis();
chainBuilder.generateBlocksUpToSlot(5);
final Map<Bytes32, SignedBeaconBlock> blockMap = chainBuilder.streamBlocksAndStates().map(SignedBlockAndState::getBlock).collect(Collectors.toMap(SignedBeaconBlock::getRoot, Function.identity()));
final HashTree tree = HashTree.builder().rootHash(genesis.getRoot()).blocks(blockMap.values()).build();
// Create block provider that is missing the base (genesis) block
blockMap.remove(genesis.getRoot());
final BlockProvider blockProvider = BlockProvider.fromMap(blockMap);
final StateGenerator generator = StateGenerator.create(spec, tree, genesis, blockProvider);
final SafeFuture<StateAndBlockSummary> result = generator.regenerateStateForBlock(genesis.getRoot());
final StateAndBlockSummary expected = StateAndBlockSummary.create(genesis.getState());
assertThat(result).isCompletedWithValue(expected);
}
use of tech.pegasys.teku.spec.datastructures.hashtree.HashTree in project teku by ConsenSys.
the class StateGeneratorTest method regenerateStateForBlock_missingBaseBlock.
@Test
public void regenerateStateForBlock_missingBaseBlock() {
// Build a small chain
final SignedBlockAndState genesis = chainBuilder.generateGenesis();
chainBuilder.generateBlocksUpToSlot(5);
final Map<Bytes32, SignedBeaconBlock> blockMap = chainBuilder.streamBlocksAndStates().map(SignedBlockAndState::getBlock).collect(Collectors.toMap(SignedBeaconBlock::getRoot, Function.identity()));
final SignedBlockAndState lastBlockAndState = chainBuilder.getLatestBlockAndState();
final HashTree tree = HashTree.builder().rootHash(genesis.getRoot()).blocks(blockMap.values()).build();
// Create block provider that is missing the base (genesis) block
blockMap.remove(genesis.getRoot());
final BlockProvider blockProvider = BlockProvider.fromMap(blockMap);
final StateGenerator generator = StateGenerator.create(spec, tree, genesis, blockProvider);
final SafeFuture<StateAndBlockSummary> result = generator.regenerateStateForBlock(lastBlockAndState.getRoot());
assertThat(result).isCompletedWithValue(lastBlockAndState);
}
use of tech.pegasys.teku.spec.datastructures.hashtree.HashTree in project teku by ConsenSys.
the class StateGeneratorTest method testGeneratorWithMissingBlock.
private void testGeneratorWithMissingBlock(BiConsumer<StateGenerator, SignedBeaconBlock> processor) {
// Build a small chain
final SignedBlockAndState genesis = chainBuilder.generateGenesis();
chainBuilder.generateBlocksUpToSlot(5);
final Map<Bytes32, SignedBeaconBlock> blockMap = chainBuilder.streamBlocksAndStates().map(SignedBlockAndState::getBlock).collect(Collectors.toMap(SignedBeaconBlock::getRoot, Function.identity()));
final HashTree tree = HashTree.builder().rootHash(genesis.getRoot()).blocks(blockMap.values()).build();
// Create block provider that is missing some blocks
final SignedBeaconBlock missingBlock = chainBuilder.getBlockAtSlot(genesis.getSlot().plus(2));
blockMap.remove(missingBlock.getRoot());
final BlockProvider blockProvider = BlockProvider.fromMap(blockMap);
final StateGenerator generator = StateGenerator.create(spec, tree, genesis, blockProvider);
processor.accept(generator, missingBlock);
}
use of tech.pegasys.teku.spec.datastructures.hashtree.HashTree in project teku by ConsenSys.
the class StateGenerationTaskTest method createTask.
private StateGenerationTask createTask(final int startSlot, final int endSlot, final Optional<SlotAndBlockRoot> epochBoundaryRoot) {
final SignedBlockAndState startBlockAndState = chainBuilder.getBlockAndStateAtSlot(startSlot);
final SignedBeaconBlock endBlock = chainBuilder.getBlockAtSlot(endSlot);
final HashTree.Builder treeBuilder = HashTree.builder().block(startBlockAndState.getBlock()).rootHash(startBlockAndState.getRoot());
SignedBeaconBlock block = endBlock;
while (block.getSlot().isGreaterThan(startBlockAndState.getSlot())) {
treeBuilder.block(block);
block = chainBuilder.getBlock(block.getParentRoot()).orElseThrow();
}
final HashTree tree = treeBuilder.build();
return new StateGenerationTask(spec, endBlock.getRoot(), tree, blockProvider, new StateRegenerationBaseSelector(spec, epochBoundaryRoot, () -> Optional.of(new BlockRootAndState(startBlockAndState.getRoot(), startBlockAndState.getState())), getStateAndBlockProvider(), Optional.empty(), REPLAY_TOLERANCE_TO_AVOID_LOADING_IN_EPOCHS));
}
Aggregations