use of tech.pegasys.teku.storage.api.StorageQueryChannel in project teku by ConsenSys.
the class HistoricalBatchFetcherTest method setup.
@BeforeEach
public void setup() {
storageSystem.chainUpdater().initializeGenesis();
when(storageUpdateChannel.onFinalizedBlocks(any())).thenReturn(SafeFuture.COMPLETE);
// Set up main chain and fork chain
chainBuilder.generateGenesis();
forkBuilder = chainBuilder.fork();
chainBuilder.generateBlocksUpToSlot(20);
// Fork skips one block then creates a chain of the same size
forkBuilder.generateBlockAtSlot(2);
forkBuilder.generateBlocksUpToSlot(20);
blockBatch = chainBuilder.streamBlocksAndStates(10, 20).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
lastBlockInBatch = chainBuilder.getLatestBlockAndState().getBlock();
firstBlockInBatch = blockBatch.get(0);
final StorageQueryChannel historicalChainData = mock(StorageQueryChannel.class);
final RecentChainData recentChainData = storageSystem.recentChainData();
chainDataClient = new CombinedChainDataClient(recentChainData, historicalChainData, spec);
peer = RespondingEth2Peer.create(spec, chainBuilder);
fetcher = new HistoricalBatchFetcher(storageUpdateChannel, signatureVerifier, chainDataClient, spec, peer, lastBlockInBatch.getSlot(), lastBlockInBatch.getRoot(), UInt64.valueOf(blockBatch.size()), maxRequests);
final ForkInfo forkInfo = mock(ForkInfo.class);
when(beaconState.getForkInfo()).thenReturn(forkInfo);
when(forkInfo.getGenesisValidatorsRoot()).thenReturn(Bytes32.ZERO);
when(signatureVerifier.verify(any(), any(), anyList())).thenReturn(SafeFuture.completedFuture(true));
}
use of tech.pegasys.teku.storage.api.StorageQueryChannel in project teku by ConsenSys.
the class BeaconChainController method initialize.
protected SafeFuture<?> initialize() {
final StoreConfig storeConfig = beaconConfig.storeConfig();
coalescingChainHeadChannel = new CoalescingChainHeadChannel(eventChannels.getPublisher(ChainHeadChannel.class), EVENT_LOG);
StorageQueryChannel storageQueryChannel = eventChannels.getPublisher(StorageQueryChannel.class, beaconAsyncRunner);
StorageUpdateChannel storageUpdateChannel = eventChannels.getPublisher(StorageUpdateChannel.class, beaconAsyncRunner);
final VoteUpdateChannel voteUpdateChannel = eventChannels.getPublisher(VoteUpdateChannel.class);
return initWeakSubjectivity(storageQueryChannel, storageUpdateChannel).thenCompose(__ -> StorageBackedRecentChainData.create(metricsSystem, storeConfig, beaconAsyncRunner, storageQueryChannel, storageUpdateChannel, voteUpdateChannel, eventChannels.getPublisher(FinalizedCheckpointChannel.class, beaconAsyncRunner), coalescingChainHeadChannel, spec)).thenCompose(client -> {
// Setup chain storage
this.recentChainData = client;
if (recentChainData.isPreGenesis()) {
setupInitialState(client);
} else if (beaconConfig.eth2NetworkConfig().isUsingCustomInitialState()) {
STATUS_LOG.warnInitialStateIgnored();
}
return SafeFuture.completedFuture(client);
}).thenAccept(client -> {
// Init other services
this.initAll();
eventChannels.subscribe(TimeTickChannel.class, this);
recentChainData.subscribeStoreInitialized(this::onStoreInitialized);
recentChainData.subscribeBestBlockInitialized(this::startServices);
});
}
use of tech.pegasys.teku.storage.api.StorageQueryChannel in project teku by ConsenSys.
the class StateSelectorFactoryTest method stateSelector_shouldReturnEmptyWhenPreForkChoice.
@Test
public void stateSelector_shouldReturnEmptyWhenPreForkChoice() {
final StorageQueryChannel historicalChainData = mock(StorageQueryChannel.class);
final RecentChainData recentChainData = mock(RecentChainData.class);
final CombinedChainDataClient client1 = new CombinedChainDataClient(recentChainData, historicalChainData, spec);
final StateSelectorFactory factory = new StateSelectorFactory(spec, client1);
when(recentChainData.isPreGenesis()).thenReturn(false);
when(recentChainData.isPreForkChoice()).thenReturn(true);
final SafeFuture<Optional<StateAndMetaData>> future = factory.defaultStateSelector(ZERO.toString()).getState();
assertThatSafeFuture(future).isCompletedWithEmptyOptional();
}
Aggregations