Search in sources :

Example 1 with StorageSystem

use of tech.pegasys.teku.storage.storageSystem.StorageSystem 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 StorageSystem

use of tech.pegasys.teku.storage.storageSystem.StorageSystem in project teku by ConsenSys.

the class ForkChoiceStrategyTest method getAncestor_headIsUnknown.

@Test
void getAncestor_headIsUnknown() {
    final StorageSystem storageSystem = initStorageSystem();
    final ForkChoiceStrategy protoArrayStrategy = getProtoArray(storageSystem);
    assertThat(protoArrayStrategy.getAncestor(dataStructureUtil.randomBytes32(), ZERO)).isEmpty();
}
Also used : ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Test(org.junit.jupiter.api.Test)

Example 3 with StorageSystem

use of tech.pegasys.teku.storage.storageSystem.StorageSystem in project teku by ConsenSys.

the class ForkChoiceStrategyTest method executionBlockHash_shouldBeEmptyForUnknownBlock.

@Test
void executionBlockHash_shouldBeEmptyForUnknownBlock() {
    final StorageSystem storageSystem = initStorageSystem(TestSpecFactory.createMinimalBellatrix());
    final ForkChoiceStrategy strategy = getProtoArray(storageSystem);
    assertThat(strategy.executionBlockHash(Bytes32.ZERO)).isEmpty();
}
Also used : ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Test(org.junit.jupiter.api.Test)

Example 4 with StorageSystem

use of tech.pegasys.teku.storage.storageSystem.StorageSystem in project teku by ConsenSys.

the class ForkChoiceStrategyTest method initStorageSystem.

private StorageSystem initStorageSystem(final Spec spec) {
    final StorageSystem storageSystem = InMemoryStorageSystemBuilder.buildDefault(spec);
    storageSystem.chainUpdater().initializeGenesis();
    return storageSystem;
}
Also used : StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem)

Example 5 with StorageSystem

use of tech.pegasys.teku.storage.storageSystem.StorageSystem in project teku by ConsenSys.

the class ForkChoiceStrategyTest method getAncestor_ancestorIsFound.

@Test
void getAncestor_ancestorIsFound() {
    final StorageSystem storageSystem = initStorageSystem();
    storageSystem.chainUpdater().advanceChain(1);
    final SignedBlockAndState ancestor = storageSystem.chainUpdater().advanceChain(2);
    storageSystem.chainUpdater().advanceChain(3);
    final SignedBlockAndState head = storageSystem.chainUpdater().advanceChain(5);
    final ForkChoiceStrategy protoArrayStrategy = getProtoArray(storageSystem);
    assertThat(protoArrayStrategy.getAncestor(head.getRoot(), ancestor.getSlot())).contains(ancestor.getRoot());
}
Also used : ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Test(org.junit.jupiter.api.Test)

Aggregations

StorageSystem (tech.pegasys.teku.storage.storageSystem.StorageSystem)31 Test (org.junit.jupiter.api.Test)22 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)18 ReadOnlyForkChoiceStrategy (tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy)13 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)8 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)6 ForkChoice (tech.pegasys.teku.statetransition.forkchoice.ForkChoice)6 Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)5 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)5 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)5 CheckpointState (tech.pegasys.teku.spec.datastructures.state.CheckpointState)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)3 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)3 TestTemplate (org.junit.jupiter.api.TestTemplate)2 ChainBuilder (tech.pegasys.teku.core.ChainBuilder)2 Spec (tech.pegasys.teku.spec.Spec)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 Duration (java.time.Duration)1 Optional (java.util.Optional)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1