Search in sources :

Example 1 with MetricsSystem

use of org.hyperledger.besu.plugin.services.MetricsSystem in project teku by ConsenSys.

the class AggregatingSignatureVerificationServiceTest method testRealServiceWithThreads.

@Test
public void testRealServiceWithThreads() throws Exception {
    final MetricsSystem metrics = new StubMetricsSystem();
    final AsyncRunnerFactory realRunnerFactory = AsyncRunnerFactory.createDefault(new MetricTrackingExecutorFactory(metrics));
    service = new AggregatingSignatureVerificationService(metrics, realRunnerFactory, realRunnerFactory.create("completion", 1), 1, queueCapacity, batchSize, minBatchSizeToSplit, strictThreadLimitEnabled);
    startService();
    final Random random = new Random(1);
    for (int i = 0; i < 3; i++) {
        final List<SafeFuture<Boolean>> validFutures = new ArrayList<>();
        final List<SafeFuture<Boolean>> invalidFutures = new ArrayList<>();
        for (int j = 0; j < queueCapacity - i; j++) {
            if (random.nextFloat() < .5) {
                validFutures.add(executeValidVerify(j, j));
            } else {
                invalidFutures.add(executeInvalidVerify(j, j));
            }
        }
        final List<SafeFuture<Boolean>> allFutures = new ArrayList<>();
        allFutures.addAll(validFutures);
        allFutures.addAll(invalidFutures);
        Waiter.waitFor(SafeFuture.allOf(allFutures.toArray(SafeFuture<?>[]::new)), Duration.ofSeconds(5));
        validFutures.forEach(f -> assertThat(f).isCompletedWithValue(true));
        invalidFutures.forEach(f -> assertThat(f).isCompletedWithValue(false));
    }
}
Also used : StubAsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.StubAsyncRunnerFactory) AsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory) Random(java.util.Random) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) MetricTrackingExecutorFactory(tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory) ArrayList(java.util.ArrayList) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) Test(org.junit.jupiter.api.Test)

Example 2 with MetricsSystem

use of org.hyperledger.besu.plugin.services.MetricsSystem 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 MetricsSystem

use of org.hyperledger.besu.plugin.services.MetricsSystem in project teku by ConsenSys.

the class ValidatorClientService method initializeValidators.

private void initializeValidators(ValidatorClientConfiguration config, ValidatorApiChannel validatorApiChannel, AsyncRunner asyncRunner) {
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    this.validatorIndexProvider = new ValidatorIndexProvider(validators, validatorApiChannel, asyncRunner);
    final BlockDutyFactory blockDutyFactory = new BlockDutyFactory(forkProvider, validatorApiChannel, spec);
    final AttestationDutyFactory attestationDutyFactory = new AttestationDutyFactory(spec, forkProvider, validatorApiChannel);
    final BeaconCommitteeSubscriptions beaconCommitteeSubscriptions = new BeaconCommitteeSubscriptions(validatorApiChannel);
    final DutyLoader<?> attestationDutyLoader = new RetryingDutyLoader<>(asyncRunner, new AttestationDutyLoader(validatorApiChannel, forkProvider, dependentRoot -> new SlotBasedScheduledDuties<>(attestationDutyFactory, dependentRoot), validators, validatorIndexProvider, beaconCommitteeSubscriptions, spec));
    final DutyLoader<?> blockDutyLoader = new RetryingDutyLoader<>(asyncRunner, new BlockProductionDutyLoader(validatorApiChannel, dependentRoot -> new SlotBasedScheduledDuties<>(blockDutyFactory, dependentRoot), validators, validatorIndexProvider));
    validatorTimingChannels.add(new BlockDutyScheduler(metricsSystem, blockDutyLoader, spec));
    validatorTimingChannels.add(new AttestationDutyScheduler(metricsSystem, attestationDutyLoader, spec));
    validatorTimingChannels.add(validatorLoader.getSlashingProtectionLogger());
    if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
        final ChainHeadTracker chainHeadTracker = new ChainHeadTracker();
        validatorTimingChannels.add(chainHeadTracker);
        final DutyLoader<SyncCommitteeScheduledDuties> syncCommitteeDutyLoader = new RetryingDutyLoader<>(asyncRunner, new SyncCommitteeDutyLoader(validators, validatorIndexProvider, spec, validatorApiChannel, chainHeadTracker, forkProvider));
        validatorTimingChannels.add(new SyncCommitteeScheduler(metricsSystem, spec, syncCommitteeDutyLoader, new Random()::nextInt));
    }
    if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) {
        proposerConfigProvider = Optional.of(ProposerConfigProvider.create(asyncRunner, config.getValidatorConfig().getRefreshProposerConfigFromSource(), new ProposerConfigLoader(new JsonProvider().getObjectMapper()), config.getValidatorConfig().getProposerConfigSource()));
        validatorTimingChannels.add(new BeaconProposerPreparer(validatorApiChannel, validatorIndexProvider, proposerConfigProvider.get(), config.getValidatorConfig().getProposerDefaultFeeRecipient(), spec));
    } else {
        proposerConfigProvider = Optional.empty();
    }
    addValidatorCountMetric(metricsSystem, validators);
    this.validatorStatusLogger = new DefaultValidatorStatusLogger(metricsSystem, validators, validatorApiChannel, asyncRunner);
}
Also used : AttestationDutyFactory(tech.pegasys.teku.validator.client.duties.attestations.AttestationDutyFactory) BlockDutyFactory(tech.pegasys.teku.validator.client.duties.BlockDutyFactory) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig) Random(java.util.Random) LocalSlashingProtector(tech.pegasys.teku.core.signatures.LocalSlashingProtector) ArrayList(java.util.ArrayList) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) PublicKeyLoader(tech.pegasys.teku.validator.client.loader.PublicKeyLoader) SlotBasedScheduledDuties(tech.pegasys.teku.validator.client.duties.SlotBasedScheduledDuties) JsonProvider(tech.pegasys.teku.provider.JsonProvider) ChainHeadTracker(tech.pegasys.teku.validator.client.duties.synccommittee.ChainHeadTracker) BeaconCommitteeSubscriptions(tech.pegasys.teku.validator.client.duties.BeaconCommitteeSubscriptions) Spec(tech.pegasys.teku.spec.Spec) Path(java.nio.file.Path) Service(tech.pegasys.teku.service.serviceutils.Service) ProposerConfigProvider(tech.pegasys.teku.validator.client.proposerconfig.ProposerConfigProvider) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) SyncDataAccessor(tech.pegasys.teku.infrastructure.io.SyncDataAccessor) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) ServiceConfig(tech.pegasys.teku.service.serviceutils.ServiceConfig) BeaconNodeApi(tech.pegasys.teku.validator.beaconnode.BeaconNodeApi) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) InProcessBeaconNodeApi(tech.pegasys.teku.validator.eventadapter.InProcessBeaconNodeApi) OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) SlashingProtector(tech.pegasys.teku.core.signatures.SlashingProtector) SystemSignalListener(tech.pegasys.teku.infrastructure.io.SystemSignalListener) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) ProposerConfigLoader(tech.pegasys.teku.validator.client.proposerconfig.loader.ProposerConfigLoader) SlashingProtectionLogger(tech.pegasys.teku.validator.client.loader.SlashingProtectionLogger) Optional(java.util.Optional) RemoteBeaconNodeApi(tech.pegasys.teku.validator.remote.RemoteBeaconNodeApi) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) LogManager(org.apache.logging.log4j.LogManager) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) AttestationDutyFactory(tech.pegasys.teku.validator.client.duties.attestations.AttestationDutyFactory) BlockDutyFactory(tech.pegasys.teku.validator.client.duties.BlockDutyFactory) ChainHeadTracker(tech.pegasys.teku.validator.client.duties.synccommittee.ChainHeadTracker) OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) BeaconCommitteeSubscriptions(tech.pegasys.teku.validator.client.duties.BeaconCommitteeSubscriptions) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) ProposerConfigLoader(tech.pegasys.teku.validator.client.proposerconfig.loader.ProposerConfigLoader) JsonProvider(tech.pegasys.teku.provider.JsonProvider) SlotBasedScheduledDuties(tech.pegasys.teku.validator.client.duties.SlotBasedScheduledDuties) Random(java.util.Random)

Example 4 with MetricsSystem

use of org.hyperledger.besu.plugin.services.MetricsSystem in project teku by ConsenSys.

the class InProcessBeaconNodeApi method create.

public static BeaconNodeApi create(final ServiceConfig services, final AsyncRunner asyncRunner, final boolean generateEarlyAttestations, final Spec spec) {
    final MetricsSystem metricsSystem = services.getMetricsSystem();
    final EventChannels eventChannels = services.getEventChannels();
    final ValidatorApiChannel validatorApiChannel = new MetricRecordingValidatorApiChannel(metricsSystem, eventChannels.getPublisher(ValidatorApiChannel.class, asyncRunner));
    final ValidatorTimingChannel validatorTimingChannel = eventChannels.getPublisher(ValidatorTimingChannel.class);
    final TimeBasedEventAdapter timeBasedEventAdapter = new TimeBasedEventAdapter(new GenesisDataProvider(asyncRunner, validatorApiChannel), new RepeatingTaskScheduler(asyncRunner, services.getTimeProvider()), services.getTimeProvider(), validatorTimingChannel, spec);
    final BeaconChainEventAdapter beaconChainEventAdapter = new IndependentTimerEventChannelEventAdapter(eventChannels, generateEarlyAttestations, timeBasedEventAdapter, validatorTimingChannel);
    return new InProcessBeaconNodeApi(validatorApiChannel, beaconChainEventAdapter);
}
Also used : MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) BeaconChainEventAdapter(tech.pegasys.teku.validator.beaconnode.BeaconChainEventAdapter) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) RepeatingTaskScheduler(tech.pegasys.teku.infrastructure.async.timed.RepeatingTaskScheduler) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) TimeBasedEventAdapter(tech.pegasys.teku.validator.beaconnode.TimeBasedEventAdapter)

Example 5 with MetricsSystem

use of org.hyperledger.besu.plugin.services.MetricsSystem in project besu by hyperledger.

the class FastSyncTargetManager method confirmPivotBlockHeader.

private CompletableFuture<Optional<EthPeer>> confirmPivotBlockHeader(final EthPeer bestPeer) {
    final BlockHeader pivotBlockHeader = fastSyncState.getPivotBlockHeader().get();
    final RetryingGetHeaderFromPeerByNumberTask task = RetryingGetHeaderFromPeerByNumberTask.forSingleNumber(protocolSchedule, ethContext, metricsSystem, pivotBlockHeader.getNumber(), MAX_QUERY_RETRIES_PER_PEER);
    task.assignPeer(bestPeer);
    return ethContext.getScheduler().timeout(task).thenCompose(result -> {
        if (peerHasDifferentPivotBlock(result)) {
            if (!hasPivotChanged(pivotBlockHeader)) {
                // if the pivot block has not changed, then warn and disconnect this peer
                LOG.warn("Best peer has wrong pivot block (#{}) expecting {} but received {}.  Disconnect: {}", pivotBlockHeader.getNumber(), pivotBlockHeader.getHash(), result.size() == 1 ? result.get(0).getHash() : "invalid response", bestPeer);
                bestPeer.disconnect(DisconnectReason.USELESS_PEER);
                return CompletableFuture.completedFuture(Optional.<EthPeer>empty());
            }
            LOG.debug("Retrying best peer {} with new pivot block {}", bestPeer.getShortNodeId(), pivotBlockHeader.toLogString());
            return confirmPivotBlockHeader(bestPeer);
        } else {
            return CompletableFuture.completedFuture(Optional.of(bestPeer));
        }
    }).exceptionally(error -> {
        LOG.debug("Could not confirm best peer had pivot block", error);
        return Optional.empty();
    });
}
Also used : Logger(org.slf4j.Logger) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) SyncTargetManager(org.hyperledger.besu.ethereum.eth.sync.SyncTargetManager) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) LoggerFactory(org.slf4j.LoggerFactory) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) CompletableFuture(java.util.concurrent.CompletableFuture) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) List(java.util.List) RetryingGetHeaderFromPeerByNumberTask(org.hyperledger.besu.ethereum.eth.sync.tasks.RetryingGetHeaderFromPeerByNumberTask) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Optional(java.util.Optional) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MAX_QUERY_RETRIES_PER_PEER(org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotBlockRetriever.MAX_QUERY_RETRIES_PER_PEER) DisconnectReason(org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) RetryingGetHeaderFromPeerByNumberTask(org.hyperledger.besu.ethereum.eth.sync.tasks.RetryingGetHeaderFromPeerByNumberTask) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Aggregations

MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)19 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)10 Optional (java.util.Optional)7 Test (org.junit.Test)7 ObservableMetricsSystem (org.hyperledger.besu.metrics.ObservableMetricsSystem)6 List (java.util.List)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)5 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Bytes (org.apache.tuweni.bytes.Bytes)3 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 EthPeer (org.hyperledger.besu.ethereum.eth.manager.EthPeer)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3