Search in sources :

Example 1 with StubExecutionEngineChannel

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);
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) TestAbortedException(org.opentest4j.TestAbortedException) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem)

Example 2 with StubExecutionEngineChannel

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);
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) SlotEventsChannel(tech.pegasys.teku.ethereum.events.SlotEventsChannel) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) BlockValidator(tech.pegasys.teku.statetransition.validation.BlockValidator) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) FetchRecentBlocksService(tech.pegasys.teku.beacon.sync.gossip.FetchRecentBlocksService) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) SinglePeerSyncService(tech.pegasys.teku.beacon.sync.forward.singlepeer.SinglePeerSyncService) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) SyncManager(tech.pegasys.teku.beacon.sync.forward.singlepeer.SyncManager) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ForwardSyncService(tech.pegasys.teku.beacon.sync.forward.ForwardSyncService) BlockManager(tech.pegasys.teku.statetransition.block.BlockManager) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) Spec(tech.pegasys.teku.spec.Spec) Eth2P2PNetwork(tech.pegasys.teku.networking.eth2.Eth2P2PNetwork)

Example 3 with StubExecutionEngineChannel

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));
}
Also used : ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Bytes(org.apache.tuweni.bytes.Bytes) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SSZ(org.apache.tuweni.ssz.SSZ) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Map(java.util.Map) InMemoryStorageSystemBuilder(tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) UInt256(org.apache.tuweni.units.bigints.UInt256) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) ImmutableMap(com.google.common.collect.ImmutableMap) TestAbortedException(org.opentest4j.TestAbortedException) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) TestExecutor(tech.pegasys.teku.reference.TestExecutor) TestDataUtils(tech.pegasys.teku.reference.TestDataUtils) TestDefinition(tech.pegasys.teku.ethtests.finder.TestDefinition) ByteOrder(java.nio.ByteOrder) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) Condition(org.assertj.core.api.Condition) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)

Example 4 with StubExecutionEngineChannel

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();
}
Also used : SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)

Aggregations

SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 StubExecutionEngineChannel (tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel)4 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)3 Spec (tech.pegasys.teku.spec.Spec)3 ForkChoice (tech.pegasys.teku.statetransition.forkchoice.ForkChoice)3 MergeTransitionBlockValidator (tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator)3 StubForkChoiceNotifier (tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier)3 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)3 TestAbortedException (org.opentest4j.TestAbortedException)2 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteOrder (java.nio.ByteOrder)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 SSZ (org.apache.tuweni.ssz.SSZ)1