Skip to content

Commit

Permalink
add shut down when validator slashed option
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Jan 24, 2024
1 parent 87a7f1e commit 5a93913
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static tech.pegasys.teku.networks.Eth2NetworkConfiguration.DEFAULT_VALIDATOR_EXECUTOR_THREADS;
import static tech.pegasys.teku.validator.api.ValidatorConfig.DEFAULT_DOPPELGANGER_DETECTION_ENABLED;
import static tech.pegasys.teku.validator.api.ValidatorConfig.DEFAULT_SHUTDOWN_WHEN_VALIDATOR_SLASHED_ENABLED;
import static tech.pegasys.teku.validator.api.ValidatorConfig.DEFAULT_VALIDATOR_IS_LOCAL_SLASHING_PROTECTION_SYNCHRONIZED_ENABLED;

import java.nio.file.Path;
Expand Down Expand Up @@ -152,6 +153,17 @@ public class ValidatorOptions {
private boolean isLocalSlashingProtectionSynchronizedEnabled =
DEFAULT_VALIDATOR_IS_LOCAL_SLASHING_PROTECTION_SYNCHRONIZED_ENABLED;

@Option(
names = {"--Xshut-down-when-validator-slashed-enabled"},
paramLabel = "<BOOLEAN>",
description =
"If an owned validator key is detected as slashed, the node should terminate with exit code 2. In this case, the service should not be restarted.",
showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
arity = "0..1",
hidden = true,
fallbackValue = "true")
private boolean shutdownWhenValidatorSlashed = DEFAULT_SHUTDOWN_WHEN_VALIDATOR_SLASHED_ENABLED;

public void configure(TekuConfiguration.Builder builder) {
builder.validator(
config ->
Expand All @@ -170,7 +182,8 @@ public void configure(TekuConfiguration.Builder builder) {
.doppelgangerDetectionEnabled(doppelgangerDetectionEnabled)
.executorThreads(executorThreads)
.blockV3enabled(blockV3Enabled)
.exitWhenNoValidatorKeysEnabled(exitWhenNoValidatorKeysEnabled));
.exitWhenNoValidatorKeysEnabled(exitWhenNoValidatorKeysEnabled)
.shutdownWhenValidatorSlashedEnabled(shutdownWhenValidatorSlashed));
validatorProposerOptions.configure(builder);
validatorKeysOptions.configure(builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,20 @@ public void shouldSetExitWhenNoValidatorKeysEnabled() {
.getValidatorConfig();
assertThat(config.isExitWhenNoValidatorKeysEnabled()).isTrue();
}

@Test
public void shouldDefaultFalseShutdownWhenValidatorSlashedEnabled() {
final ValidatorConfig config =
getTekuConfigurationFromArguments().validatorClient().getValidatorConfig();
assertThat(config.isShutdownWhenValidatorSlashedEnabled()).isFalse();
}

@Test
public void shouldSetShutdownWhenValidatorSlashedEnabled() {
final ValidatorConfig config =
getTekuConfigurationFromArguments("--Xshut-down-when-validator-slashed-enabled=true")
.validatorClient()
.getValidatorConfig();
assertThat(config.isShutdownWhenValidatorSlashedEnabled()).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ValidatorConfig {
public static final boolean DEFAULT_VALIDATOR_CLIENT_SSZ_BLOCKS_ENABLED = true;
public static final boolean DEFAULT_VALIDATOR_CLIENT_USE_POST_VALIDATORS_ENDPOINT_ENABLED = true;
public static final boolean DEFAULT_DOPPELGANGER_DETECTION_ENABLED = false;
public static final boolean DEFAULT_SHUTDOWN_WHEN_VALIDATOR_SLASHED_ENABLED = false;
public static final boolean DEFAULT_VALIDATOR_IS_LOCAL_SLASHING_PROTECTION_SYNCHRONIZED_ENABLED =
true;
public static final int DEFAULT_EXECUTOR_MAX_QUEUE_SIZE = 20_000;
Expand Down Expand Up @@ -93,6 +94,7 @@ public class ValidatorConfig {
private final boolean failoversPublishSignedDutiesEnabled;
private final boolean blockV3Enabled;
private final boolean exitWhenNoValidatorKeysEnabled;
private final boolean shutdownWhenValidatorSlashedEnabled;
private final UInt64 builderRegistrationDefaultGasLimit;
private final int builderRegistrationSendingBatchSize;
private final Optional<UInt64> builderRegistrationTimestampOverride;
Expand Down Expand Up @@ -133,6 +135,7 @@ private ValidatorConfig(
final boolean failoversPublishSignedDutiesEnabled,
final boolean blockV3Enabled,
final boolean exitWhenNoValidatorKeysEnabled,
final boolean shutdownWhenValidatorSlashedEnabled,
final UInt64 builderRegistrationDefaultGasLimit,
final int builderRegistrationSendingBatchSize,
final Optional<UInt64> builderRegistrationTimestampOverride,
Expand Down Expand Up @@ -173,6 +176,7 @@ private ValidatorConfig(
this.failoversPublishSignedDutiesEnabled = failoversPublishSignedDutiesEnabled;
this.blockV3Enabled = blockV3Enabled;
this.exitWhenNoValidatorKeysEnabled = exitWhenNoValidatorKeysEnabled;
this.shutdownWhenValidatorSlashedEnabled = shutdownWhenValidatorSlashedEnabled;
this.builderRegistrationDefaultGasLimit = builderRegistrationDefaultGasLimit;
this.builderRegistrationSendingBatchSize = builderRegistrationSendingBatchSize;
this.builderRegistrationTimestampOverride = builderRegistrationTimestampOverride;
Expand Down Expand Up @@ -311,6 +315,10 @@ public boolean isExitWhenNoValidatorKeysEnabled() {
return exitWhenNoValidatorKeysEnabled;
}

public boolean isShutdownWhenValidatorSlashedEnabled() {
return shutdownWhenValidatorSlashedEnabled;
}

public boolean isBuilderRegistrationDefaultEnabled() {
return builderRegistrationDefaultEnabled;
}
Expand Down Expand Up @@ -378,6 +386,8 @@ public static final class Builder {
DEFAULT_FAILOVERS_PUBLISH_SIGNED_DUTIES_ENABLED;
private boolean blockV3Enabled = DEFAULT_BLOCK_V3_ENABLED;
private boolean exitWhenNoValidatorKeysEnabled = DEFAULT_EXIT_WHEN_NO_VALIDATOR_KEYS_ENABLED;
private boolean shutdownWhenValidatorSlashedEnabled =
DEFAULT_SHUTDOWN_WHEN_VALIDATOR_SLASHED_ENABLED;
private UInt64 builderRegistrationDefaultGasLimit = DEFAULT_BUILDER_REGISTRATION_GAS_LIMIT;
private int builderRegistrationSendingBatchSize =
DEFAULT_VALIDATOR_REGISTRATION_SENDING_BATCH_SIZE;
Expand Down Expand Up @@ -580,6 +590,12 @@ public Builder exitWhenNoValidatorKeysEnabled(final boolean exitWhenNoValidatorK
return this;
}

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

public Builder builderRegistrationDefaultGasLimit(
final UInt64 builderRegistrationDefaultGasLimit) {
this.builderRegistrationDefaultGasLimit = builderRegistrationDefaultGasLimit;
Expand Down Expand Up @@ -659,6 +675,7 @@ public ValidatorConfig build() {
failoversPublishSignedDutiesEnabled,
blockV3Enabled,
exitWhenNoValidatorKeysEnabled,
shutdownWhenValidatorSlashedEnabled,
builderRegistrationDefaultGasLimit,
builderRegistrationSendingBatchSize,
builderRegistrationTimestampOverride,
Expand Down

0 comments on commit 5a93913

Please sign in to comment.