From d04d76ff8835c666de8d3b69c5776752d2bdadd6 Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Fri, 19 Jul 2024 17:40:29 +0200 Subject: [PATCH] add option to enable attestations V2 API --- .../teku/cli/options/ValidatorOptions.java | 11 +++++++++++ .../teku/validator/api/ValidatorConfig.java | 15 +++++++++++++++ .../validator/client/ValidatorClientService.java | 7 ++++++- .../attestations/AttestationDutyFactory.java | 16 +++++++++++++--- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/teku/src/main/java/tech/pegasys/teku/cli/options/ValidatorOptions.java b/teku/src/main/java/tech/pegasys/teku/cli/options/ValidatorOptions.java index 3eeb2d07de8..42e050a621e 100644 --- a/teku/src/main/java/tech/pegasys/teku/cli/options/ValidatorOptions.java +++ b/teku/src/main/java/tech/pegasys/teku/cli/options/ValidatorOptions.java @@ -148,6 +148,16 @@ public class ValidatorOptions { fallbackValue = "true") private boolean blockV3Enabled = ValidatorConfig.DEFAULT_BLOCK_V3_ENABLED; + @Option( + names = {"--Xattestations-v2-enabled"}, + paramLabel = "", + 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 = "", @@ -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); diff --git a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorConfig.java b/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorConfig.java index 81a1bf3b81a..98f3a65b1a3 100644 --- a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorConfig.java +++ b/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorConfig.java @@ -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; @@ -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; @@ -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, @@ -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; @@ -329,6 +333,10 @@ public boolean isBlockV3Enabled() { return blockV3Enabled; } + public boolean isAttestationsV2Enabled() { + return attestationsV2enabled; + } + public boolean isExitWhenNoValidatorKeysEnabled() { return exitWhenNoValidatorKeysEnabled; } @@ -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; @@ -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; @@ -716,6 +730,7 @@ public ValidatorConfig build() { failoversSendSubnetSubscriptionsEnabled, failoversPublishSignedDutiesEnabled, blockV3Enabled, + attestationsV2Enabled, exitWhenNoValidatorKeysEnabled, shutdownWhenValidatorSlashedEnabled, builderRegistrationDefaultGasLimit, diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java index 2916633f3b1..8e2a3f5a6a4 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java @@ -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 = diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationDutyFactory.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationDutyFactory.java index f0bbeafe82e..1ad7043c0fe 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationDutyFactory.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationDutyFactory.java @@ -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 @@ -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); }