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));
}
}
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);
});
}
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);
}
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);
}
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();
});
}
Aggregations