Skip to content

Commit

Permalink
Don't require signing keys when doing event stream recovery. (#6285)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <cody@swirldslabs.com>
  • Loading branch information
cody-littley committed Apr 27, 2023
1 parent edb8da9 commit ec0701e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion platform-sdk/sdk/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ useLoopbackIp, false
csvFileName, PlatformTesting
checkSignedStateFromDisk, true
loadKeysFromPfxFiles, false
event.preconsensus.enableStorage, false
event.preconsensus.enableStorage, false
enableEventStreaming, false
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class EventStreamRecoverCommand extends AbstractCommand {
private long finalRound = -1;
private Path eventStreamDirectory;
private List<Path> configurationPaths = List.of();
private boolean loadSigningKeys;

private EventStreamRecoverCommand() {}

Expand Down Expand Up @@ -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(
Expand All @@ -115,7 +124,8 @@ public Integer call() throws Exception {
!ignorePartialRounds,
finalRound,
outputPath,
selfId);
selfId,
loadSigningKeys);
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
*/
Expand All @@ -213,7 +216,8 @@ public static SignedState reapplyTransactions(
final SwirldMain appMain,
final IOIterator<Round> roundIterator,
final long finalRound,
final long selfId)
final long selfId,
final boolean loadSigningKeys)
throws IOException {

throwArgNull(configuration, "configuration");
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ec0701e

Please sign in to comment.