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

05786 5396 misc startup improvements #5790

Merged
merged 65 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9e2cf3f
Integrate preconsensus event stream (except for removal of old files.…
cody-littley Mar 13, 2023
6d6f70e
Initial work for state metadata file.
cody-littley Mar 13, 2023
56f5f46
Incremental progress.
cody-littley Mar 14, 2023
5ecfeda
Added TODO.
cody-littley Mar 14, 2023
4003ef4
incremental work
cody-littley Mar 14, 2023
3dd786e
Integrate writing of metadata file. Lots of loose ends need tying.
cody-littley Mar 14, 2023
602f77b
Incremental progress.
cody-littley Mar 14, 2023
29bfeba
Incremental improvements.
cody-littley Mar 15, 2023
d240531
Add unit test
cody-littley Mar 15, 2023
c03e66b
Incremental improvements.
cody-littley Mar 15, 2023
8d0a30e
Add minimum generation non-ancient explicitly to state.
cody-littley Mar 15, 2023
8efdb0c
Fix naming.
cody-littley Mar 15, 2023
1400c78
Check minimum generation non-ancient in unit test.
cody-littley Mar 15, 2023
9bc6a28
Revert settings change.
cody-littley Mar 16, 2023
f668a47
Removed code that is in a different PR.
cody-littley Mar 16, 2023
6b26fe1
Cleanup.
cody-littley Mar 16, 2023
9bac432
Merge branch 'develop' into 05631-state-metadata-file
cody-littley Mar 16, 2023
e53fb30
Fixed smells.
cody-littley Mar 16, 2023
4ae4138
Fixed broken tests.
cody-littley Mar 16, 2023
2db33e4
Merge branch 'develop' into 05396-write-to-preconsensus-stream-2
cody-littley Mar 16, 2023
0e139f1
Merge branch '05631-state-metadata-file' into 05396-write-to-preconse…
cody-littley Mar 16, 2023
50cfde2
Added cleanup of old files.
cody-littley Mar 16, 2023
444696b
Added ability to disable preconsensus stream.
cody-littley Mar 16, 2023
5d21d90
Fix bugs.
cody-littley Mar 16, 2023
ae65eb0
Qualify event files with node ID (to prevent collisions when testing …
cody-littley Mar 16, 2023
e376373
Merge branch 'develop' into 05396-write-to-preconsensus-stream-2
cody-littley Mar 16, 2023
c115f64
Made suggested changes.
cody-littley Mar 17, 2023
edac2af
Added TODO
cody-littley Mar 17, 2023
fecb285
Added new unit tests.
cody-littley Mar 17, 2023
5498982
final, spotless
cody-littley Mar 17, 2023
b2ffdc5
Merge branch 'develop' into 05631-state-metadata-file
cody-littley Mar 20, 2023
bae8750
Made suggested changes.
cody-littley Mar 20, 2023
9e5897e
Fixed unit test.
cody-littley Mar 21, 2023
10333c1
Make suggested change.
cody-littley Mar 21, 2023
be6cf65
Merge branch '05631-state-metadata-file' into 05396-write-to-preconse…
cody-littley Mar 21, 2023
de52cad
Don't flush on event intake thread, fix tests.
cody-littley Mar 21, 2023
e619762
Tweaks.
cody-littley Mar 22, 2023
40adb5d
Block for durability on the correct thread.
cody-littley Mar 22, 2023
0ec898c
Resolved TODOs.
cody-littley Mar 22, 2023
ec48695
Merge branch 'develop' into 05396-write-to-preconsensus-stream-2
cody-littley Mar 23, 2023
f131ae9
Various minor platform cleanup.
cody-littley Mar 23, 2023
3879b24
Fixed unit tests.
cody-littley Mar 23, 2023
e754eb8
Fixed smells.
cody-littley Mar 23, 2023
e3317f5
Merge branch '05396-write-to-preconsensus-stream-2' into 05786-5396-m…
cody-littley Mar 23, 2023
77471b0
Cleanup.
cody-littley Mar 24, 2023
8cbe18a
Fixed broken tests.
cody-littley Mar 24, 2023
2cbdeb9
Made suggested changes.
cody-littley Mar 24, 2023
9d032b4
Merge branch 'develop' into 05396-write-to-preconsensus-stream-2
cody-littley Mar 24, 2023
385e9f6
Made suggested changes.
cody-littley Mar 24, 2023
edc98bc
Merge branch '05396-write-to-preconsensus-stream-2' into 05786-5396-m…
cody-littley Mar 24, 2023
6349891
Merge branch 'develop' into 05396-write-to-preconsensus-stream-2
cody-littley Mar 27, 2023
3097da0
fix smells
cody-littley Mar 27, 2023
5514a77
Made suggested changes.
cody-littley Mar 27, 2023
0165ebf
Made suggested changes.
cody-littley Mar 27, 2023
3c06613
Updated the diagram.
cody-littley Mar 27, 2023
98f4cef
Exported html for diagram.
cody-littley Mar 27, 2023
9b019e1
Made suggested change.
cody-littley Mar 27, 2023
aa7734e
Merge branch '05396-write-to-preconsensus-stream-2' into 05786-5396-m…
cody-littley Mar 27, 2023
d3eace3
spotless
cody-littley Mar 27, 2023
6365554
Merge branch 'develop' into 05396-write-to-preconsensus-stream-2
cody-littley Mar 28, 2023
4a1283c
Made suggested change.
cody-littley Mar 28, 2023
84d4b64
Merge branch '05396-write-to-preconsensus-stream-2' into 05786-5396-m…
cody-littley Mar 28, 2023
c244baa
Merge branch 'develop' into 05786-5396-misc-startup-improvements
cody-littley Mar 30, 2023
77f1028
Merge branch 'develop' into 05786-5396-misc-startup-improvements
cody-littley Apr 4, 2023
63de082
Made suggested changes.
cody-littley Apr 4, 2023
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
4 changes: 4 additions & 0 deletions platform-sdk/docs/components/eventflow-threads.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.swirlds.platform;

import static com.swirlds.base.ArgumentUtils.throwArgNull;
import static com.swirlds.common.io.utility.FileUtils.getAbsolutePath;
import static com.swirlds.common.io.utility.FileUtils.rethrowIO;
import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager;
Expand Down Expand Up @@ -64,7 +65,6 @@
import com.swirlds.common.system.address.Address;
import com.swirlds.common.system.address.AddressBook;
import com.swirlds.common.threading.framework.config.ThreadConfiguration;
import com.swirlds.common.threading.interrupt.Uninterruptable;
import com.swirlds.common.utility.CommonUtils;
import com.swirlds.config.api.Configuration;
import com.swirlds.config.api.ConfigurationBuilder;
Expand All @@ -89,6 +89,10 @@
import com.swirlds.platform.gui.internal.InfoMember;
import com.swirlds.platform.gui.internal.InfoSwirld;
import com.swirlds.platform.gui.internal.StateHierarchy;
import com.swirlds.platform.health.OSHealthChecker;
import com.swirlds.platform.health.clock.OSClockSpeedSourceChecker;
import com.swirlds.platform.health.entropy.OSEntropyChecker;
import com.swirlds.platform.health.filesystem.OSFileSystemChecker;
import com.swirlds.platform.reconnect.emergency.EmergencySignedStateValidator;
import com.swirlds.platform.state.EmergencyRecoveryManager;
import com.swirlds.platform.state.signed.SavedStateInfo;
Expand All @@ -113,13 +117,15 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.swing.JFrame;
import javax.swing.UIManager;
Expand Down Expand Up @@ -151,9 +157,6 @@ public class Browser {

private static Logger logger = LogManager.getLogger(Browser.class);

/** the thread for each Platform.run */
private static Thread[] platformRunThreads;

private static Thread[] appRunThreads;

private static Browser INSTANCE;
Expand Down Expand Up @@ -226,6 +229,13 @@ private Browser(final Set<Integer> localNodesToStart) throws IOException {
ConfigurationHolder.getInstance().setConfiguration(configuration);
CryptographyHolder.reset();

OSHealthChecker.performOSHealthChecks(
configuration.getConfigData(OSHealthCheckConfig.class),
List.of(
OSClockSpeedSourceChecker::performClockSourceSpeedCheck,
OSEntropyChecker::performEntropyChecks,
OSFileSystemChecker::performFileSystemCheck));

try {
// discover the inset size and set the look and feel
if (!GraphicsEnvironment.isHeadless()) {
Expand Down Expand Up @@ -350,8 +360,8 @@ private Browser(final Set<Integer> localNodesToStart) throws IOException {
@NonNull
private Map<Long, SwirldMain> loadSwirldMains(
@NonNull final ApplicationDefinition appDefinition, @NonNull final Set<Integer> localNodesToStart) {
Objects.requireNonNull(appDefinition, "appDefinition must not be null");
Objects.requireNonNull(localNodesToStart, "localNodesToStart must not be null");
throwArgNull(appDefinition, "appDefinition must not be null");
throwArgNull(localNodesToStart, "localNodesToStart must not be null");
try {
// Create the SwirldAppLoader
final SwirldAppLoader appLoader;
Expand Down Expand Up @@ -577,19 +587,21 @@ private static SwirldMain buildAppMain(final ApplicationDefinition appDefinition
}
}

private void createLocalPlatforms(
private Collection<SwirldsPlatform> createLocalPlatforms(
@NonNull final ApplicationDefinition appDefinition,
@NonNull final Crypto[] crypto,
@NonNull final InfoSwirld infoSwirld,
@NonNull final Map<Long, SwirldMain> appMains,
@NonNull final Configuration configuration,
@NonNull final MetricsProvider metricsProvider) {
Objects.requireNonNull(appDefinition, "the app definition must not be null");
Objects.requireNonNull(crypto, "the crypto array must not be null");
Objects.requireNonNull(infoSwirld, "the infoSwirld must not be null");
Objects.requireNonNull(appMains, "the appMains map must not be null");
Objects.requireNonNull(configuration, "the configuration must not be null");
Objects.requireNonNull(metricsProvider, "the metricsProvider must not be null");
throwArgNull(appDefinition, "the app definition must not be null");
throwArgNull(crypto, "the crypto array must not be null");
throwArgNull(infoSwirld, "the infoSwirld must not be null");
throwArgNull(appMains, "the appMains map must not be null");
throwArgNull(configuration, "the configuration must not be null");
throwArgNull(metricsProvider, "the metricsProvider must not be null");

final List<SwirldsPlatform> platforms = new ArrayList<>();

final AddressBook addressBook = appDefinition.getAddressBook();

Expand Down Expand Up @@ -654,6 +666,7 @@ private void createLocalPlatforms(
appMain::newState,
loadedSignedState,
emergencyRecoveryManager);
platforms.add(platform);

new InfoMember(infoSwirld, i, platform);

Expand All @@ -667,26 +680,14 @@ private void createLocalPlatforms(
.build();
appRunThreads[ownHostIndex] = appThread;

platformRunThreads[ownHostIndex] = new ThreadConfiguration(getStaticThreadManager())
.setDaemon(false)
.setPriority(Settings.getInstance().getThreadPriorityNonSync())
.setNodeId((long) ownHostIndex)
.setComponent(SwirldsPlatform.PLATFORM_THREAD_POOL_NAME)
.setThreadName("platformRun")
.setRunnable(() -> {
platform.run();
// When the SwirldMain quits, end the run() for this platform instance
Uninterruptable.abortAndLogIfInterrupted(
appThread::join, "interrupted when waiting for app thread to terminate");
})
.build();

ownHostIndex++;
synchronized (getPlatforms()) {
getPlatforms().add(platform);
hendrikebbers marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

return Collections.unmodifiableList(platforms);
}

/**
Expand Down Expand Up @@ -767,7 +768,6 @@ private void startPlatforms(
// the thread for each Platform.run
// will create a new thread with a new Platform for each local address
// general address number addIndex is local address number i
platformRunThreads = new Thread[ownHostCount];
appRunThreads = new Thread[ownHostCount];
appDefinition.setMasterKey(new byte[CryptoConstants.SYM_KEY_SIZE_BYTES]);
appDefinition.setSwirldId(new byte[CryptoConstants.HASH_SIZE_BYTES]);
Expand All @@ -794,14 +794,15 @@ private void startPlatforms(
CryptoMetrics.registerMetrics(globalMetrics);

// Create all instances for all nodes that should run locally
createLocalPlatforms(appDefinition, crypto, infoSwirld, appMains, configuration, metricsProvider);
final Collection<SwirldsPlatform> platforms =
createLocalPlatforms(appDefinition, crypto, infoSwirld, appMains, configuration, metricsProvider);

// Write all metrics information to file
MetricsDocUtils.writeMetricsDocumentToFile(globalMetrics, getPlatforms(), configuration);

// the platforms need to start after all the initial loading has been done
for (int nodeIndex = 0; nodeIndex < platformRunThreads.length; nodeIndex++) {
platformRunThreads[nodeIndex].start();
platforms.forEach(SwirldsPlatform::start);

for (int nodeIndex = 0; nodeIndex < appRunThreads.length; nodeIndex++) {
appRunThreads[nodeIndex].start();
}

Expand All @@ -817,15 +818,6 @@ private void startPlatforms(
logger.debug(STARTUP.getMarker(), "Done with starting platforms");
}

/**
* Wait until all platform main threads are stopped.
*/
public static void join() throws InterruptedException {
for (final Thread thread : platformRunThreads) {
thread.join();
}
}

public static void main(final String[] args) {
parseCommandLineArgsAndLaunch(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
import static com.swirlds.logging.LogMarker.STARTUP;
import static com.swirlds.platform.state.GenesisStateBuilder.buildGenesisState;

import com.swirlds.common.config.BasicConfig;
import com.swirlds.common.config.ConsensusConfig;
import com.swirlds.common.config.OSHealthCheckConfig;
import com.swirlds.common.config.StateConfig;
import com.swirlds.common.config.singleton.ConfigurationHolder;
import com.swirlds.common.context.PlatformContext;
Expand Down Expand Up @@ -76,9 +74,9 @@
import com.swirlds.common.time.Time;
import com.swirlds.common.utility.AutoCloseableWrapper;
import com.swirlds.common.utility.Clearable;
import com.swirlds.common.utility.CommonUtils;
import com.swirlds.common.utility.LoggingClearables;
import com.swirlds.common.utility.PlatformVersion;
import com.swirlds.common.utility.Startable;
import com.swirlds.logging.LogMarker;
import com.swirlds.logging.payloads.PlatformStatusPayload;
import com.swirlds.logging.payloads.SavedStateLoadedPayload;
Expand Down Expand Up @@ -144,10 +142,6 @@
import com.swirlds.platform.event.validation.TransactionSizeValidator;
import com.swirlds.platform.eventhandling.ConsensusRoundHandler;
import com.swirlds.platform.eventhandling.PreConsensusEventHandler;
import com.swirlds.platform.health.OSHealthChecker;
import com.swirlds.platform.health.clock.OSClockSpeedSourceChecker;
import com.swirlds.platform.health.entropy.OSEntropyChecker;
import com.swirlds.platform.health.filesystem.OSFileSystemChecker;
import com.swirlds.platform.intake.IntakeCycleStats;
import com.swirlds.platform.internal.EventImpl;
import com.swirlds.platform.metrics.AddedEventMetrics;
Expand Down Expand Up @@ -191,7 +185,6 @@
import com.swirlds.platform.reconnect.ReconnectProtocolResponder;
import com.swirlds.platform.reconnect.ReconnectThrottle;
import com.swirlds.platform.reconnect.emergency.EmergencyReconnectProtocol;
import com.swirlds.platform.state.BackgroundHashChecker;
import com.swirlds.platform.state.EmergencyRecoveryManager;
import com.swirlds.platform.state.State;
import com.swirlds.platform.state.StateSettings;
Expand Down Expand Up @@ -234,7 +227,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods, ConnectionTracker {
public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods, ConnectionTracker, Startable {

public static final String PLATFORM_THREAD_POOL_NAME = "platform-core";
/** use this for all logging, as controlled by the optional data/log4j2.xml file */
Expand All @@ -247,7 +240,7 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
* the ID of the member running this. Since a node can be a main node or a mirror node, the ID is not a primitive
* value
*/
protected final NodeId selfId;
private final NodeId selfId;
/** tell which pairs of members should establish connections */
final NetworkTopology topology;
/**
Expand All @@ -263,10 +256,6 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
* is for this to replace EventMapper once syncing is removed from the code
*/
private final ChatterEventMapper chatterEventMapper;
/** the name of the swirld being run */
private final String swirldName;
/** the name of the main class this platform will be running */
private final String mainClassName;
/** this is the Nth Platform running on this machine (N=winNum) */
private final int instanceNumber;
/** parameters given to the app when it starts */
Expand Down Expand Up @@ -315,11 +304,11 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,

private final ChatterCore<GossipEvent> chatterCore;
/** all the events and other data about the hashgraph */
protected EventTaskCreator eventTaskCreator;
private EventTaskCreator eventTaskCreator;
/** ID number of the swirld being run */
protected byte[] swirldId;
private final byte[] swirldId;
/** the object that contains all key pairs and CSPRNG state for this member */
protected Crypto crypto;
private final Crypto crypto;
/** a long name including (app, swirld, member id, member self name) */
private final String platformName;
/** is used for calculating runningHash of all consensus events and writing consensus events to file */
Expand All @@ -336,11 +325,6 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
* If a state was loaded from disk, this will have the hash of that state.
*/
private Hash diskStateHash;
/**
* The previous version of the software that was run. Null if this is the first time running, or if the previous
* version ran before the concept of application software versioning was introduced.
*/
private SoftwareVersion previousSoftwareVersion;
/** Helps when executing a reconnect */
private ReconnectHelper reconnectHelper;
/** tells callers who to sync with and keeps track of whether we have fallen behind */
Expand Down Expand Up @@ -384,11 +368,6 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
*/
private final List<StoppableThread> chatterThreads = new LinkedList<>();

/**
* Builds dispatchers and registers observers for this platform instance.
*/
private final DispatchBuilder dispatchBuilder;

/**
* All components that need to be started or that have dispatch observers.
*/
Expand Down Expand Up @@ -426,8 +405,6 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
*/
private final PreConsensusEventWriter preConsensusEventWriter;

private final BasicConfig basicConfig;

/**
* the browser gives the Platform what app to run. There can be multiple Platforms on one computer.
*
Expand Down Expand Up @@ -463,11 +440,11 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
@Nullable final SignedState loadedSignedState,
@NonNull final EmergencyRecoveryManager emergencyRecoveryManager) {

this.platformContext = CommonUtils.throwArgNull(platformContext, "platformContext");
this.basicConfig = platformContext.getConfiguration().getConfigData(BasicConfig.class);
this.platformContext = Objects.requireNonNull(platformContext, "platformContext");
hendrikebbers marked this conversation as resolved.
Show resolved Hide resolved

DispatchBuilder dispatchBuilder =
new DispatchBuilder(platformContext.getConfiguration().getConfigData(DispatchConfiguration.class));

dispatchBuilder =
new DispatchBuilder(ConfigurationHolder.getInstance().get().getConfigData(DispatchConfiguration.class));
components = new PlatformComponents(dispatchBuilder);

// FUTURE WORK: use a real thread manager here
Expand All @@ -487,9 +464,8 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
new SimultaneousSyncThrottle(settings.getMaxIncomingSyncsInc() + settings.getMaxOutgoingSyncs());

final StateConfig stateConfig = platformContext.getConfiguration().getConfigData(StateConfig.class);
this.mainClassName = stateConfig.getMainClassName(mainClassName);
final String actualMainClassName = stateConfig.getMainClassName(mainClassName);

this.swirldName = swirldName;
this.appVersion = appVersion;

this.instanceNumber = instanceNumber;
Expand Down Expand Up @@ -553,7 +529,7 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,

stateManagementComponent = wiring.wireStateManagementComponent(
PlatformConstructor.platformSigner(crypto.getKeysAndCerts()),
this.mainClassName,
actualMainClassName,
selfId,
swirldName,
this::createPrioritySystemTransaction,
Expand All @@ -566,11 +542,6 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,
new NetworkStatsTransmitter(platformContext, this::createSystemTransaction, networkMetrics);
components.add(networkStatsTransmitter);

if (settings.getState().backgroundHashChecking) {
// This object performs background sanity checks on copies of the state.
new BackgroundHashChecker(threadManager, stateManagementComponent::getLatestSignedState);
}

preConsensusSystemTransactionManager = new PreConsensusSystemTransactionManagerFactory()
.addHandlers(stateManagementComponent.getPreConsensusHandleMethods())
.build();
Expand Down Expand Up @@ -606,13 +577,6 @@ public class SwirldsPlatform implements Platform, PlatformWithDeprecatedMethods,

final LoadedState loadedState = initializeLoadedStateFromSignedState(loadedSignedState);
init(loadedState, genesisStateBuilder);

OSHealthChecker.performOSHealthChecks(
platformContext.getConfiguration().getConfigData(OSHealthCheckConfig.class),
List.of(
OSClockSpeedSourceChecker::performClockSourceSpeedCheck,
OSEntropyChecker::performEntropyChecks,
OSFileSystemChecker::performFileSystemCheck));
}

/**
Expand Down Expand Up @@ -770,7 +734,11 @@ private State loadSavedState(final SignedState signedStateFromDisk) {
.setDepth(StateSettings.getDebugHashDepth())
.render());

previousSoftwareVersion = signedStateFromDisk
/**
* The previous version of the software that was run. Null if this is the first time running, or if the previous
* version ran before the concept of application software versioning was introduced.
*/
SoftwareVersion previousSoftwareVersion = signedStateFromDisk
.getState()
.getPlatformState()
.getPlatformData()
Expand Down Expand Up @@ -1229,10 +1197,10 @@ private void buildEventHandlersFromState(
}

/**
* Start the platform, which will in turn start the app and all the syncing threads. When using the normal browser,
* only one Platform is running. But with config.txt, multiple can be running.
* Start this platform.
*/
void run() {
@Override
public void start() {
syncManager = components.add(new SyncManagerImpl(
intakeQueue,
topology.getConnectionGraph(),
Expand Down
Loading