@Test public void create_timeLessThanGenesisTime() { final UInt64 genesisTime = UInt64.valueOf(100); final SignedBlockAndState genesis = chainBuilder.generateGenesis(genesisTime, false); final Checkpoint genesisCheckpoint = chainBuilder.getCurrentCheckpointForEpoch(0); assertThatThrownBy( () -> Store.create( SYNC_RUNNER, new StubMetricsSystem(), blockProviderFromChainBuilder(), StateAndBlockProvider.NOOP, genesisTime.minus(1), genesisTime, genesisCheckpoint, genesisCheckpoint, genesisCheckpoint, Map.of(genesis.getRoot(), genesis.getParentRoot()), Map.of(genesis.getRoot(), genesis.getSlot()), genesis, Collections.emptyMap(), StoreConfig.createDefault())) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Time must be greater than or equal to genesisTime"); }
public static SafeFuture<UpdatableStore> create( final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final BlockProvider blockProvider, final StateAndBlockProvider stateAndBlockProvider, final UInt64 time, final UInt64 genesisTime, final Checkpoint justifiedCheckpoint, final Checkpoint finalizedCheckpoint, final Checkpoint bestJustifiedCheckpoint, final Map<Bytes32, Bytes32> childToParentRoot, final Map<Bytes32, UInt64> rootToSlotMap, final SignedBlockAndState finalizedBlockAndState, final Map<UInt64, VoteTracker> votes, final StoreConfig config) { final Map<Bytes32, SignedBeaconBlock> blocks = LimitedMap.create(config.getBlockCacheSize()); final CachingTaskQueue<Checkpoint, BeaconState> checkpointStateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_checkpoint_states", config.getCheckpointStateCacheSize()); final CachingTaskQueue<Bytes32, SignedBlockAndState> stateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_states", config.getStateCacheSize()); HashTree.Builder treeBuilder = HashTree.builder().rootHash(finalizedBlockAndState.getRoot()); childToParentRoot.forEach(treeBuilder::childAndParentRoots); final BlockTree blockTree = BlockTree.create(treeBuilder.build(), rootToSlotMap); if (blockTree.size() < childToParentRoot.size()) { LOG.warn("Ignoring {} non-canonical blocks", childToParentRoot.size() - blockTree.size()); } return SafeFuture.completedFuture( new Store( metricsSystem, config.getHotStatePersistenceFrequencyInEpochs(), blockProvider, stateAndBlockProvider, stateTaskQueue, time, genesisTime, justifiedCheckpoint, finalizedCheckpoint, bestJustifiedCheckpoint, blockTree, finalizedBlockAndState, votes, blocks, checkpointStateTaskQueue)); }
Store implements UpdatableStore { public static SafeFuture<UpdatableStore> create( final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final BlockProvider blockProvider, final StateAndBlockProvider stateAndBlockProvider, final UInt64 time, final UInt64 genesisTime, final Checkpoint justifiedCheckpoint, final Checkpoint finalizedCheckpoint, final Checkpoint bestJustifiedCheckpoint, final Map<Bytes32, Bytes32> childToParentRoot, final Map<Bytes32, UInt64> rootToSlotMap, final SignedBlockAndState finalizedBlockAndState, final Map<UInt64, VoteTracker> votes, final StoreConfig config) { final Map<Bytes32, SignedBeaconBlock> blocks = LimitedMap.create(config.getBlockCacheSize()); final CachingTaskQueue<Checkpoint, BeaconState> checkpointStateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_checkpoint_states", config.getCheckpointStateCacheSize()); final CachingTaskQueue<Bytes32, SignedBlockAndState> stateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_states", config.getStateCacheSize()); HashTree.Builder treeBuilder = HashTree.builder().rootHash(finalizedBlockAndState.getRoot()); childToParentRoot.forEach(treeBuilder::childAndParentRoots); final BlockTree blockTree = BlockTree.create(treeBuilder.build(), rootToSlotMap); if (blockTree.size() < childToParentRoot.size()) { LOG.warn("Ignoring {} non-canonical blocks", childToParentRoot.size() - blockTree.size()); } return SafeFuture.completedFuture( new Store( metricsSystem, config.getHotStatePersistenceFrequencyInEpochs(), blockProvider, stateAndBlockProvider, stateTaskQueue, time, genesisTime, justifiedCheckpoint, finalizedCheckpoint, bestJustifiedCheckpoint, blockTree, finalizedBlockAndState, votes, blocks, checkpointStateTaskQueue)); } }
Store implements UpdatableStore { public static SafeFuture<UpdatableStore> create( final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final BlockProvider blockProvider, final StateAndBlockProvider stateAndBlockProvider, final UInt64 time, final UInt64 genesisTime, final Checkpoint justifiedCheckpoint, final Checkpoint finalizedCheckpoint, final Checkpoint bestJustifiedCheckpoint, final Map<Bytes32, Bytes32> childToParentRoot, final Map<Bytes32, UInt64> rootToSlotMap, final SignedBlockAndState finalizedBlockAndState, final Map<UInt64, VoteTracker> votes, final StoreConfig config) { final Map<Bytes32, SignedBeaconBlock> blocks = LimitedMap.create(config.getBlockCacheSize()); final CachingTaskQueue<Checkpoint, BeaconState> checkpointStateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_checkpoint_states", config.getCheckpointStateCacheSize()); final CachingTaskQueue<Bytes32, SignedBlockAndState> stateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_states", config.getStateCacheSize()); HashTree.Builder treeBuilder = HashTree.builder().rootHash(finalizedBlockAndState.getRoot()); childToParentRoot.forEach(treeBuilder::childAndParentRoots); final BlockTree blockTree = BlockTree.create(treeBuilder.build(), rootToSlotMap); if (blockTree.size() < childToParentRoot.size()) { LOG.warn("Ignoring {} non-canonical blocks", childToParentRoot.size() - blockTree.size()); } return SafeFuture.completedFuture( new Store( metricsSystem, config.getHotStatePersistenceFrequencyInEpochs(), blockProvider, stateAndBlockProvider, stateTaskQueue, time, genesisTime, justifiedCheckpoint, finalizedCheckpoint, bestJustifiedCheckpoint, blockTree, finalizedBlockAndState, votes, blocks, checkpointStateTaskQueue)); } private  Store(
      final MetricsSystem metricsSystem,
      int hotStatePersistenceFrequencyInEpochs,
      final BlockProvider blockProvider,
      final StateAndBlockProvider stateAndBlockProvider,
      final CachingTaskQueue<Bytes32, SignedBlockAndState> states,
      final UInt64 time,
      final UInt64 genesis_time,
      final Checkpoint justified_checkpoint,
      final Checkpoint finalized_checkpoint,
      final Checkpoint best_justified_checkpoint,
      final BlockTree blockTree,
      final SignedBlockAndState finalizedBlockAndState,
      final Map<UInt64, VoteTracker> votes,
      final Map<Bytes32, SignedBeaconBlock> blocks,
      final CachingTaskQueue<Checkpoint, BeaconState> checkpointStates); }
Store implements UpdatableStore { public static SafeFuture<UpdatableStore> create( final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final BlockProvider blockProvider, final StateAndBlockProvider stateAndBlockProvider, final UInt64 time, final UInt64 genesisTime, final Checkpoint justifiedCheckpoint, final Checkpoint finalizedCheckpoint, final Checkpoint bestJustifiedCheckpoint, final Map<Bytes32, Bytes32> childToParentRoot, final Map<Bytes32, UInt64> rootToSlotMap, final SignedBlockAndState finalizedBlockAndState, final Map<UInt64, VoteTracker> votes, final StoreConfig config) { final Map<Bytes32, SignedBeaconBlock> blocks = LimitedMap.create(config.getBlockCacheSize()); final CachingTaskQueue<Checkpoint, BeaconState> checkpointStateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_checkpoint_states", config.getCheckpointStateCacheSize()); final CachingTaskQueue<Bytes32, SignedBlockAndState> stateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_states", config.getStateCacheSize()); HashTree.Builder treeBuilder = HashTree.builder().rootHash(finalizedBlockAndState.getRoot()); childToParentRoot.forEach(treeBuilder::childAndParentRoots); final BlockTree blockTree = BlockTree.create(treeBuilder.build(), rootToSlotMap); if (blockTree.size() < childToParentRoot.size()) { LOG.warn("Ignoring {} non-canonical blocks", childToParentRoot.size() - blockTree.size()); } return SafeFuture.completedFuture( new Store( metricsSystem, config.getHotStatePersistenceFrequencyInEpochs(), blockProvider, stateAndBlockProvider, stateTaskQueue, time, genesisTime, justifiedCheckpoint, finalizedCheckpoint, bestJustifiedCheckpoint, blockTree, finalizedBlockAndState, votes, blocks, checkpointStateTaskQueue)); } private  Store(
      final MetricsSystem metricsSystem,
      int hotStatePersistenceFrequencyInEpochs,
      final BlockProvider blockProvider,
      final StateAndBlockProvider stateAndBlockProvider,
      final CachingTaskQueue<Bytes32, SignedBlockAndState> states,
      final UInt64 time,
      final UInt64 genesis_time,
      final Checkpoint justified_checkpoint,
      final Checkpoint finalized_checkpoint,
      final Checkpoint best_justified_checkpoint,
      final BlockTree blockTree,
      final SignedBlockAndState finalizedBlockAndState,
      final Map<UInt64, VoteTracker> votes,
      final Map<Bytes32, SignedBeaconBlock> blocks,
      final CachingTaskQueue<Checkpoint, BeaconState> checkpointStates); static SafeFuture<UpdatableStore> create(
      final AsyncRunner asyncRunner,
      final MetricsSystem metricsSystem,
      final BlockProvider blockProvider,
      final StateAndBlockProvider stateAndBlockProvider,
      final UInt64 time,
      final UInt64 genesisTime,
      final Checkpoint justifiedCheckpoint,
      final Checkpoint finalizedCheckpoint,
      final Checkpoint bestJustifiedCheckpoint,
      final Map<Bytes32, Bytes32> childToParentRoot,
      final Map<Bytes32, UInt64> rootToSlotMap,
      final SignedBlockAndState finalizedBlockAndState,
      final Map<UInt64, VoteTracker> votes,
      final StoreConfig config); @Override void startMetrics(); @Override StoreTransaction startTransaction(final StorageUpdateChannel storageUpdateChannel); @Override StoreTransaction startTransaction(
      final StorageUpdateChannel storageUpdateChannel, final StoreUpdateHandler updateHandler); @Override UInt64 getTime(); @Override UInt64 getGenesisTime(); @Override Checkpoint getJustifiedCheckpoint(); @Override Checkpoint getFinalizedCheckpoint(); @Override SignedBlockAndState getLatestFinalizedBlockAndState(); @Override UInt64 getLatestFinalizedBlockSlot(); @Override Checkpoint getBestJustifiedCheckpoint(); @Override boolean containsBlock(Bytes32 blockRoot); @Override Set<Bytes32> getBlockRoots(); @Override List<Bytes32> getOrderedBlockRoots(); @Override Optional<BeaconState> getBlockStateIfAvailable(final Bytes32 blockRoot); @Override Optional<SignedBeaconBlock> getBlockIfAvailable(final Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBeaconBlock>> retrieveSignedBlock(final Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBlockAndState>> retrieveBlockAndState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(Checkpoint checkpoint); @Override SafeFuture<CheckpointState> retrieveFinalizedCheckpointAndState(); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(
      Checkpoint checkpoint, final BeaconState latestStateAtEpoch); @Override Set<UInt64> getVotedValidatorIndices(); }
Store implements UpdatableStore { public static SafeFuture<UpdatableStore> create( final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final BlockProvider blockProvider, final StateAndBlockProvider stateAndBlockProvider, final UInt64 time, final UInt64 genesisTime, final Checkpoint justifiedCheckpoint, final Checkpoint finalizedCheckpoint, final Checkpoint bestJustifiedCheckpoint, final Map<Bytes32, Bytes32> childToParentRoot, final Map<Bytes32, UInt64> rootToSlotMap, final SignedBlockAndState finalizedBlockAndState, final Map<UInt64, VoteTracker> votes, final StoreConfig config) { final Map<Bytes32, SignedBeaconBlock> blocks = LimitedMap.create(config.getBlockCacheSize()); final CachingTaskQueue<Checkpoint, BeaconState> checkpointStateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_checkpoint_states", config.getCheckpointStateCacheSize()); final CachingTaskQueue<Bytes32, SignedBlockAndState> stateTaskQueue = CachingTaskQueue.create( asyncRunner, metricsSystem, "memory_states", config.getStateCacheSize()); HashTree.Builder treeBuilder = HashTree.builder().rootHash(finalizedBlockAndState.getRoot()); childToParentRoot.forEach(treeBuilder::childAndParentRoots); final BlockTree blockTree = BlockTree.create(treeBuilder.build(), rootToSlotMap); if (blockTree.size() < childToParentRoot.size()) { LOG.warn("Ignoring {} non-canonical blocks", childToParentRoot.size() - blockTree.size()); } return SafeFuture.completedFuture( new Store( metricsSystem, config.getHotStatePersistenceFrequencyInEpochs(), blockProvider, stateAndBlockProvider, stateTaskQueue, time, genesisTime, justifiedCheckpoint, finalizedCheckpoint, bestJustifiedCheckpoint, blockTree, finalizedBlockAndState, votes, blocks, checkpointStateTaskQueue)); } private  Store(
      final MetricsSystem metricsSystem,
      int hotStatePersistenceFrequencyInEpochs,
      final BlockProvider blockProvider,
      final StateAndBlockProvider stateAndBlockProvider,
      final CachingTaskQueue<Bytes32, SignedBlockAndState> states,
      final UInt64 time,
      final UInt64 genesis_time,
      final Checkpoint justified_checkpoint,
      final Checkpoint finalized_checkpoint,
      final Checkpoint best_justified_checkpoint,
      final BlockTree blockTree,
      final SignedBlockAndState finalizedBlockAndState,
      final Map<UInt64, VoteTracker> votes,
      final Map<Bytes32, SignedBeaconBlock> blocks,
      final CachingTaskQueue<Checkpoint, BeaconState> checkpointStates); static SafeFuture<UpdatableStore> create(
      final AsyncRunner asyncRunner,
      final MetricsSystem metricsSystem,
      final BlockProvider blockProvider,
      final StateAndBlockProvider stateAndBlockProvider,
      final UInt64 time,
      final UInt64 genesisTime,
      final Checkpoint justifiedCheckpoint,
      final Checkpoint finalizedCheckpoint,
      final Checkpoint bestJustifiedCheckpoint,
      final Map<Bytes32, Bytes32> childToParentRoot,
      final Map<Bytes32, UInt64> rootToSlotMap,
      final SignedBlockAndState finalizedBlockAndState,
      final Map<UInt64, VoteTracker> votes,
      final StoreConfig config); @Override void startMetrics(); @Override StoreTransaction startTransaction(final StorageUpdateChannel storageUpdateChannel); @Override StoreTransaction startTransaction(
      final StorageUpdateChannel storageUpdateChannel, final StoreUpdateHandler updateHandler); @Override UInt64 getTime(); @Override UInt64 getGenesisTime(); @Override Checkpoint getJustifiedCheckpoint(); @Override Checkpoint getFinalizedCheckpoint(); @Override SignedBlockAndState getLatestFinalizedBlockAndState(); @Override UInt64 getLatestFinalizedBlockSlot(); @Override Checkpoint getBestJustifiedCheckpoint(); @Override boolean containsBlock(Bytes32 blockRoot); @Override Set<Bytes32> getBlockRoots(); @Override List<Bytes32> getOrderedBlockRoots(); @Override Optional<BeaconState> getBlockStateIfAvailable(final Bytes32 blockRoot); @Override Optional<SignedBeaconBlock> getBlockIfAvailable(final Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBeaconBlock>> retrieveSignedBlock(final Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBlockAndState>> retrieveBlockAndState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(Checkpoint checkpoint); @Override SafeFuture<CheckpointState> retrieveFinalizedCheckpointAndState(); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(
      Checkpoint checkpoint, final BeaconState latestStateAtEpoch); @Override Set<UInt64> getVotedValidatorIndices();  }