Skip to content

Commit

Permalink
add option to enable attestations V2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Jul 19, 2024
1 parent fc13e5f commit d04d76f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ public class ValidatorOptions {
fallbackValue = "true")
private boolean blockV3Enabled = ValidatorConfig.DEFAULT_BLOCK_V3_ENABLED;

@Option(
names = {"--Xattestations-v2-enabled"},
paramLabel = "<BOOLEAN>",
description = "Enable the Attestations V2 API for attestations pool",
hidden = true,
showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
arity = "0..1",
fallbackValue = "true")
private boolean attestationsV2Enabled = ValidatorConfig.DEFAULT_ATTESTATIONS_V2_ENABLED;

@Option(
names = {"--exit-when-no-validator-keys-enabled"},
paramLabel = "<BOOLEAN>",
Expand Down Expand Up @@ -196,6 +206,7 @@ public void configure(final TekuConfiguration.Builder builder) {
.doppelgangerDetectionEnabled(doppelgangerDetectionEnabled)
.executorThreads(executorThreads)
.blockV3enabled(blockV3Enabled)
.attestationsV2Enabled(attestationsV2Enabled)
.exitWhenNoValidatorKeysEnabled(exitWhenNoValidatorKeysEnabled)
.shutdownWhenValidatorSlashedEnabled(shutdownWhenValidatorSlashed);
executorMaxQueueSize.ifPresent(config::executorMaxQueueSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ValidatorConfig {
public static final boolean DEFAULT_FAILOVERS_SEND_SUBNET_SUBSCRIPTIONS_ENABLED = true;
public static final boolean DEFAULT_FAILOVERS_PUBLISH_SIGNED_DUTIES_ENABLED = true;
public static final boolean DEFAULT_BLOCK_V3_ENABLED = false;
public static final boolean DEFAULT_ATTESTATIONS_V2_ENABLED = false;
public static final boolean DEFAULT_EXIT_WHEN_NO_VALIDATOR_KEYS_ENABLED = false;
public static final boolean DEFAULT_VALIDATOR_CLIENT_SSZ_BLOCKS_ENABLED = true;
public static final boolean DEFAULT_VALIDATOR_CLIENT_USE_POST_VALIDATORS_ENDPOINT_ENABLED = true;
Expand Down Expand Up @@ -99,6 +100,7 @@ public class ValidatorConfig {
private final boolean failoversSendSubnetSubscriptionsEnabled;
private final boolean failoversPublishSignedDutiesEnabled;
private final boolean blockV3Enabled;
private final boolean attestationsV2enabled;
private final boolean exitWhenNoValidatorKeysEnabled;
private final boolean shutdownWhenValidatorSlashedEnabled;
private final UInt64 builderRegistrationDefaultGasLimit;
Expand Down Expand Up @@ -142,6 +144,7 @@ private ValidatorConfig(
final boolean failoversSendSubnetSubscriptionsEnabled,
final boolean failoversPublishSignedDutiesEnabled,
final boolean blockV3Enabled,
final boolean attestationsV2enabled,
final boolean exitWhenNoValidatorKeysEnabled,
final boolean shutdownWhenValidatorSlashedEnabled,
final UInt64 builderRegistrationDefaultGasLimit,
Expand Down Expand Up @@ -185,6 +188,7 @@ private ValidatorConfig(
this.failoversSendSubnetSubscriptionsEnabled = failoversSendSubnetSubscriptionsEnabled;
this.failoversPublishSignedDutiesEnabled = failoversPublishSignedDutiesEnabled;
this.blockV3Enabled = blockV3Enabled;
this.attestationsV2enabled = attestationsV2enabled;
this.exitWhenNoValidatorKeysEnabled = exitWhenNoValidatorKeysEnabled;
this.shutdownWhenValidatorSlashedEnabled = shutdownWhenValidatorSlashedEnabled;
this.builderRegistrationDefaultGasLimit = builderRegistrationDefaultGasLimit;
Expand Down Expand Up @@ -329,6 +333,10 @@ public boolean isBlockV3Enabled() {
return blockV3Enabled;
}

public boolean isAttestationsV2Enabled() {
return attestationsV2enabled;
}

public boolean isExitWhenNoValidatorKeysEnabled() {
return exitWhenNoValidatorKeysEnabled;
}
Expand Down Expand Up @@ -409,6 +417,7 @@ public static final class Builder {
private boolean failoversPublishSignedDutiesEnabled =
DEFAULT_FAILOVERS_PUBLISH_SIGNED_DUTIES_ENABLED;
private boolean blockV3Enabled = DEFAULT_BLOCK_V3_ENABLED;
private boolean attestationsV2Enabled = DEFAULT_ATTESTATIONS_V2_ENABLED;
private boolean exitWhenNoValidatorKeysEnabled = DEFAULT_EXIT_WHEN_NO_VALIDATOR_KEYS_ENABLED;
private boolean shutdownWhenValidatorSlashedEnabled =
DEFAULT_SHUTDOWN_WHEN_VALIDATOR_SLASHED_ENABLED;
Expand Down Expand Up @@ -614,6 +623,11 @@ public Builder blockV3enabled(final boolean useBlockV3) {
return this;
}

public Builder attestationsV2Enabled(final boolean useAttestationsV2) {
this.attestationsV2Enabled = useAttestationsV2;
return this;
}

public Builder exitWhenNoValidatorKeysEnabled(final boolean exitWhenNoValidatorKeysEnabled) {
this.exitWhenNoValidatorKeysEnabled = exitWhenNoValidatorKeysEnabled;
return this;
Expand Down Expand Up @@ -716,6 +730,7 @@ public ValidatorConfig build() {
failoversSendSubnetSubscriptionsEnabled,
failoversPublishSignedDutiesEnabled,
blockV3Enabled,
attestationsV2Enabled,
exitWhenNoValidatorKeysEnabled,
shutdownWhenValidatorSlashedEnabled,
builderRegistrationDefaultGasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,12 @@ private void scheduleValidatorsDuties(
spec,
validatorDutyMetrics);
final AttestationDutyFactory attestationDutyFactory =
new AttestationDutyFactory(spec, forkProvider, validatorApiChannel, validatorDutyMetrics);
new AttestationDutyFactory(
spec,
forkProvider,
validatorApiChannel,
validatorDutyMetrics,
config.getValidatorConfig().isAttestationsV2Enabled());
final BeaconCommitteeSubscriptions beaconCommitteeSubscriptions =
new BeaconCommitteeSubscriptions(validatorApiChannel);
final boolean dvtSelectionsEndpointEnabled =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ public class AttestationDutyFactory
private final Spec spec;
private final ForkProvider forkProvider;
private final ValidatorApiChannel validatorApiChannel;

private final ValidatorDutyMetrics validatorDutyMetrics;
private final boolean attestationsV2Enabled;

public AttestationDutyFactory(
final Spec spec,
final ForkProvider forkProvider,
final ValidatorApiChannel validatorApiChannel,
final ValidatorDutyMetrics validatorDutyMetrics) {
final ValidatorDutyMetrics validatorDutyMetrics,
final boolean attestationsV2Enabled) {
this.spec = spec;
this.forkProvider = forkProvider;
this.validatorApiChannel = validatorApiChannel;
this.validatorDutyMetrics = validatorDutyMetrics;
this.attestationsV2Enabled = attestationsV2Enabled;
}

@Override
Expand All @@ -51,7 +53,15 @@ public AttestationProductionDuty createProductionDuty(
slot,
forkProvider,
validatorApiChannel,
new BatchAttestationSendingStrategy<>(validatorApiChannel::sendSignedAttestations),
new BatchAttestationSendingStrategy<>(
attestations -> {
if (attestationsV2Enabled) {
return validatorApiChannel.sendSignedAttestationsV2(
spec.atSlot(slot).getMilestone(), attestations);
} else {
return validatorApiChannel.sendSignedAttestations(attestations);
}
}),
validatorDutyMetrics);
}

Expand Down

0 comments on commit d04d76f

Please sign in to comment.