Search in sources :

Example 1 with StorageQueryChannel

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));
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with StorageQueryChannel

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);
    });
}
Also used : SyncCommitteePerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.SyncCommitteePerformanceTracker) SyncCommitteeSubscriptionManager(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager) Eth2P2PNetwork(tech.pegasys.teku.networking.eth2.Eth2P2PNetwork) SyncCommitteeStateUtils(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils) TimeProvider(tech.pegasys.teku.infrastructure.time.TimeProvider) VersionProvider(tech.pegasys.teku.infrastructure.version.VersionProvider) SyncServiceFactory(tech.pegasys.teku.beacon.sync.SyncServiceFactory) OperationPool(tech.pegasys.teku.statetransition.OperationPool) StableSubnetSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.StableSubnetSubscriber) AggregateAttestationValidator(tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel) EpochCachePrimer(tech.pegasys.teku.statetransition.EpochCachePrimer) Duration(java.time.Duration) Path(java.nio.file.Path) Service(tech.pegasys.teku.service.serviceutils.Service) SyncService(tech.pegasys.teku.beacon.sync.SyncService) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) OperationsReOrgManager(tech.pegasys.teku.statetransition.OperationsReOrgManager) ValidatorBasedStableSubnetSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.ValidatorBasedStableSubnetSubscriber) NoOpPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.NoOpPerformanceTracker) SyncCommitteeMessageValidator(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator) TerminalPowBlockMonitor(tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor) ActiveValidatorTracker(tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker) AttestationValidator(tech.pegasys.teku.statetransition.validation.AttestationValidator) Logger(org.apache.logging.log4j.Logger) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) BlockManager(tech.pegasys.teku.statetransition.block.BlockManager) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) Bytes(org.apache.tuweni.bytes.Bytes) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) FileKeyValueStore(tech.pegasys.teku.storage.store.FileKeyValueStore) SyncCommitteeMessagePool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignatureVerificationService(tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService) ZERO(tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) FinalizedCheckpointChannel(tech.pegasys.teku.storage.api.FinalizedCheckpointChannel) ForkChoiceNotifierImpl(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl) AttestationManager(tech.pegasys.teku.statetransition.attestation.AttestationManager) DiscoveryConfig(tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig) Throwables(com.google.common.base.Throwables) InteropStartupUtil(tech.pegasys.teku.spec.datastructures.interop.InteropStartupUtil) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) ServiceConfig(tech.pegasys.teku.service.serviceutils.ServiceConfig) PerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) CoalescingChainHeadChannel(tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel) STATUS_LOG(tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) StorageBackedRecentChainData(tech.pegasys.teku.storage.client.StorageBackedRecentChainData) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException) ValidatorPerformanceTrackingMode(tech.pegasys.teku.validator.api.ValidatorPerformanceTrackingMode) Random(java.util.Random) AggregatingAttestationPool(tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool) Eth1VotingPeriod(tech.pegasys.teku.validator.coordinator.Eth1VotingPeriod) P2PConfig(tech.pegasys.teku.networking.eth2.P2PConfig) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ProposerSlashingValidator(tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator) BeaconBlockBodySchema(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) ActiveValidatorChannel(tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel) Eth1DataCache(tech.pegasys.teku.validator.coordinator.Eth1DataCache) DefaultPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker) BlockFactory(tech.pegasys.teku.validator.coordinator.BlockFactory) ValidatorApiHandler(tech.pegasys.teku.validator.coordinator.ValidatorApiHandler) DepositProvider(tech.pegasys.teku.validator.coordinator.DepositProvider) TimeTickChannel(tech.pegasys.teku.services.timer.TimeTickChannel) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) OperationAcceptedFilter(tech.pegasys.teku.statetransition.OperationAcceptedFilter) BlockValidator(tech.pegasys.teku.statetransition.validation.BlockValidator) FutureItems(tech.pegasys.teku.statetransition.util.FutureItems) AttesterSlashingValidator(tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator) BlockOperationSelectorFactory(tech.pegasys.teku.validator.coordinator.BlockOperationSelectorFactory) SyncCommitteeContributionPool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool) AsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory) ForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier) Optional(java.util.Optional) PortAvailability(tech.pegasys.teku.infrastructure.io.PortAvailability) VoteUpdateChannel(tech.pegasys.teku.storage.api.VoteUpdateChannel) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) ActiveValidatorCache(tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache) SignedContributionAndProofValidator(tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) ChainHeadChannel(tech.pegasys.teku.storage.api.ChainHeadChannel) ReexecutingExecutionPayloadBlockManager(tech.pegasys.teku.statetransition.block.ReexecutingExecutionPayloadBlockManager) ForkChoiceTrigger(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger) AttestationTopicSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber) BindException(java.net.BindException) DutyMetrics(tech.pegasys.teku.validator.coordinator.DutyMetrics) Function(java.util.function.Function) NoOpEth2P2PNetwork(tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork) ValidatorPerformanceMetrics(tech.pegasys.teku.validator.coordinator.performance.ValidatorPerformanceMetrics) KeyValueStore(tech.pegasys.teku.storage.store.KeyValueStore) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) PendingPool(tech.pegasys.teku.statetransition.util.PendingPool) Bytes20(tech.pegasys.teku.infrastructure.bytes.Bytes20) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) Spec(tech.pegasys.teku.spec.Spec) AggregatingSignatureVerificationService(tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService) SlotEventsChannel(tech.pegasys.teku.ethereum.events.SlotEventsChannel) VoluntaryExitValidator(tech.pegasys.teku.statetransition.validation.VoluntaryExitValidator) EVENT_LOG(tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG) StorageUpdateChannel(tech.pegasys.teku.storage.api.StorageUpdateChannel) AllSubnetsSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AllSubnetsSubscriber) BeaconRestApi(tech.pegasys.teku.beaconrestapi.BeaconRestApi) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) GenesisHandler(tech.pegasys.teku.statetransition.genesis.GenesisHandler) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) DataProvider(tech.pegasys.teku.api.DataProvider) AllSyncCommitteeSubscriptions(tech.pegasys.teku.networking.eth2.gossip.subnets.AllSyncCommitteeSubscriptions) Eth1EventsChannel(tech.pegasys.teku.pow.api.Eth1EventsChannel) InteropConfig(tech.pegasys.teku.validator.api.InteropConfig) AsyncRunnerEventThread(tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) CoalescingChainHeadChannel(tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) VoteUpdateChannel(tech.pegasys.teku.storage.api.VoteUpdateChannel) StorageUpdateChannel(tech.pegasys.teku.storage.api.StorageUpdateChannel)

Example 3 with StorageQueryChannel

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();
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) Optional(java.util.Optional) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) Test(org.junit.jupiter.api.Test)

Aggregations

StorageQueryChannel (tech.pegasys.teku.storage.api.StorageQueryChannel)3 CombinedChainDataClient (tech.pegasys.teku.storage.client.CombinedChainDataClient)3 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)3 Optional (java.util.Optional)2 Throwables (com.google.common.base.Throwables)1 BindException (java.net.BindException)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Comparator (java.util.Comparator)1 Random (java.util.Random)1 Function (java.util.function.Function)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Bytes (org.apache.tuweni.bytes.Bytes)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ChainDataProvider (tech.pegasys.teku.api.ChainDataProvider)1 DataProvider (tech.pegasys.teku.api.DataProvider)1 SyncService (tech.pegasys.teku.beacon.sync.SyncService)1