From ec0701eddb1c0e261a2ed2f314d459893c1ac8b4 Mon Sep 17 00:00:00 2001 From: Cody Littley <56973212+cody-littley@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:11:08 -0500 Subject: [PATCH] Don't require signing keys when doing event stream recovery. (#6285) Signed-off-by: Cody Littley --- .../signing/StatsSigningTestingToolMain.java | 1 - platform-sdk/sdk/settings.txt | 3 +- .../cli/EventStreamRecoverCommand.java | 12 +++++++- .../recovery/EventRecoveryWorkflow.java | 28 +++++++++++-------- .../recovery/internal/RecoveryPlatform.java | 24 ++++++++++++---- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java index 1ee18a246ccf..27e9325b9613 100644 --- a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java @@ -261,7 +261,6 @@ private synchronized void generateTransactions() { if (((double) now - lastTPSMeasureTime) * NANOSECONDS_TO_MICROSECONDS > tps_measure_window_milliseconds) { toCreate = ((double) now - lastTPSMeasureTime) * NANOSECONDS_TO_SECONDS * rampUpTPS; lastTPSMeasureTime = now; - logger.info(STARTUP.getMarker(), "rampUpTPS {}", rampUpTPS); } } diff --git a/platform-sdk/sdk/settings.txt b/platform-sdk/sdk/settings.txt index b2b8474dcd2a..6159fc573d33 100644 --- a/platform-sdk/sdk/settings.txt +++ b/platform-sdk/sdk/settings.txt @@ -14,4 +14,5 @@ useLoopbackIp, false csvFileName, PlatformTesting checkSignedStateFromDisk, true loadKeysFromPfxFiles, false -event.preconsensus.enableStorage, false \ No newline at end of file +event.preconsensus.enableStorage, false +enableEventStreaming, false \ No newline at end of file diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/cli/EventStreamRecoverCommand.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/cli/EventStreamRecoverCommand.java index 937d35c444ec..4f8902059337 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/cli/EventStreamRecoverCommand.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/cli/EventStreamRecoverCommand.java @@ -40,6 +40,7 @@ public final class EventStreamRecoverCommand extends AbstractCommand { private long finalRound = -1; private Path eventStreamDirectory; private List configurationPaths = List.of(); + private boolean loadSigningKeys; private EventStreamRecoverCommand() {} @@ -105,6 +106,14 @@ private void setFinalRound(final long finalRound) { this.finalRound = finalRound; } + @CommandLine.Option( + names = {"-s", "--load-signing-keys"}, + defaultValue = "false", + description = "If present then load the signing keys. If not present, calling platform.sign() will throw.") + private void setLoadSigningKeys(final boolean loadSigningKeys) { + this.loadSigningKeys = loadSigningKeys; + } + @Override public Integer call() throws Exception { recoverState( @@ -115,7 +124,8 @@ public Integer call() throws Exception { !ignorePartialRounds, finalRound, outputPath, - selfId); + selfId, + loadSigningKeys); return 0; } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/EventRecoveryWorkflow.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/EventRecoveryWorkflow.java index d685ccc37f6f..d13dcc13cf82 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/EventRecoveryWorkflow.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/EventRecoveryWorkflow.java @@ -88,6 +88,7 @@ private EventRecoveryWorkflow() {} * @param selfId the self ID of the node * @param allowPartialRounds if true then allow the last round to be missing events, if false then ignore the * last round if it does not have all of its events + * @param loadSigningKeys if true then load the signing keys */ public static void recoverState( final Path signedStateFile, @@ -97,7 +98,8 @@ public static void recoverState( final Boolean allowPartialRounds, final Long finalRound, final Path resultingStateDirectory, - final Long selfId) + final Long selfId, + final boolean loadSigningKeys) throws IOException { setupConstructableRegistry(); @@ -135,8 +137,8 @@ public static void recoverState( logger.info(STARTUP.getMarker(), "Reapplying transactions"); - final SignedState resultingState = - reapplyTransactions(configuration, initialState, appMain, roundIterator, finalRound, selfId); + final SignedState resultingState = reapplyTransactions( + configuration, initialState, appMain, roundIterator, finalRound, selfId, loadSigningKeys); logger.info( STARTUP.getMarker(), "Finished reapplying transactions, writing state to {}", resultingStateDirectory); @@ -197,13 +199,14 @@ private static void notifyStateRecovered( /** * Apply transactions on top of a state to produce a new state * - * @param configuration the configuration for the node - * @param initialState the starting signed state - * @param appMain the {@link SwirldMain} for the app. Ignored if null. - * @param roundIterator an iterator that walks over transactions - * @param finalRound the last round to apply to the state (inclusive), will stop earlier if the event stream does - * not have events from the final round - * @param selfId the self ID of the node + * @param configuration the configuration for the node + * @param initialState the starting signed state + * @param appMain the {@link SwirldMain} for the app. Ignored if null. + * @param roundIterator an iterator that walks over transactions + * @param finalRound the last round to apply to the state (inclusive), will stop earlier if the event stream + * does not have events from the final round + * @param selfId the self ID of the node + * @param loadSigningKeys if true then load the signing keys * @return the resulting signed state * @throws IOException if there is a problem reading from the event stream file */ @@ -213,7 +216,8 @@ public static SignedState reapplyTransactions( final SwirldMain appMain, final IOIterator roundIterator, final long finalRound, - final long selfId) + final long selfId, + final boolean loadSigningKeys) throws IOException { throwArgNull(configuration, "configuration"); @@ -228,7 +232,7 @@ public static SignedState reapplyTransactions( logger.info(STARTUP.getMarker(), "Initializing application state"); - final RecoveryPlatform platform = new RecoveryPlatform(configuration, initialState, selfId); + final RecoveryPlatform platform = new RecoveryPlatform(configuration, initialState, selfId, loadSigningKeys); initialState .getSwirldState() diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/internal/RecoveryPlatform.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/internal/RecoveryPlatform.java index 63e2bdcf2766..7068c37ba045 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/internal/RecoveryPlatform.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/recovery/internal/RecoveryPlatform.java @@ -64,17 +64,27 @@ public class RecoveryPlatform implements Platform, AutoCloseableNonThrowing { /** * Create a new recovery platform. * - * @param configuration the node's configuration - * @param initialState the starting signed state - * @param selfId the ID of the node + * @param configuration the node's configuration + * @param initialState the starting signed state + * @param selfId the ID of the node + * @param loadSigningKeys whether to load the signing keys, if false then {@link #sign(byte[])} will throw if + * called */ - public RecoveryPlatform(final Configuration configuration, final SignedState initialState, final long selfId) { + public RecoveryPlatform( + final Configuration configuration, + final SignedState initialState, + final long selfId, + final boolean loadSigningKeys) { this.selfId = new NodeId(false, selfId); this.addressBook = initialState.getAddressBook(); - crypto = initNodeSecurity(addressBook, configuration)[(int) selfId]; + if (loadSigningKeys) { + crypto = initNodeSecurity(addressBook, configuration)[(int) selfId]; + } else { + crypto = null; + } final MetricsConfig metricsConfig = configuration.getConfigData(MetricsConfig.class); @@ -109,6 +119,10 @@ public synchronized void setLatestState(final SignedState signedState) { */ @Override public Signature sign(final byte[] data) { + if (crypto == null) { + throw new UnsupportedOperationException( + "RecoveryPlatform was not loaded with signing keys, this operation is not supported"); + } return crypto.sign(data); }