From 20a5ea820ca6c68c15e247d28dfcb391c363e337 Mon Sep 17 00:00:00 2001 From: Miroslav Gatsanoga Date: Mon, 25 Nov 2024 15:36:08 +0200 Subject: [PATCH 1/6] fix: frontend throttle capacity stop querying the platform for roster Signed-off-by: Miroslav Gatsanoga --- .../hedera/node/app/platform/PlatformModule.java | 7 ------- .../node/app/throttle/ThrottleServiceModule.java | 5 ++++- .../workflows/standalone/TransactionExecutors.java | 2 +- .../standalone/impl/StandaloneNetworkInfo.java | 14 +++++++++++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/platform/PlatformModule.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/platform/PlatformModule.java index 49939859d3e2..612ab0b17371 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/platform/PlatformModule.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/platform/PlatformModule.java @@ -30,7 +30,6 @@ import java.nio.charset.Charset; import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; -import java.util.function.IntSupplier; import java.util.function.Supplier; import javax.inject.Singleton; @@ -55,12 +54,6 @@ static Supplier provideNativeCharset() { return Charset::defaultCharset; } - @Provides - @Singleton - static IntSupplier provideFrontendThrottleSplit(@NonNull final Platform platform) { - return () -> platform.getRoster().rosterEntries().size(); - } - @Binds @Singleton ReconnectCompleteListener bindReconnectListener(ReconnectListener reconnectListener); diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/throttle/ThrottleServiceModule.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/throttle/ThrottleServiceModule.java index dafb463e44ee..0d318d4ebff8 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/throttle/ThrottleServiceModule.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/throttle/ThrottleServiceModule.java @@ -28,6 +28,7 @@ import com.hedera.node.config.ConfigProvider; import com.hedera.node.config.data.FeesConfig; import com.swirlds.metrics.api.Metrics; +import com.swirlds.state.lifecycle.info.NetworkInfo; import dagger.Binds; import dagger.Module; import dagger.Provides; @@ -57,10 +58,12 @@ static ThrottleAccumulator provideBackendThrottleAccumulator(ConfigProvider conf @Singleton @IngestThrottle static ThrottleAccumulator provideIngestThrottleAccumulator( - @NonNull final IntSupplier frontendThrottleSplit, + @NonNull final NetworkInfo networkInfo, @NonNull final ConfigProvider configProvider, @NonNull final Metrics metrics) { final var throttleMetrics = new ThrottleMetrics(metrics, FRONTEND_THROTTLE); + final IntSupplier frontendThrottleSplit = + () -> networkInfo.roster().rosterEntries().size(); return new ThrottleAccumulator(frontendThrottleSplit, configProvider, FRONTEND_THROTTLE, throttleMetrics); } diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/TransactionExecutors.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/TransactionExecutors.java index 385feb14129f..5597373f71a6 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/TransactionExecutors.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/TransactionExecutors.java @@ -76,8 +76,8 @@ public TransactionExecutor newExecutor( final var tracerBinding = customTracerBinding != null ? customTracerBinding : DefaultTracerBinding.DEFAULT_TRACER_BINDING; final var executor = newExecutorComponent(properties, tracerBinding); - executor.initializer().accept(state); executor.stateNetworkInfo().initFrom(state); + executor.initializer().accept(state); final var exchangeRateManager = executor.exchangeRateManager(); return (transactionBody, consensusNow, operationTracers) -> { final var dispatch = executor.standaloneDispatchFactory().newDispatch(state, transactionBody, consensusNow); diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/impl/StandaloneNetworkInfo.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/impl/StandaloneNetworkInfo.java index 8885d13e591f..16b0fc2f6385 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/impl/StandaloneNetworkInfo.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/impl/StandaloneNetworkInfo.java @@ -24,6 +24,7 @@ import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.base.NodeAddressBook; import com.hedera.hapi.node.state.roster.Roster; +import com.hedera.hapi.node.state.roster.RosterEntry; import com.hedera.node.app.info.NodeInfoImpl; import com.hedera.node.config.ConfigProvider; import com.hedera.node.config.data.FilesConfig; @@ -35,6 +36,7 @@ import com.swirlds.state.lifecycle.info.NodeInfo; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +import java.util.Comparator; import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; @@ -135,7 +137,17 @@ public void updateFrom(final State state) { @Override public Roster roster() { - throw new UnsupportedOperationException("Not implemented"); + return Roster.newBuilder() + .rosterEntries(nodeInfosOrThrow().stream() + .map(node -> RosterEntry.newBuilder() + .nodeId(node.nodeId()) + .weight(node.stake()) + .gossipCaCertificate(node.sigCertBytes()) + .gossipEndpoint(node.gossipEndpoints()) + .build()) + .sorted(Comparator.comparing(RosterEntry::nodeId)) + .toList()) + .build(); } private @NonNull List nodeInfosOrThrow() { From 4530f9e73da4c2c6210230116ec38884156967b8 Mon Sep 17 00:00:00 2001 From: Miroslav Gatsanoga Date: Tue, 26 Nov 2024 11:00:10 +0200 Subject: [PATCH 2/6] fix: remove call to platfrom from initializeDagger() method Signed-off-by: Miroslav Gatsanoga --- .../src/main/java/com/hedera/node/app/Hedera.java | 12 ++++++++++-- .../java/com/hedera/node/app/tss/TssBaseService.java | 6 +----- .../com/hedera/node/app/tss/TssBaseServiceImpl.java | 9 ++------- .../hedera/embedded/fakes/FakeTssBaseService.java | 7 ++----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java index 2ff2025a0f23..212e4239b390 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java @@ -56,6 +56,7 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.hapi.node.state.blockrecords.BlockInfo; import com.hedera.hapi.node.state.blockstream.BlockStreamInfo; +import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.hapi.platform.state.PlatformState; import com.hedera.hapi.util.HapiUtils; @@ -110,6 +111,7 @@ import com.hedera.node.config.data.HederaConfig; import com.hedera.node.config.data.LedgerConfig; import com.hedera.node.config.data.NetworkAdminConfig; +import com.hedera.node.config.data.TssConfig; import com.hedera.node.config.data.VersionConfig; import com.hedera.node.config.types.StreamMode; import com.hedera.pbj.runtime.io.buffer.Bytes; @@ -970,8 +972,14 @@ private void initializeDagger(@NonNull final State state, @NonNull final InitTri .round(); final var initialStateHash = new InitialStateHash(initialStateHashFuture, roundNum); - final var activeRoster = tssBaseService.chooseRosterForNetwork( - state, trigger, serviceMigrator, version, configProvider.getConfiguration(), platform.getRoster()); + final Roster activeRoster; + if (!configProvider.getConfiguration().getConfigData(TssConfig.class).keyCandidateRoster()) { + final var platformState = + new ReadablePlatformStateStore(state.getReadableStates(PlatformStateService.NAME)); + activeRoster = buildRoster(platformState.getAddressBook()); + } else { + activeRoster = tssBaseService.chooseRosterForNetwork(state, trigger, serviceMigrator, version); + } final var networkInfo = new StateNetworkInfo(state, activeRoster, platform.getSelfId().id(), configProvider); // Fully qualified so as to not confuse javadoc diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseService.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseService.java index 0516ebf2002b..be1d5593e89e 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseService.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseService.java @@ -26,7 +26,6 @@ import com.hedera.node.app.tss.stores.ReadableTssStoreImpl; import com.hedera.node.app.version.ServicesSoftwareVersion; import com.hedera.pbj.runtime.io.buffer.Bytes; -import com.swirlds.config.api.Configuration; import com.swirlds.platform.system.InitTrigger; import com.swirlds.state.State; import com.swirlds.state.lifecycle.Service; @@ -138,16 +137,13 @@ void bootstrapLedgerId( * @param trigger the initialization trigger * @param serviceMigrator the service migrator * @param version the services software version - * @param configuration the configuration * @return the active roster */ Roster chooseRosterForNetwork( @NonNull State state, @NonNull InitTrigger trigger, @NonNull ServiceMigrator serviceMigrator, - @NonNull ServicesSoftwareVersion version, - @NonNull Configuration configuration, - @NonNull Roster overrideRoster); + @NonNull ServicesSoftwareVersion version); /** * Regenerates the key material for the active roster. This happens each time the active roster is updated. diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseServiceImpl.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseServiceImpl.java index 80d35ffdaa41..fcbc2514ccbc 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseServiceImpl.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/tss/TssBaseServiceImpl.java @@ -49,7 +49,6 @@ import com.hedera.node.config.data.TssConfig; import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.utility.CommonUtils; -import com.swirlds.config.api.Configuration; import com.swirlds.metrics.api.Metrics; import com.swirlds.platform.roster.RosterUtils; import com.swirlds.platform.state.service.ReadableRosterStore; @@ -270,12 +269,8 @@ public Roster chooseRosterForNetwork( @NonNull State state, @NonNull InitTrigger trigger, @NonNull ServiceMigrator serviceMigrator, - @NonNull ServicesSoftwareVersion version, - @NonNull final Configuration configuration, - @NonNull final Roster overrideRoster) { - if (!configuration.getConfigData(TssConfig.class).keyCandidateRoster()) { - return overrideRoster; - } + @NonNull ServicesSoftwareVersion version) { + final var activeRoster = retrieveActiveOrGenesisRoster(state); if (trigger != GENESIS) { final var creatorVersion = requireNonNull(serviceMigrator.creationVersionOf(state)); diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeTssBaseService.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeTssBaseService.java index b36aba3c1f86..1eb60ffb2ace 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeTssBaseService.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeTssBaseService.java @@ -34,7 +34,6 @@ import com.hedera.services.bdd.junit.HapiTest; import com.swirlds.common.metrics.noop.NoOpMetrics; import com.swirlds.common.utility.CommonUtils; -import com.swirlds.config.api.Configuration; import com.swirlds.platform.system.InitTrigger; import com.swirlds.state.State; import com.swirlds.state.lifecycle.SchemaRegistry; @@ -241,10 +240,8 @@ public Roster chooseRosterForNetwork( @NonNull State state, @NonNull InitTrigger trigger, @NonNull ServiceMigrator serviceMigrator, - @NonNull ServicesSoftwareVersion version, - @NonNull final Configuration configuration, - @NonNull final Roster overrideRoster) { - return delegate.chooseRosterForNetwork(state, trigger, serviceMigrator, version, configuration, overrideRoster); + @NonNull ServicesSoftwareVersion version) { + return delegate.chooseRosterForNetwork(state, trigger, serviceMigrator, version); } @Override From 9487b0c6540c4e36104778ba955859bb65830f34 Mon Sep 17 00:00:00 2001 From: Miroslav Gatsanoga Date: Tue, 26 Nov 2024 12:47:16 +0200 Subject: [PATCH 3/6] fix: use genesis startup network instead of genesis address book when initializing states api Signed-off-by: Miroslav Gatsanoga --- .../main/java/com/hedera/node/app/Hedera.java | 21 +++++++------------ .../com/hedera/node/app/ServicesMain.java | 7 +------ .../embedded/AbstractEmbeddedHedera.java | 3 +-- .../block/StateChangesValidator.java | 2 +- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java index a99cf395a548..6fce533d155c 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java @@ -117,6 +117,7 @@ import com.hedera.node.config.data.TssConfig; import com.hedera.node.config.data.VersionConfig; import com.hedera.node.config.types.StreamMode; +import com.hedera.node.internal.network.NodeMetadata; import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; @@ -135,7 +136,6 @@ import com.swirlds.platform.listeners.ReconnectCompleteListener; import com.swirlds.platform.listeners.ReconnectCompleteNotification; import com.swirlds.platform.listeners.StateWriteToDiskCompleteListener; -import com.swirlds.platform.roster.RosterUtils; import com.swirlds.platform.state.MerkleRoot; import com.swirlds.platform.state.PlatformMerkleStateRoot; import com.swirlds.platform.state.service.PlatformStateService; @@ -146,7 +146,6 @@ import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.SwirldMain; -import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.state.notifications.StateHashedListener; import com.swirlds.platform.system.status.PlatformStatus; @@ -540,7 +539,6 @@ public void initializeStatesApi( @NonNull final State state, @NonNull final Metrics metrics, @NonNull final InitTrigger trigger, - @Nullable final AddressBook genesisAddressBook, @NonNull final Configuration platformConfiguration) { requireNonNull(state); requireNonNull(platformConfiguration); @@ -569,7 +567,7 @@ public void initializeStatesApi( throw new IllegalStateException("Cannot downgrade from " + savedStateVersion + " to " + version); } try { - migrateSchemas(state, savedStateVersion, trigger, metrics, genesisAddressBook, platformConfiguration); + migrateSchemas(state, savedStateVersion, trigger, metrics, platformConfiguration); logConfiguration(); } catch (final Throwable t) { logger.fatal("Critical failure during schema migration", t); @@ -598,12 +596,7 @@ public void onStateInitialized( } this.platform = requireNonNull(platform); if (state.getReadableStates(PlatformStateService.NAME).isEmpty()) { - initializeStatesApi( - state, - metrics, - trigger, - RosterUtils.buildAddressBook(platform.getRoster()), - platform.getContext().getConfiguration()); + initializeStatesApi(state, metrics, trigger, platform.getContext().getConfiguration()); } // With the States API grounded in the working state, we can create the object graph from it initializeDagger(state, trigger); @@ -621,7 +614,6 @@ public void onStateInitialized( * @param state current state * @param deserializedVersion version deserialized * @param trigger trigger that is calling migration - * @param genesisAddressBook the genesis address book, if applicable * @param platformConfiguration platform configuration */ private void migrateSchemas( @@ -629,7 +621,6 @@ private void migrateSchemas( @Nullable final ServicesSoftwareVersion deserializedVersion, @NonNull final InitTrigger trigger, @NonNull final Metrics metrics, - @Nullable final AddressBook genesisAddressBook, @NonNull final Configuration platformConfiguration) { final var previousVersion = deserializedVersion == null ? null : deserializedVersion.getPbjSemanticVersion(); final var isUpgrade = version.compareTo(deserializedVersion) > 0; @@ -641,17 +632,19 @@ private void migrateSchemas( .orElse(null)), () -> HapiUtils.toString(version.getPbjSemanticVersion()), () -> trigger); + startupNetworks = startupNetworksFactory.apply(selfNodeId.id(), configProvider, tssBaseService); // This is set only when the trigger is genesis. Because, only in those cases // the migration code is using the network info values. NetworkInfo genesisNetworkInfo = null; if (trigger == GENESIS) { final var config = configProvider.getConfiguration(); final var ledgerConfig = config.getConfigData(LedgerConfig.class); - final var genesisRoster = buildRoster(requireNonNull(genesisAddressBook)); + final var genesisRoster = new Roster(startupNetworks.genesisNetworkOrThrow().nodeMetadata().stream() + .map(NodeMetadata::rosterEntryOrThrow) + .toList()); genesisNetworkInfo = new GenesisNetworkInfo(genesisRoster, ledgerConfig.id()); } blockStreamService.resetMigratedLastBlockHash(); - startupNetworks = startupNetworksFactory.apply(selfNodeId.id(), configProvider, tssBaseService); PLATFORM_STATE_SERVICE.setAppVersionFn(() -> version); PLATFORM_STATE_SERVICE.setActiveRosterFn( () -> new ReadableRosterStoreImpl(state.getReadableStates(RosterService.NAME)).getActiveRoster()); diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java index f14c3365a5fd..4d1a6227672d 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java @@ -235,11 +235,7 @@ public static void main(final String... args) throws Exception { isGenesis.set(true); final var genesisState = hedera.newMerkleStateRoot(); hedera.initializeStatesApi( - (MerkleStateRoot) genesisState, - metrics, - InitTrigger.GENESIS, - diskAddressBook, - configuration); + (MerkleStateRoot) genesisState, metrics, InitTrigger.GENESIS, configuration); return genesisState; }, Hedera.APP_NAME, @@ -252,7 +248,6 @@ public static void main(final String... args) throws Exception { (MerkleStateRoot) initialState.get().getState().getSwirldState(), metrics, InitTrigger.RESTART, - null, configuration); } diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java index 659236e75168..40b46bef4f2b 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java @@ -147,8 +147,7 @@ public void start() { final Configuration configuration = ConfigurationBuilder.create().autoDiscoverExtensions().build(); - hedera.initializeStatesApi( - state, fakePlatform().getContext().getMetrics(), GENESIS, addressBook, configuration); + hedera.initializeStatesApi(state, fakePlatform().getContext().getMetrics(), GENESIS, configuration); // TODO - remove this after https://github.com/hashgraph/hedera-services/issues/16552 is done // and we are running all CI tests with the Roster lifecycle enabled diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java index 5a7cd9891822..cad3547f89bf 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java @@ -243,7 +243,7 @@ public StateChangesValidator( .withConfigDataType(TemporaryFileConfig.class) .withConfigDataType(StateCommonConfig.class) .build(); - hedera.initializeStatesApi(state, metrics, InitTrigger.GENESIS, addressBook, platformConfig); + hedera.initializeStatesApi(state, metrics, InitTrigger.GENESIS, platformConfig); initGenesisPlatformState(platformConfig, this.state.getWritablePlatformState(), addressBook, currentVersion); final var stateToBeCopied = state; state = state.copy(); From 0925fe25246a44cc099f24a863d36fbba07259f2 Mon Sep 17 00:00:00 2001 From: Miroslav Gatsanoga Date: Thu, 28 Nov 2024 17:55:33 +0200 Subject: [PATCH 4/6] fix: failing CI check due to StateChangesValidator genesis setup Signed-off-by: Miroslav Gatsanoga --- .../block/StateChangesValidator.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java index cad3547f89bf..36eb43404af8 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java @@ -19,7 +19,10 @@ import static com.hedera.node.app.blocks.impl.BlockImplUtils.combine; import static com.hedera.node.app.hapi.utils.CommonUtils.noThrowSha384HashOf; import static com.hedera.node.app.hapi.utils.CommonUtils.sha384DigestOrThrow; +import static com.hedera.node.app.info.DiskStartupNetworks.ARCHIVE; +import static com.hedera.node.app.info.DiskStartupNetworks.GENESIS_NETWORK_JSON; import static com.hedera.services.bdd.junit.hedera.ExternalPath.APPLICATION_PROPERTIES; +import static com.hedera.services.bdd.junit.hedera.ExternalPath.DATA_CONFIG_DIR; import static com.hedera.services.bdd.junit.hedera.ExternalPath.SAVED_STATES_DIR; import static com.hedera.services.bdd.junit.hedera.ExternalPath.SWIRLDS_LOG; import static com.hedera.services.bdd.junit.hedera.NodeSelector.byNodeId; @@ -184,6 +187,23 @@ public static StateChangesValidator newValidatorFor(@NonNull final HapiSpec spec final var node0 = subProcessNetwork.getRequiredNode(byNodeId(0)); final var genesisConfigTxt = node0.metadata().workingDirOrThrow().resolve("genesis-config.txt"); Files.writeString(genesisConfigTxt, subProcessNetwork.genesisConfigTxt()); + + // restore archived genesis-network.json + final var archivedGenesisNetwork = + node0.getExternalPath(DATA_CONFIG_DIR).resolve(ARCHIVE).resolve(GENESIS_NETWORK_JSON); + try { + if (Files.exists(archivedGenesisNetwork)) { + final var dest = node0.getExternalPath(DATA_CONFIG_DIR).resolve(GENESIS_NETWORK_JSON); + Files.move(archivedGenesisNetwork, dest); + } + } catch (IOException e) { + logger.warn("Failed to restore {} from archive", GENESIS_NETWORK_JSON, e); + } + + System.setProperty( + "networkAdmin.upgradeSysFilesLoc", + node0.getExternalPath(DATA_CONFIG_DIR).toAbsolutePath().toString()); + return new StateChangesValidator( rootHash, node0.getExternalPath(SWIRLDS_LOG), From 441f1d5514a93b3956ffed970a4f0844aadf19b5 Mon Sep 17 00:00:00 2001 From: Miroslav Gatsanoga Date: Mon, 2 Dec 2024 17:11:14 +0200 Subject: [PATCH 5/6] fix: revert genesisiAddressBook param changes Signed-off-by: Miroslav Gatsanoga --- .../main/java/com/hedera/node/app/Hedera.java | 30 +++++++++++++++---- .../com/hedera/node/app/ServicesMain.java | 8 ++++- .../embedded/AbstractEmbeddedHedera.java | 3 +- .../block/StateChangesValidator.java | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java index 6fce533d155c..3a85a2272adc 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java @@ -117,7 +117,6 @@ import com.hedera.node.config.data.TssConfig; import com.hedera.node.config.data.VersionConfig; import com.hedera.node.config.types.StreamMode; -import com.hedera.node.internal.network.NodeMetadata; import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; @@ -136,6 +135,8 @@ import com.swirlds.platform.listeners.ReconnectCompleteListener; import com.swirlds.platform.listeners.ReconnectCompleteNotification; import com.swirlds.platform.listeners.StateWriteToDiskCompleteListener; +import com.swirlds.platform.roster.RosterHistory; +import com.swirlds.platform.roster.RosterUtils; import com.swirlds.platform.state.MerkleRoot; import com.swirlds.platform.state.PlatformMerkleStateRoot; import com.swirlds.platform.state.service.PlatformStateService; @@ -146,6 +147,7 @@ import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.state.notifications.StateHashedListener; import com.swirlds.platform.system.status.PlatformStatus; @@ -352,6 +354,8 @@ public final class Hedera implements SwirldMain, PlatformStatusChangeListener, A @Nullable private StartupNetworks startupNetworks; + private RosterHistory rosterHistory; + @FunctionalInterface public interface TssBaseServiceFactory { @NonNull @@ -539,6 +543,7 @@ public void initializeStatesApi( @NonNull final State state, @NonNull final Metrics metrics, @NonNull final InitTrigger trigger, + @Nullable final AddressBook genesisAddressBook, @NonNull final Configuration platformConfiguration) { requireNonNull(state); requireNonNull(platformConfiguration); @@ -567,7 +572,7 @@ public void initializeStatesApi( throw new IllegalStateException("Cannot downgrade from " + savedStateVersion + " to " + version); } try { - migrateSchemas(state, savedStateVersion, trigger, metrics, platformConfiguration); + migrateSchemas(state, savedStateVersion, trigger, metrics, genesisAddressBook, platformConfiguration); logConfiguration(); } catch (final Throwable t) { logger.fatal("Critical failure during schema migration", t); @@ -596,7 +601,12 @@ public void onStateInitialized( } this.platform = requireNonNull(platform); if (state.getReadableStates(PlatformStateService.NAME).isEmpty()) { - initializeStatesApi(state, metrics, trigger, platform.getContext().getConfiguration()); + initializeStatesApi( + state, + metrics, + trigger, + RosterUtils.buildAddressBook(this.rosterHistory.getCurrentRoster()), + platform.getContext().getConfiguration()); } // With the States API grounded in the working state, we can create the object graph from it initializeDagger(state, trigger); @@ -621,6 +631,7 @@ private void migrateSchemas( @Nullable final ServicesSoftwareVersion deserializedVersion, @NonNull final InitTrigger trigger, @NonNull final Metrics metrics, + @Nullable final AddressBook genesisAddressBook, @NonNull final Configuration platformConfiguration) { final var previousVersion = deserializedVersion == null ? null : deserializedVersion.getPbjSemanticVersion(); final var isUpgrade = version.compareTo(deserializedVersion) > 0; @@ -639,9 +650,7 @@ private void migrateSchemas( if (trigger == GENESIS) { final var config = configProvider.getConfiguration(); final var ledgerConfig = config.getConfigData(LedgerConfig.class); - final var genesisRoster = new Roster(startupNetworks.genesisNetworkOrThrow().nodeMetadata().stream() - .map(NodeMetadata::rosterEntryOrThrow) - .toList()); + final var genesisRoster = buildRoster(requireNonNull(genesisAddressBook)); genesisNetworkInfo = new GenesisNetworkInfo(genesisRoster, ledgerConfig.id()); } blockStreamService.resetMigratedLastBlockHash(); @@ -906,6 +915,15 @@ public void setInitialStateHash(@NonNull final Hash stateHash) { initialStateHashFuture = completedFuture(stateHash.getBytes()); } + /** + * Called to set the roster history used when building the platform. + * + * @param rosterHistory the roster history used when building the platform + */ + public void setRosterHistory(@NonNull final RosterHistory rosterHistory) { + this.rosterHistory = rosterHistory; + } + /*================================================================================================================== * * Exposed for use by embedded Hedera diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java index 4d1a6227672d..c9c1b9bf301c 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java @@ -235,7 +235,11 @@ public static void main(final String... args) throws Exception { isGenesis.set(true); final var genesisState = hedera.newMerkleStateRoot(); hedera.initializeStatesApi( - (MerkleStateRoot) genesisState, metrics, InitTrigger.GENESIS, configuration); + (MerkleStateRoot) genesisState, + metrics, + InitTrigger.GENESIS, + diskAddressBook, + configuration); return genesisState; }, Hedera.APP_NAME, @@ -248,6 +252,7 @@ public static void main(final String... args) throws Exception { (MerkleStateRoot) initialState.get().getState().getSwirldState(), metrics, InitTrigger.RESTART, + null, configuration); } @@ -308,6 +313,7 @@ public static void main(final String... args) throws Exception { .withConfiguration(configuration) .withKeysAndCerts(keysAndCerts); + hedera.setRosterHistory(rosterHistory); hedera.setInitialStateHash(stateHash); // IMPORTANT: A surface-level reading of this method will undersell the centrality // of the Hedera instance. It is actually omnipresent throughout both the startup diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java index 40b46bef4f2b..659236e75168 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/AbstractEmbeddedHedera.java @@ -147,7 +147,8 @@ public void start() { final Configuration configuration = ConfigurationBuilder.create().autoDiscoverExtensions().build(); - hedera.initializeStatesApi(state, fakePlatform().getContext().getMetrics(), GENESIS, configuration); + hedera.initializeStatesApi( + state, fakePlatform().getContext().getMetrics(), GENESIS, addressBook, configuration); // TODO - remove this after https://github.com/hashgraph/hedera-services/issues/16552 is done // and we are running all CI tests with the Roster lifecycle enabled diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java index 36eb43404af8..96ab645d3058 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java @@ -263,7 +263,7 @@ public StateChangesValidator( .withConfigDataType(TemporaryFileConfig.class) .withConfigDataType(StateCommonConfig.class) .build(); - hedera.initializeStatesApi(state, metrics, InitTrigger.GENESIS, platformConfig); + hedera.initializeStatesApi(state, metrics, InitTrigger.GENESIS, addressBook, platformConfig); initGenesisPlatformState(platformConfig, this.state.getWritablePlatformState(), addressBook, currentVersion); final var stateToBeCopied = state; state = state.copy(); From 31b83d32eeff9a3ef73e2a7de6e32d02907b7fa1 Mon Sep 17 00:00:00 2001 From: Miroslav Gatsanoga Date: Mon, 2 Dec 2024 18:11:49 +0200 Subject: [PATCH 6/6] fix: revert more unneeded changes Signed-off-by: Miroslav Gatsanoga --- .../main/java/com/hedera/node/app/Hedera.java | 3 ++- .../block/StateChangesValidator.java | 20 ------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java index 3a85a2272adc..a5df45dbbced 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java @@ -624,6 +624,7 @@ public void onStateInitialized( * @param state current state * @param deserializedVersion version deserialized * @param trigger trigger that is calling migration + * @param genesisAddressBook the genesis address book, if applicable * @param platformConfiguration platform configuration */ private void migrateSchemas( @@ -643,7 +644,6 @@ private void migrateSchemas( .orElse(null)), () -> HapiUtils.toString(version.getPbjSemanticVersion()), () -> trigger); - startupNetworks = startupNetworksFactory.apply(selfNodeId.id(), configProvider, tssBaseService); // This is set only when the trigger is genesis. Because, only in those cases // the migration code is using the network info values. NetworkInfo genesisNetworkInfo = null; @@ -654,6 +654,7 @@ private void migrateSchemas( genesisNetworkInfo = new GenesisNetworkInfo(genesisRoster, ledgerConfig.id()); } blockStreamService.resetMigratedLastBlockHash(); + startupNetworks = startupNetworksFactory.apply(selfNodeId.id(), configProvider, tssBaseService); PLATFORM_STATE_SERVICE.setAppVersionFn(() -> version); PLATFORM_STATE_SERVICE.setActiveRosterFn( () -> new ReadableRosterStoreImpl(state.getReadableStates(RosterService.NAME)).getActiveRoster()); diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java index 96ab645d3058..5a7cd9891822 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/support/validators/block/StateChangesValidator.java @@ -19,10 +19,7 @@ import static com.hedera.node.app.blocks.impl.BlockImplUtils.combine; import static com.hedera.node.app.hapi.utils.CommonUtils.noThrowSha384HashOf; import static com.hedera.node.app.hapi.utils.CommonUtils.sha384DigestOrThrow; -import static com.hedera.node.app.info.DiskStartupNetworks.ARCHIVE; -import static com.hedera.node.app.info.DiskStartupNetworks.GENESIS_NETWORK_JSON; import static com.hedera.services.bdd.junit.hedera.ExternalPath.APPLICATION_PROPERTIES; -import static com.hedera.services.bdd.junit.hedera.ExternalPath.DATA_CONFIG_DIR; import static com.hedera.services.bdd.junit.hedera.ExternalPath.SAVED_STATES_DIR; import static com.hedera.services.bdd.junit.hedera.ExternalPath.SWIRLDS_LOG; import static com.hedera.services.bdd.junit.hedera.NodeSelector.byNodeId; @@ -187,23 +184,6 @@ public static StateChangesValidator newValidatorFor(@NonNull final HapiSpec spec final var node0 = subProcessNetwork.getRequiredNode(byNodeId(0)); final var genesisConfigTxt = node0.metadata().workingDirOrThrow().resolve("genesis-config.txt"); Files.writeString(genesisConfigTxt, subProcessNetwork.genesisConfigTxt()); - - // restore archived genesis-network.json - final var archivedGenesisNetwork = - node0.getExternalPath(DATA_CONFIG_DIR).resolve(ARCHIVE).resolve(GENESIS_NETWORK_JSON); - try { - if (Files.exists(archivedGenesisNetwork)) { - final var dest = node0.getExternalPath(DATA_CONFIG_DIR).resolve(GENESIS_NETWORK_JSON); - Files.move(archivedGenesisNetwork, dest); - } - } catch (IOException e) { - logger.warn("Failed to restore {} from archive", GENESIS_NETWORK_JSON, e); - } - - System.setProperty( - "networkAdmin.upgradeSysFilesLoc", - node0.getExternalPath(DATA_CONFIG_DIR).toAbsolutePath().toString()); - return new StateChangesValidator( rootHash, node0.getExternalPath(SWIRLDS_LOG),