Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exit when no validator keys #7829

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ the [releases page](https://github.com/Consensys/teku/releases).
- Added `--ee-jwt-claim-id` command line option to provide `id` to the execution engine JWT claims

### Bug Fixes
- Fixed bug preventing node to startup when using `--exit-when-no-validator-keys-enabled` even with keys present
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class ValidatorClientServiceAcceptanceTest extends AcceptanceTestBase {

@Test
void shouldFailWithNoValidatorKeysWhenExitOptionEnabledOnBeaconNode() throws Exception {
TekuNode beaconNode = createTekuNode(config -> config.withExitWhenNoValidatorKeysEnabled(true));
TekuNode beaconNode =
createTekuNode(
config -> config.withExitWhenNoValidatorKeysEnabled(true).withInteropValidators(0, 0));
beaconNode.startWithFailure(
"No loaded validators when --exit-when-no-validator-keys-enabled option is true");
}
Expand All @@ -32,7 +34,11 @@ void shouldFailWithNoValidatorKeysWhenExitOptionEnabledOnValidatorClient() throw
TekuNode beaconNode = createTekuNode();
TekuValidatorNode validatorClient =
createValidatorNode(
config -> config.withBeaconNode(beaconNode).withExitWhenNoValidatorKeysEnabled(true));
config ->
config
.withBeaconNode(beaconNode)
.withExitWhenNoValidatorKeysEnabled(true)
.withInteropModeDisabled());
beaconNode.start();
validatorClient.startWithFailure(
"No loaded validators when --exit-when-no-validator-keys-enabled option is true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ public void doppelgangerDetectionAlert(final Set<String> doppelgangerPublicKeys)
String.join(", ", doppelgangerPublicKeys));
}

public void exitOnDoppelgangerDetected(final String keys) {
log.fatal("Validator doppelganger detected. Public keys: {}. Shutting down...", keys);
}

public void exitOnNoValidatorKeys() {
log.fatal(
"No loaded validators when --exit-when-no-validator-keys-enabled option is true. Shutting down...");
}

public void beginInitializingChainData() {
log.info("Initializing storage");
}
Expand Down
16 changes: 1 addition & 15 deletions teku/src/main/java/tech/pegasys/teku/cli/BeaconNodeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.storage.server.DatabaseStorageException;
import tech.pegasys.teku.validator.client.NoValidatorKeysStateException;

@SuppressWarnings("unused")
@Command(
Expand Down Expand Up @@ -353,25 +352,12 @@ public int handleExceptionAndReturnExitCode(final Throwable e) {
return 2;
} else {
reportUnexpectedError(e);
if (ExceptionUtil.hasCause(e, NoValidatorKeysStateException.class)) {
return 2;
}
return 1;
}
}

public void reportUnexpectedError(final Throwable t) {
if (ExceptionUtil.hasCause(t, NoValidatorKeysStateException.class)) {
getLogger().fatal("Teku failed to start: " + t.getMessage());
} else {
getLogger().fatal("Teku failed to start", t);
}
errorWriter.println("Teku failed to start: " + t.getMessage());
printUsage(errorWriter);
}

public void reportUnexpectedErrorNoStacktrace(final Throwable t) {
getLogger().fatal("Teku failed to start", t.getMessage());
getLogger().fatal("Teku failed to start", t);
errorWriter.println("Teku failed to start: " + t.getMessage());
printUsage(errorWriter);
}
Expand Down

This file was deleted.

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

package tech.pegasys.teku.validator.client;

import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG;

import java.net.http.HttpClient;
import java.nio.file.Path;
import java.time.Duration;
Expand Down Expand Up @@ -218,6 +220,12 @@ public static ValidatorClientService create(
() -> validatorClientService.initializeValidators(validatorApiChannel, asyncRunner))
.thenCompose(
__ -> {
if (validatorConfig.isExitWhenNoValidatorKeysEnabled()
&& validatorLoader.getOwnedValidators().getActiveValidators().isEmpty()) {
STATUS_LOG.exitOnNoValidatorKeys();
System.exit(2);
}

if (validatorConfig.isDoppelgangerDetectionEnabled()) {
validatorClientService.initializeDoppelgangerDetector(
asyncRunner,
Expand Down Expand Up @@ -270,12 +278,6 @@ public static ValidatorClientService create(
})
.always(() -> LOG.trace("Finished starting validator client service."));

if (validatorConfig.isExitWhenNoValidatorKeysEnabled()
&& validatorLoader.getOwnedValidators().getActiveValidators().size() == 0) {
throw new NoValidatorKeysStateException(
"No loaded validators when --exit-when-no-validator-keys-enabled option is true");
}

return validatorClientService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@

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

import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG;

import java.util.List;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.bls.BLSPublicKey;

public class DoppelgangerDetectionShutDown implements DoppelgangerDetectionAction {

private static final Logger LOG = LogManager.getLogger();

@Override
public void perform(final List<BLSPublicKey> doppelgangers) {
LOG.info(
"Validator doppelganger detected. Public keys: {}. Shutting down...",
STATUS_LOG.exitOnDoppelgangerDetected(
doppelgangers.stream()
.map(BLSPublicKey::toAbbreviatedString)
.collect(Collectors.joining(", ")));
Expand Down
Loading