diff --git a/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V053AddressBookSchema.java b/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V053AddressBookSchema.java index 9e2472464a5f..e736bd8f8ee5 100644 --- a/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V053AddressBookSchema.java +++ b/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V053AddressBookSchema.java @@ -93,7 +93,7 @@ public void migrate(@NonNull final MigrationContext ctx) { ? parseEd25519NodeAdminKeysFrom( ctx.configuration().getConfigData(BootstrapConfig.class).nodeAdminKeysPath()) : emptyMap(); - final var networkInfo = ctx.genesisNetworkInfo(); + final var networkInfo = ctx.activeNetworkInfo(); if (networkInfo == null) { throw new IllegalStateException("Genesis network info is not found"); } diff --git a/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V056AddressBookSchema.java b/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V056AddressBookSchema.java index 6078161db684..50fe9a7df91c 100644 --- a/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V056AddressBookSchema.java +++ b/hedera-node/hedera-addressbook-service-impl/src/main/java/com/hedera/node/app/service/addressbook/impl/schemas/V056AddressBookSchema.java @@ -73,9 +73,9 @@ public void migrate(@NonNull final MigrationContext ctx) { return; } - final NetworkInfo networkInfo = ctx.genesisNetworkInfo(); + final NetworkInfo networkInfo = ctx.activeNetworkInfo(); if (networkInfo == null) { - throw new IllegalStateException("Genesis network info is not found"); + throw new IllegalStateException("Active network info is not found"); } final WritableKVState writableNodes = ctx.newStates().get(NODES_KEY); diff --git a/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V053AddressBookSchemaTest.java b/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V053AddressBookSchemaTest.java index d2aa8440cdaa..7f64a6d4c7e7 100644 --- a/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V053AddressBookSchemaTest.java +++ b/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V053AddressBookSchemaTest.java @@ -270,7 +270,7 @@ void migrateAsExpected4() throws IOException { @Test void failedNullNetworkinfo() { - given(migrationContext.genesisNetworkInfo()).willReturn(null); + given(migrationContext.activeNetworkInfo()).willReturn(null); assertThatCode(() -> subject.migrate(migrationContext)) .isInstanceOf(IllegalStateException.class) .hasMessage("Genesis network info is not found"); @@ -300,7 +300,7 @@ private void setupMigrationContext() { List.of(endpointFor("23.45.34.243", 45), endpointFor("127.0.0.3", 124)), Bytes.wrap(grpcCertificateHash)); given(networkInfo.addressBook()).willReturn(List.of(nodeInfo1, nodeInfo2, nodeInfo3)); - given(migrationContext.genesisNetworkInfo()).willReturn(networkInfo); + given(migrationContext.activeNetworkInfo()).willReturn(networkInfo); final var config = HederaTestConfigBuilder.create() .withValue("bootstrap.genesisPublicKey", defaultAdminKeyBytes) .getOrCreateConfig(); diff --git a/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V056AddressBookSchemaTest.java b/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V056AddressBookSchemaTest.java index 3e50858f26a4..888527f56e52 100644 --- a/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V056AddressBookSchemaTest.java +++ b/hedera-node/hedera-addressbook-service-impl/src/test/java/com/hedera/node/app/service/addressbook/impl/test/schemas/V056AddressBookSchemaTest.java @@ -131,7 +131,7 @@ void migrateFailedWithNotGoodNodeDetailFile() { @Test void failedNullNetworkInfo() { given(migrationContext.previousVersion()).willReturn(version); - given(migrationContext.genesisNetworkInfo()).willReturn(null); + given(migrationContext.activeNetworkInfo()).willReturn(null); assertThatCode(() -> subject.migrate(migrationContext)) .isInstanceOf(IllegalStateException.class) .hasMessage("Genesis network info is not found"); @@ -238,7 +238,7 @@ private void setupMigrationContext() { List.of(endpointFor("23.45.34.243", 45), endpointFor("127.0.0.3", 124)), Bytes.wrap(grpcCertificateHash)); given(networkInfo.addressBook()).willReturn(List.of(nodeInfo1, nodeInfo2, nodeInfo3)); - given(migrationContext.genesisNetworkInfo()).willReturn(networkInfo); + given(migrationContext.activeNetworkInfo()).willReturn(networkInfo); writableStates = MapWritableStates.builder().state(writableNodes).build(); given(migrationContext.newStates()).willReturn(writableStates); 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 23dcb98b7448..71559c50818a 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 @@ -148,7 +148,6 @@ import com.swirlds.state.State; import com.swirlds.state.StateChangeListener; import com.swirlds.state.spi.WritableSingletonStateBase; -import com.swirlds.state.spi.info.NetworkInfo; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.nio.charset.Charset; @@ -589,17 +588,12 @@ private List onMigrate( .orElse(null)), () -> HapiUtils.toString(version.getPbjSemanticVersion()), () -> trigger); - // 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 readableStore = - new ReadablePlatformStateStore(state.getReadableStates(PlatformStateService.NAME)); - final var genesisRoster = createRoster(requireNonNull(readableStore.getAddressBook())); - genesisNetworkInfo = new GenesisNetworkInfo(genesisRoster, ledgerConfig.id()); - } + + final var config = configProvider.getConfiguration(); + final var ledgerConfig = config.getConfigData(LedgerConfig.class); + final var readableStore = new ReadablePlatformStateStore(state.getReadableStates(PlatformStateService.NAME)); + final var genesisRoster = createRoster(requireNonNull(readableStore.getAddressBook())); + final var activeNetworkInfo = new GenesisNetworkInfo(genesisRoster, ledgerConfig.id()); final List migrationStateChanges = new ArrayList<>(); if (isNotEmbedded()) { if (!(state instanceof MerkleStateRoot merkleStateRoot)) { @@ -617,7 +611,7 @@ private List onMigrate( deserializedVersion, version, configProvider.getConfiguration(), - genesisNetworkInfo, + activeNetworkInfo, metrics); migrationStateChanges.addAll(migrationChanges); kvStateChangeListener.reset(); diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/MigrationContextImpl.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/MigrationContextImpl.java index 47b2ed7d27fa..191f29e09d25 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/MigrationContextImpl.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/MigrationContextImpl.java @@ -46,7 +46,7 @@ public record MigrationContextImpl( @NonNull ReadableStates previousStates, @NonNull WritableStates newStates, @NonNull Configuration configuration, - @Nullable NetworkInfo genesisNetworkInfo, + @Nullable NetworkInfo activeNetworkInfo, @Nullable WritableEntityIdStore writableEntityIdStore, @Nullable SemanticVersion previousVersion, @NonNull Map sharedValues) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/OrderedServiceMigrator.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/OrderedServiceMigrator.java index 41e660116c01..480aeb2f38e9 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/OrderedServiceMigrator.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/OrderedServiceMigrator.java @@ -63,7 +63,7 @@ public class OrderedServiceMigrator implements ServiceMigrator { * @param previousVersion The previous version of the state * @param currentVersion The current version of the state * @param config The configuration to use for the migrations - * @param genesisNetworkInfo The network information to use for the migrations. + * @param activeNetworkInfo The network information to use for the migrations. * This is only used in genesis case * @param metrics The metrics to use for the migrations * @return The list of state changes that occurred during the migrations @@ -75,7 +75,7 @@ public List doMigrations( @Nullable final SoftwareVersion previousVersion, @NonNull final SoftwareVersion currentVersion, @NonNull final Configuration config, - @Nullable final NetworkInfo genesisNetworkInfo, + @Nullable final NetworkInfo activeNetworkInfo, @NonNull final Metrics metrics) { requireNonNull(state); requireNonNull(currentVersion); @@ -98,7 +98,7 @@ public List doMigrations( deserializedPbjVersion, currentVersion.getPbjSemanticVersion(), config, - genesisNetworkInfo, + activeNetworkInfo, metrics, // We call with null here because we're migrating the entity ID service itself null, @@ -135,7 +135,7 @@ public List doMigrations( deserializedPbjVersion, currentVersion.getPbjSemanticVersion(), config, - genesisNetworkInfo, + activeNetworkInfo, metrics, entityIdStore, sharedValues, diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/ServiceMigrator.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/ServiceMigrator.java index b8691b489664..7cb7d6a6df8f 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/ServiceMigrator.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/services/ServiceMigrator.java @@ -41,7 +41,7 @@ public interface ServiceMigrator { * @param previousVersion The previous version of the state * @param currentVersion The current version of the state * @param config The configuration to use for the migrations - * @param genesisNetworkInfo The network information to use for the migrations + * @param activeNetworkInfo The network information to use for the migrations * @param metrics The metrics to use for the migrations * @return The list of builders for state changes that occurred during the migrations */ @@ -51,7 +51,7 @@ List doMigrations( @Nullable SoftwareVersion previousVersion, @NonNull SoftwareVersion currentVersion, @NonNull Configuration config, - @Nullable NetworkInfo genesisNetworkInfo, + @Nullable NetworkInfo activeNetworkInfo, @NonNull Metrics metrics); /** diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java index ea04a326128f..d1b512105db0 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java @@ -179,7 +179,7 @@ private record RedefinedWritableStates(WritableStates beforeStates, WritableStat * @param currentVersion The current version. Never null. Must be newer than {@code * previousVersion}. * @param config The system configuration to use at the time of migration - * @param genesisNetworkInfo The network information to use at the time of migration + * @param activeNetworkInfo The network information to use at the time of migration * @param sharedValues A map of shared values for cross-service migration patterns * @param migrationStateChanges Tracker for state changes during migration * @throws IllegalArgumentException if the {@code currentVersion} is not at least the @@ -192,7 +192,7 @@ public void migrate( @Nullable final SemanticVersion previousVersion, @NonNull final SemanticVersion currentVersion, @NonNull final Configuration config, - @Nullable final NetworkInfo genesisNetworkInfo, + @Nullable final NetworkInfo activeNetworkInfo, @NonNull final Metrics metrics, @Nullable final WritableEntityIdStore entityIdStore, @NonNull final Map sharedValues, @@ -257,13 +257,7 @@ && alreadyIncludesStateDefs(previousVersion, s.getVersion())) } final var migrationContext = new MigrationContextImpl( - previousStates, - newStates, - config, - genesisNetworkInfo, - entityIdStore, - previousVersion, - sharedValues); + previousStates, newStates, config, activeNetworkInfo, entityIdStore, previousVersion, sharedValues); if (applications.contains(MIGRATION)) { schema.migrate(migrationContext); } diff --git a/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeSchemaRegistry.java b/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeSchemaRegistry.java index b4712d57f604..3179b719327a 100644 --- a/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeSchemaRegistry.java +++ b/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeSchemaRegistry.java @@ -197,7 +197,7 @@ public Configuration configuration() { } @Override - public NetworkInfo genesisNetworkInfo() { + public NetworkInfo activeNetworkInfo() { return networkInfo; } diff --git a/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeServiceMigrator.java b/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeServiceMigrator.java index 3c7b30757d95..1b30cab17ea4 100644 --- a/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeServiceMigrator.java +++ b/hedera-node/hedera-app/src/testFixtures/java/com/hedera/node/app/fixtures/state/FakeServiceMigrator.java @@ -50,13 +50,13 @@ public List doMigrations( @Nullable final SoftwareVersion previousVersion, @NonNull final SoftwareVersion currentVersion, @NonNull final Configuration config, - @NonNull final NetworkInfo networkInfo, + @NonNull final NetworkInfo activeNetworkInfo, @NonNull final Metrics metrics) { requireNonNull(state); requireNonNull(servicesRegistry); requireNonNull(currentVersion); requireNonNull(config); - requireNonNull(networkInfo); + requireNonNull(activeNetworkInfo); requireNonNull(metrics); if (!(state instanceof FakeState fakeState)) { @@ -84,7 +84,7 @@ public List doMigrations( NAME_OF_ENTITY_ID_SERVICE, fakeState, deserializedPbjVersion, - networkInfo, + activeNetworkInfo, config, sharedValues, prevEntityNum); @@ -98,7 +98,7 @@ public List doMigrations( registration.serviceName(), fakeState, deserializedPbjVersion, - networkInfo, + activeNetworkInfo, config, sharedValues, prevEntityNum); diff --git a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0490TokenSchema.java b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0490TokenSchema.java index 6cc08b20dd0f..e1e8059d6a72 100644 --- a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0490TokenSchema.java +++ b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0490TokenSchema.java @@ -240,7 +240,7 @@ private void initializeStakingNodeInfo(@NonNull final MigrationContext ctx) { final var config = ctx.configuration(); final var ledgerConfig = config.getConfigData(LedgerConfig.class); final var stakingConfig = config.getConfigData(StakingConfig.class); - final var addressBook = ctx.genesisNetworkInfo().addressBook(); + final var addressBook = ctx.activeNetworkInfo().addressBook(); final var numberOfNodes = addressBook.size(); final long maxStakePerNode = ledgerConfig.totalTinyBarFloat() / numberOfNodes; diff --git a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0530TokenSchema.java b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0530TokenSchema.java index 918263f4e129..f7f13ebb2f4b 100644 --- a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0530TokenSchema.java +++ b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/V0530TokenSchema.java @@ -58,7 +58,7 @@ public void migrate(@NonNull final MigrationContext ctx) { private void setMinStakeToZero(final MigrationContext ctx) { final var stakingInfoState = ctx.newStates().get(STAKING_INFO_KEY); - final var addressBook = ctx.genesisNetworkInfo().addressBook(); + final var addressBook = ctx.activeNetworkInfo().addressBook(); logger.info("Setting minStake to 0 for all nodes in the address book"); for (final var node : addressBook) { final var nodeNumber = diff --git a/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/spi/MigrationContext.java b/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/spi/MigrationContext.java index 85dda7463157..6535b450a15d 100644 --- a/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/spi/MigrationContext.java +++ b/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/spi/MigrationContext.java @@ -58,13 +58,12 @@ public interface MigrationContext { Configuration configuration(); /** - * Information about the network itself. Generally, this is not useful information for migrations, but is used at - * genesis for the file service. In the future, this may no longer be required. + * Information about the current active network itself. * * @return The {@link NetworkInfo} of the network at the time of migration. */ @Nullable - NetworkInfo genesisNetworkInfo(); + NetworkInfo activeNetworkInfo(); /** * Consumes and returns the next entity number. For use by migrations that need to create entities.