use of tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel in project teku by ConsenSys.
the class ForkChoiceTestExecutor method runTest.
@Override
public void runTest(final TestDefinition testDefinition) throws Throwable {
if (testsToSkip.contains(testDefinition.getTestName())) {
throw new TestAbortedException("Test " + testDefinition.getDisplayName() + " has been ignored");
}
// Note: The fork choice spec says there may be settings in a meta.yaml file but currently no
// tests actually have one, so we currently don't bother trying to load it.
final BeaconState anchorState = TestDataUtils.loadStateFromSsz(testDefinition, "anchor_state.ssz_snappy");
final Spec spec = testDefinition.getSpec();
final SignedBeaconBlock anchorBlock = loadAnchorBlock(testDefinition);
final StorageSystem storageSystem = InMemoryStorageSystemBuilder.create().specProvider(spec).build();
final RecentChainData recentChainData = storageSystem.recentChainData();
recentChainData.initializeFromAnchorPoint(AnchorPoint.fromInitialBlockAndState(spec, new SignedBlockAndState(anchorBlock, anchorState)), spec.getSlotStartTime(anchorBlock.getSlot(), anchorState.getGenesis_time()));
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
final ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator, true);
final StubExecutionEngineChannel executionEngine = new StubExecutionEngineChannel(spec);
runSteps(testDefinition, spec, recentChainData, forkChoice, executionEngine);
}
use of tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel in project teku by ConsenSys.
the class SyncingNodeManager method create.
@SuppressWarnings("FutureReturnValueIgnored")
public static SyncingNodeManager create(final AsyncRunner asyncRunner, Eth2P2PNetworkFactory networkFactory, final List<BLSKeyPair> validatorKeys, Consumer<Eth2P2PNetworkBuilder> configureNetwork) throws Exception {
final Spec spec = TestSpecFactory.createMinimalPhase0();
final EventChannels eventChannels = EventChannels.createSyncChannels(TEST_EXCEPTION_HANDLER, new NoOpMetricsSystem());
final RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
final BeaconChainUtil chainUtil = BeaconChainUtil.create(spec, recentChainData, validatorKeys);
chainUtil.initializeStorage();
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
BlockImporter blockImporter = new BlockImporter(spec, eventChannels.getPublisher(BlockImportNotifications.class), recentChainData, forkChoice, WeakSubjectivityFactory.lenientValidator(), new StubExecutionEngineChannel(spec));
BlockValidator blockValidator = new BlockValidator(spec, recentChainData);
final PendingPool<SignedBeaconBlock> pendingBlocks = PendingPool.createForBlocks(spec);
final FutureItems<SignedBeaconBlock> futureBlocks = FutureItems.create(SignedBeaconBlock::getSlot);
BlockManager blockManager = new BlockManager(recentChainData, blockImporter, pendingBlocks, futureBlocks, blockValidator);
eventChannels.subscribe(SlotEventsChannel.class, blockManager).subscribe(BlockImportChannel.class, blockManager).subscribe(BlockImportNotifications.class, blockManager).subscribe(FinalizedCheckpointChannel.class, pendingBlocks);
final Eth2P2PNetworkBuilder networkBuilder = networkFactory.builder().spec(spec).eventChannels(eventChannels).recentChainData(recentChainData).gossipedBlockProcessor(blockManager::validateAndImportBlock);
configureNetwork.accept(networkBuilder);
final Eth2P2PNetwork eth2P2PNetwork = networkBuilder.startNetwork();
SyncManager syncManager = SyncManager.create(asyncRunner, eth2P2PNetwork, recentChainData, blockImporter, new NoOpMetricsSystem(), spec);
ForwardSyncService syncService = new SinglePeerSyncService(syncManager, recentChainData);
final FetchRecentBlocksService recentBlockFetcher = FetchRecentBlocksService.create(asyncRunner, eth2P2PNetwork, pendingBlocks, syncService);
recentBlockFetcher.subscribeBlockFetched(blockManager::importBlock);
blockManager.subscribeToReceivedBlocks((block, executionOptimistic) -> recentBlockFetcher.cancelRecentBlockRequest(block.getRoot()));
recentBlockFetcher.start().join();
blockManager.start().join();
syncService.start().join();
return new SyncingNodeManager(eventChannels, recentChainData, chainUtil, eth2P2PNetwork, syncService);
}
use of tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel in project teku by ConsenSys.
the class ForkChoiceTestExecutor method applyBlock.
private void applyBlock(final TestDefinition testDefinition, final Spec spec, final ForkChoice forkChoice, final Map<String, Object> step, final StubExecutionEngineChannel executionEngine) {
final String blockName = get(step, "block");
final boolean valid = !step.containsKey("valid") || (boolean) step.get("valid");
final SignedBeaconBlock block = TestDataUtils.loadSsz(testDefinition, blockName + ".ssz_snappy", spec::deserializeSignedBeaconBlock);
LOG.info("Importing block {} at slot {} with parent {}", block.getRoot(), block.getSlot(), block.getParentRoot());
final SafeFuture<BlockImportResult> result = forkChoice.onBlock(block, executionEngine);
assertThat(result).isCompleted();
final BlockImportResult importResult = result.join();
assertThat(importResult).describedAs("Incorrect block import result for block %s", block).has(new Condition<>(r -> r.isSuccessful() == valid, "isSuccessful matching " + valid));
}
use of tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel in project teku by ConsenSys.
the class BeaconChainUtil method createAndImportBlockAtSlot.
public SignedBeaconBlock createAndImportBlockAtSlot(final UInt64 slot, Optional<SszList<Attestation>> attestations, Optional<SszList<Deposit>> deposits, Optional<SszList<SignedVoluntaryExit>> exits, Optional<Eth1Data> eth1Data) throws Exception {
final SignedBeaconBlock block = createBlockAndStateAtSlot(slot, true, attestations, deposits, exits, eth1Data).getBlock();
setSlot(slot);
final BlockImportResult importResult = forkChoice.onBlock(block, new StubExecutionEngineChannel(spec)).join();
if (!importResult.isSuccessful()) {
throw new IllegalStateException("Produced an invalid block ( reason " + importResult.getFailureReason().name() + ") at slot " + slot + ": " + block);
}
forkChoice.processHead(slot).join();
return importResult.getBlock();
}
Aggregations