Skip to content

Commit

Permalink
Capture time taken creating, signing and sending blocks on block prod…
Browse files Browse the repository at this point in the history
…uction duty
  • Loading branch information
courtneyeh committed Oct 24, 2023
1 parent c85516c commit a2f526f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,19 @@ private void scheduleValidatorsDuties(
validatorTimingChannels.add(validatorStatusProvider);
final OwnedValidators validators = validatorLoader.getOwnedValidators();
final BlockContainerSigner blockContainerSigner = new MilestoneBasedBlockContainerSigner(spec);
final ValidatorDutyMetrics validatorDutyMetrics = ValidatorDutyMetrics.create(metricsSystem);
final BlockDutyFactory blockDutyFactory =
new BlockDutyFactory(
forkProvider,
validatorApiChannel,
blockContainerSigner,
config.getValidatorConfig().isBlindedBeaconBlocksEnabled(),
spec);
spec,
validatorDutyMetrics);
final AttestationDutyFactory attestationDutyFactory =
new AttestationDutyFactory(spec, forkProvider, validatorApiChannel);
final BeaconCommitteeSubscriptions beaconCommitteeSubscriptions =
new BeaconCommitteeSubscriptions(validatorApiChannel);
final ValidatorDutyMetrics validatorDutyMetrics = ValidatorDutyMetrics.create(metricsSystem);
final DutyLoader<?> attestationDutyLoader =
new RetryingDutyLoader<>(
asyncRunner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ public class BlockDutyFactory implements DutyFactory<BlockProductionDuty, Duty>
private final BlockContainerSigner blockContainerSigner;
private final Spec spec;
private final boolean useBlindedBlock;
private final ValidatorDutyMetrics validatorDutyMetrics;

public BlockDutyFactory(
final ForkProvider forkProvider,
final ValidatorApiChannel validatorApiChannel,
final BlockContainerSigner blockContainerSigner,
final boolean useBlindedBlock,
final Spec spec) {
final Spec spec,
final ValidatorDutyMetrics validatorDutyMetrics) {
this.forkProvider = forkProvider;
this.validatorApiChannel = validatorApiChannel;
this.blockContainerSigner = blockContainerSigner;
this.useBlindedBlock = useBlindedBlock;
this.spec = spec;
this.validatorDutyMetrics = validatorDutyMetrics;
}

@Override
Expand All @@ -50,7 +53,8 @@ public BlockProductionDuty createProductionDuty(final UInt64 slot, final Validat
validatorApiChannel,
blockContainerSigner,
useBlindedBlock,
spec);
spec,
validatorDutyMetrics);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class BlockProductionDuty implements Duty {
private final BlockContainerSigner blockContainerSigner;
private final boolean useBlindedBlock;
private final Spec spec;
private final ValidatorDutyMetrics validatorDutyMetrics;

public BlockProductionDuty(
final Validator validator,
Expand All @@ -52,14 +53,16 @@ public BlockProductionDuty(
final ValidatorApiChannel validatorApiChannel,
final BlockContainerSigner blockContainerSigner,
final boolean useBlindedBlock,
final Spec spec) {
final Spec spec,
final ValidatorDutyMetrics validatorDutyMetrics) {
this.validator = validator;
this.slot = slot;
this.forkProvider = forkProvider;
this.validatorApiChannel = validatorApiChannel;
this.blockContainerSigner = blockContainerSigner;
this.useBlindedBlock = useBlindedBlock;
this.spec = spec;
this.validatorDutyMetrics = validatorDutyMetrics;
}

@Override
Expand All @@ -74,10 +77,18 @@ public SafeFuture<DutyResult> performDuty() {
}

public SafeFuture<DutyResult> produceBlock(final ForkInfo forkInfo) {
final String dutyType = getType().getType();
return createRandaoReveal(forkInfo)
.thenCompose(this::createUnsignedBlock)
.thenCompose(unsignedBlock -> signBlockContainer(forkInfo, unsignedBlock))
.thenCompose(this::sendBlock)
.thenCompose(
signature ->
validatorDutyMetrics.record(() -> createUnsignedBlock(signature), dutyType, "create"))
.thenCompose(
unsignedBlock ->
validatorDutyMetrics.record(
() -> signBlockContainer(forkInfo, unsignedBlock), dutyType, "sign"))
.thenCompose(
signedBlockContainer ->
validatorDutyMetrics.record(() -> sendBlock(signedBlockContainer), dutyType, "send"))
.exceptionally(error -> DutyResult.forError(validator.getPublicKey(), error));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.validator.client.duties;

import java.util.function.Supplier;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.plugin.services.metrics.OperationTimer;
Expand All @@ -38,9 +39,22 @@ public static ValidatorDutyMetrics create(final MetricsSystem metricsSystem) {
}

public SafeFuture<DutyResult> performDutyWithMetrics(final Duty duty) {
final String dutyType = duty.getType().getType();
final OperationTimer timer = dutyMetric.labels(dutyType, "total");
final OperationTimer.TimingContext context = timer.startTimer();
final OperationTimer.TimingContext context = startTimer(getDutyType(duty), "total");
return duty.performDuty().alwaysRun(context::stopTimer);
}

private OperationTimer.TimingContext startTimer(final String dutyType, final String step) {
final OperationTimer timer = dutyMetric.labels(dutyType, step);
return timer.startTimer();
}

private static String getDutyType(final Duty duty) {
return duty.getType().getType();
}

public <T> SafeFuture<T> record(
final Supplier<SafeFuture<T>> supplier, final String dutyType, final String step) {
final OperationTimer.TimingContext context = startTimer(dutyType, step);
return supplier.get().alwaysRun(context::stopTimer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void setUp() {
validatorApiChannel,
blockContainerSigner,
false,
spec);
spec,
mock(ValidatorDutyMetrics.class)); // todo fix
when(forkProvider.getForkInfo(any())).thenReturn(completedFuture(fork));
}

Expand All @@ -119,7 +120,8 @@ public void shouldCreateAndPublishBlock(final boolean isBlindedBlocksEnabled) {
validatorApiChannel,
blockContainerSigner,
isBlindedBlocksEnabled,
spec);
spec,
mock(ValidatorDutyMetrics.class)); // todo fix
final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
final BLSSignature blockSignature = dataStructureUtil.randomSignature();
final BeaconBlock unsignedBlock;
Expand Down Expand Up @@ -164,7 +166,8 @@ public void forDeneb_shouldCreateAndPublishBlockContents() {
validatorApiChannel,
blockContainerSigner,
false,
spec);
spec,
mock(ValidatorDutyMetrics.class)); // todo fix

final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
final BLSSignature blockSignature = dataStructureUtil.randomSignature();
Expand Down Expand Up @@ -244,7 +247,8 @@ public void forDeneb_shouldCreateAndPublishBlindedBlockContents() {
validatorApiChannel,
blockContainerSigner,
true,
spec);
spec,
mock(ValidatorDutyMetrics.class)); // todo fix

final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
final BLSSignature blockSignature = dataStructureUtil.randomSignature();
Expand Down

0 comments on commit a2f526f

Please sign in to comment.