Search in sources :

Example 31 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.

the class RecentChainDataTest method getAncestorsOnFork_unknownRoot.

@Test
public void getAncestorsOnFork_unknownRoot() {
    initPreGenesis();
    final ChainBuilder chainBuilder = ChainBuilder.create(BLSKeyGenerator.generateKeyPairs(16));
    final SignedBlockAndState genesis = chainBuilder.generateGenesis();
    recentChainData.initializeFromGenesis(genesis.getState(), UInt64.ZERO);
    assertThat(recentChainData.getAncestorsOnFork(UInt64.valueOf(1), Bytes32.ZERO)).isEmpty();
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 32 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.

the class RecentChainDataTest method initializeFromAnchorPoint_withTimeLessThanAnchorBlockTime.

@Test
public void initializeFromAnchorPoint_withTimeLessThanAnchorBlockTime() {
    initPreGenesis();
    final ChainBuilder chainBuilder = ChainBuilder.create(spec);
    final UInt64 genesisTime = UInt64.valueOf(5000);
    chainBuilder.generateGenesis(genesisTime, true);
    // Build a small chain
    chainBuilder.generateBlocksUpToSlot(10);
    final SignedBlockAndState anchor = chainBuilder.generateNextBlock();
    final AnchorPoint anchorPoint = AnchorPoint.fromInitialState(spec, anchor.getState());
    final UInt64 anchorBlockTime = anchorPoint.getBlockSlot().times(genesisSpecConfig.getSecondsPerSlot()).plus(genesisTime);
    final UInt64 time = genesisTime.plus(1);
    assertThat(time).isLessThan(anchorBlockTime);
    recentChainData.initializeFromAnchorPoint(anchorPoint, time);
    assertThat(recentChainData.getStore().getTime()).isEqualTo(anchorBlockTime);
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 33 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.

the class ForkChoiceStrategyTest method getBlockRootsAtSlot_shouldReturnAllRoots.

@Test
void getBlockRootsAtSlot_shouldReturnAllRoots() {
    final StorageSystem storageSystem = initStorageSystem();
    storageSystem.chainUpdater().addNewBestBlock();
    ChainBuilder fork = storageSystem.chainBuilder().fork();
    final SignedBlockAndState bestBlock = storageSystem.chainUpdater().addNewBestBlock();
    final SignedBlockAndState forkBlock = fork.generateBlockAtSlot(bestBlock.getSlot(), ChainBuilder.BlockOptions.create().setEth1Data(new Eth1Data(Bytes32.ZERO, UInt64.valueOf(6), Bytes32.ZERO)));
    final ForkChoiceStrategy strategy = getProtoArray(storageSystem);
    strategy.applyUpdate(List.of(BlockAndCheckpointEpochs.fromBlockAndState(bestBlock), BlockAndCheckpointEpochs.fromBlockAndState(forkBlock)), emptySet(), storageSystem.recentChainData().getFinalizedCheckpoint().orElseThrow());
    assertThat(strategy.getBlockRootsAtSlot(bestBlock.getSlot())).containsExactlyInAnyOrder(bestBlock.getRoot(), forkBlock.getRoot());
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Test(org.junit.jupiter.api.Test)

Aggregations

ChainBuilder (tech.pegasys.teku.core.ChainBuilder)33 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)30 Test (org.junit.jupiter.api.Test)27 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)18 BlockOptions (tech.pegasys.teku.core.ChainBuilder.BlockOptions)7 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)5 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)5 Eth1Data (tech.pegasys.teku.spec.datastructures.blocks.Eth1Data)4 StoreTransaction (tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction)4 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)3 ChainUpdater (tech.pegasys.teku.storage.client.ChainUpdater)3 HashSet (java.util.HashSet)2 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)2 BlockAndCheckpointEpochs (tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 ReorgEvent (tech.pegasys.teku.storage.api.TrackingChainHeadChannel.ReorgEvent)2 StorageSystem (tech.pegasys.teku.storage.storageSystem.StorageSystem)2 ArrayList (java.util.ArrayList)1