Skip to content

Commit

Permalink
Changed genesisNetworkInfo to activeNetworkInfo.
Browse files Browse the repository at this point in the history
Signed-off-by: Iris Simon <[email protected]>
  • Loading branch information
iwsimon committed Nov 13, 2024
1 parent fbed355 commit 0211b80
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityNumber, Node> writableNodes =
ctx.newStates().get(NODES_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -589,17 +588,12 @@ private List<StateChanges.Builder> 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());

Check warning on line 596 in hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java

View check run for this annotation

Codecov / codecov/patch

hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java#L592-L596

Added lines #L592 - L596 were not covered by tests
final List<StateChanges.Builder> migrationStateChanges = new ArrayList<>();
if (isNotEmbedded()) {
if (!(state instanceof MerkleStateRoot merkleStateRoot)) {
Expand All @@ -617,7 +611,7 @@ private List<StateChanges.Builder> onMigrate(
deserializedVersion,
version,
configProvider.getConfiguration(),
genesisNetworkInfo,
activeNetworkInfo,
metrics);
migrationStateChanges.addAll(migrationChanges);
kvStateChangeListener.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> sharedValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,7 +75,7 @@ public List<StateChanges.Builder> 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);
Expand All @@ -98,7 +98,7 @@ public List<StateChanges.Builder> doMigrations(
deserializedPbjVersion,
currentVersion.getPbjSemanticVersion(),
config,
genesisNetworkInfo,
activeNetworkInfo,
metrics,
// We call with null here because we're migrating the entity ID service itself
null,
Expand Down Expand Up @@ -135,7 +135,7 @@ public List<StateChanges.Builder> doMigrations(
deserializedPbjVersion,
currentVersion.getPbjSemanticVersion(),
config,
genesisNetworkInfo,
activeNetworkInfo,
metrics,
entityIdStore,
sharedValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -51,7 +51,7 @@ List<StateChanges.Builder> doMigrations(
@Nullable SoftwareVersion previousVersion,
@NonNull SoftwareVersion currentVersion,
@NonNull Configuration config,
@Nullable NetworkInfo genesisNetworkInfo,
@Nullable NetworkInfo activeNetworkInfo,
@NonNull Metrics metrics);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, Object> sharedValues,
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Configuration configuration() {
}

@Override
public NetworkInfo genesisNetworkInfo() {
public NetworkInfo activeNetworkInfo() {
return networkInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public List<StateChanges.Builder> 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)) {
Expand Down Expand Up @@ -84,7 +84,7 @@ public List<StateChanges.Builder> doMigrations(
NAME_OF_ENTITY_ID_SERVICE,
fakeState,
deserializedPbjVersion,
networkInfo,
activeNetworkInfo,
config,
sharedValues,
prevEntityNum);
Expand All @@ -98,7 +98,7 @@ public List<StateChanges.Builder> doMigrations(
registration.serviceName(),
fakeState,
deserializedPbjVersion,
networkInfo,
activeNetworkInfo,
config,
sharedValues,
prevEntityNum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0211b80

Please sign in to comment.