Skip to content

Commit fe902ef

Browse files
committed
Merge branch 'develop' into 11556-entity-utilization-metrics-cherry-pick
* develop: feat: Introduce software update admin (#12489) feat: Remove getOtherId (#12465) fix: tokenAssociate throws IndexOutOfBoundsException (#12552) fix: enable HelloWorldEthereumSuite hapi tests (#11602) fix: tokenAssociate throws IndexOutOfBoundsException (#12453) fix: treat an out-of-range allowance amount as an invalid op (#12445) feat: restrict qualified delegates to appropriate transfer functions only (#12358) feat: move the JVM anchor into the wiring model (#12534) feat: Automate scheduler construction for the event deduplicator (#12527) feat: cleaner wiring for complete state nexus (#12502) fix: finalize stake metadata only once per transaction (#12537) feat: platform component builder (#12499) feat: address book serializes text hostnames (#12515) feat: improve bottom half of the wiring diagram (#12511) refactor: Migrate some tests to use event test util (#12471) test: security v2 model - add test for token associate with callcode (#12168) chore: Added extra-checks to prevent unchecked submits (#12436) chore: Change owner of DEV configuration (#12523) feat: construct schedulers automatically (#12504) feat: Cherry-pick: Pass Metrics to created VirtualMaps (#12495) # Conflicts: # hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/HandleContextImpl.java
2 parents 92900bb + 0683086 commit fe902ef

File tree

98 files changed

+1727
-668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1727
-668
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# Hedera Node Deployments - Configuration & Grafana Dashboards
1616
/hedera-node/configuration/** @rbair23 @dalvizu @poulok @netopyr @Nana-EC @SimiHunjan @steven-sheehy @nathanklick
17+
/hedera-node/configuration/dev/** @hashgraph/hedera-base @hashgraph/hedera-services
1718
/hedera-node/infrastructure/** @hashgraph/release-engineering @hashgraph/devops @hashgraph/hedera-base @hashgraph/hedera-services
1819

1920
# Hedera Node Docker Definitions

hedera-node/configuration/dev/application.properties

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ staking.fees.nodeRewardPercentage=10
99
staking.fees.stakingRewardPercentage=10
1010
# Needed for Restart and Reconnect HapiTests that run many transactions of each type
1111
bootstrap.throttleDefsJson.resource=genesis/throttles-dev.json
12+
ledger.id=0x03

hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ public void onStateInitialized(
463463
final VirtualMap<UniqueTokenKey, UniqueTokenValue> uniqTokensFromState = state.getChild(UNIQUE_TOKENS);
464464
if (uniqTokensFromState != null) {
465465
// Copy this virtual map, so it doesn't get released before the migration is done
466-
MONO_VIRTUAL_MAPS.add(uniqTokensFromState.copy());
466+
final var copy = uniqTokensFromState.copy();
467+
copy.registerMetrics(metrics);
468+
MONO_VIRTUAL_MAPS.add(copy);
467469
TOKEN_SERVICE.setNftsFromState(uniqTokensFromState);
468470
}
469471

@@ -472,7 +474,9 @@ public void onStateInitialized(
472474
state.getChild(TOKEN_ASSOCIATIONS);
473475
if (tokenRelsFromState != null) {
474476
// Copy this virtual map, so it doesn't get released before the migration is done
475-
MONO_VIRTUAL_MAPS.add(tokenRelsFromState.copy());
477+
final var copy = tokenRelsFromState.copy();
478+
copy.registerMetrics(metrics);
479+
MONO_VIRTUAL_MAPS.add(copy);
476480
TOKEN_SERVICE.setTokenRelsFromState(tokenRelsFromState);
477481
}
478482

@@ -486,7 +490,9 @@ public void onStateInitialized(
486490
final VirtualMap<VirtualBlobKey, VirtualBlobValue> filesFromState = state.getChild(STORAGE);
487491
if (filesFromState != null) {
488492
// Copy this virtual map, so it doesn't get released before the migration is done
489-
MONO_VIRTUAL_MAPS.add(filesFromState.copy());
493+
final var copy = filesFromState.copy();
494+
copy.registerMetrics(metrics);
495+
MONO_VIRTUAL_MAPS.add(copy);
490496

491497
// Note: some files have no metadata, e.g. contract bytecode files
492498
FILE_SERVICE.setFs(() -> VirtualMapLike.from(filesFromState));
@@ -499,7 +505,9 @@ public void onStateInitialized(
499505
final VirtualMap<EntityNumVirtualKey, OnDiskAccount> acctsFromState = state.getChild(ACCOUNTS);
500506
if (acctsFromState != null) {
501507
// Copy this virtual map, so it doesn't get released before the migration is done
502-
MONO_VIRTUAL_MAPS.add(acctsFromState.copy());
508+
final var copy = acctsFromState.copy();
509+
copy.registerMetrics(metrics);
510+
MONO_VIRTUAL_MAPS.add(copy);
503511
TOKEN_SERVICE.setAcctsFromState(acctsFromState);
504512
}
505513

@@ -536,7 +544,9 @@ public void onStateInitialized(
536544
final VirtualMap<ContractKey, IterableContractValue> contractFromStorage = state.getChild(CONTRACT_STORAGE);
537545
if (contractFromStorage != null) {
538546
// Copy this virtual map, so it doesn't get released before the migration is done
539-
MONO_VIRTUAL_MAPS.add(contractFromStorage.copy());
547+
final var copy = contractFromStorage.copy();
548+
copy.registerMetrics(metrics);
549+
MONO_VIRTUAL_MAPS.add(copy);
540550
CONTRACT_SERVICE.setStorageFromState(VirtualMapLike.from(contractFromStorage));
541551
}
542552

@@ -616,7 +626,7 @@ public void onStateInitialized(
616626
// here. This is intentional so as to avoid forgetting to handle a new trigger.
617627
try {
618628
switch (trigger) {
619-
case GENESIS -> genesis(state, platformState);
629+
case GENESIS -> genesis(state, platformState, metrics);
620630
case RECONNECT -> reconnect(state, deserializedVersion, platformState, metrics);
621631
case RESTART, EVENT_STREAM_RECOVERY -> restart(
622632
state, deserializedVersion, trigger, platformState, metrics);
@@ -653,7 +663,8 @@ public void onStateInitialized(
653663
private void onMigrate(
654664
@NonNull final MerkleHederaState state,
655665
@Nullable final HederaSoftwareVersion deserializedVersion,
656-
@NonNull final InitTrigger trigger) {
666+
@NonNull final InitTrigger trigger,
667+
@NonNull final Metrics metrics) {
657668
final var currentVersion = version.getServicesVersion();
658669
final var previousVersion = deserializedVersion == null ? null : deserializedVersion.getServicesVersion();
659670
logger.info(
@@ -669,7 +680,8 @@ private void onMigrate(
669680

670681
final var migrator = new OrderedServiceMigrator(servicesRegistry);
671682
logger.info("Migration versions are {} to {}", previousVersion, currentVersion);
672-
migrator.doMigrations(state, currentVersion, previousVersion, configProvider.getConfiguration(), networkInfo);
683+
migrator.doMigrations(
684+
state, currentVersion, previousVersion, configProvider.getConfiguration(), networkInfo, metrics);
673685

674686
// Now that migrations are complete, clean up the leftover virtual maps
675687
MONO_VIRTUAL_MAPS.forEach(vm -> {
@@ -976,10 +988,13 @@ public void shutdownGrpcServer() {
976988
/**
977989
* Implements the code flow for initializing the state of a new Hedera node with NO SAVED STATE.
978990
*/
979-
private void genesis(@NonNull final MerkleHederaState state, @NonNull final PlatformState platformState) {
991+
private void genesis(
992+
@NonNull final MerkleHederaState state,
993+
@NonNull final PlatformState platformState,
994+
@NonNull final Metrics metrics) {
980995
logger.debug("Genesis Initialization");
981996
// Create all the nodes in the merkle tree for all the services
982-
onMigrate(state, null, GENESIS);
997+
onMigrate(state, null, GENESIS, metrics);
983998
// Now that we have the state created, we are ready to create the dependency graph with Dagger
984999
initializeDagger(state, GENESIS, platformState);
9851000
// And now that the entire dependency graph has been initialized, and we have config, and all migration has
@@ -1051,7 +1066,7 @@ private void initializeForTrigger(
10511066
// Create all the nodes in the merkle tree for all the services
10521067
// TODO: Actually, we should reinitialize the config on each step along the migration path, so we should pass
10531068
// the config provider to the migration code and let it get the right version of config as it goes.
1054-
onMigrate(state, deserializedVersion, trigger);
1069+
onMigrate(state, deserializedVersion, trigger, metrics);
10551070
if (trigger == EVENT_STREAM_RECOVERY) {
10561071
// (FUTURE) Dump post-migration mod-service state
10571072
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/OrderedServiceMigrator.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.hedera.node.app.state.merkle.MerkleHederaState;
2929
import com.hedera.node.app.state.merkle.MerkleSchemaRegistry;
3030
import com.hedera.node.config.VersionedConfiguration;
31+
import com.swirlds.metrics.api.Metrics;
3132
import edu.umd.cs.findbugs.annotations.NonNull;
3233
import edu.umd.cs.findbugs.annotations.Nullable;
3334
import java.util.Comparator;
@@ -62,11 +63,13 @@ public void doMigrations(
6263
@NonNull final SemanticVersion currentVersion,
6364
@Nullable final SemanticVersion previousVersion,
6465
@NonNull final VersionedConfiguration versionedConfiguration,
65-
@NonNull final NetworkInfo networkInfo) {
66+
@NonNull final NetworkInfo networkInfo,
67+
@NonNull final Metrics metrics) {
6668
requireNonNull(state);
6769
requireNonNull(currentVersion);
6870
requireNonNull(versionedConfiguration);
6971
requireNonNull(networkInfo);
72+
requireNonNull(metrics);
7073

7174
logger.info("Migrating Entity ID Service as pre-requisite for other services");
7275
final var entityIdRegistration = servicesRegistry.registrations().stream()
@@ -80,6 +83,7 @@ public void doMigrations(
8083
currentVersion,
8184
versionedConfiguration,
8285
networkInfo,
86+
metrics,
8387
// We call with null here because we're migrating the entity ID service itself
8488
null);
8589

@@ -116,6 +120,7 @@ public void doMigrations(
116120
currentVersion,
117121
versionedConfiguration,
118122
networkInfo,
123+
metrics,
119124
// If we have reached this point in the code, entityIdStore should not be null because the
120125
// EntityIdService should have been migrated already. We enforce with requireNonNull in case
121126
// there are scenarios we haven't considered.

hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
import static com.swirlds.common.io.utility.FileUtils.getAbsolutePath;
2020
import static com.swirlds.logging.legacy.LogMarker.EXCEPTION;
21-
import static com.swirlds.platform.PlatformBuilder.DEFAULT_SETTINGS_FILE_NAME;
22-
import static com.swirlds.platform.PlatformBuilder.buildPlatformContext;
21+
import static com.swirlds.platform.builder.PlatformBuildConstants.DEFAULT_CONFIG_FILE_NAME;
22+
import static com.swirlds.platform.builder.PlatformBuildConstants.DEFAULT_SETTINGS_FILE_NAME;
23+
import static com.swirlds.platform.builder.PlatformBuilder.buildPlatformContext;
2324
import static com.swirlds.platform.system.SystemExitCode.CONFIGURATION_ERROR;
2425
import static com.swirlds.platform.system.SystemExitCode.NODE_ADDRESS_MISMATCH;
2526
import static com.swirlds.platform.system.SystemExitUtils.exitSystem;
@@ -37,7 +38,7 @@
3738
import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource;
3839
import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource;
3940
import com.swirlds.platform.CommandLineArgs;
40-
import com.swirlds.platform.PlatformBuilder;
41+
import com.swirlds.platform.builder.PlatformBuilder;
4142
import com.swirlds.platform.config.legacy.ConfigurationException;
4243
import com.swirlds.platform.config.legacy.LegacyConfigProperties;
4344
import com.swirlds.platform.config.legacy.LegacyConfigPropertiesLoader;
@@ -128,7 +129,7 @@ public static void main(final String... args) throws Exception {
128129

129130
// Determine which node to run locally
130131
// Load config.txt address book file and parse address book
131-
final AddressBook addressBook = loadAddressBook(PlatformBuilder.DEFAULT_CONFIG_FILE_NAME);
132+
final AddressBook addressBook = loadAddressBook(DEFAULT_CONFIG_FILE_NAME);
132133
// parse command line arguments
133134
final CommandLineArgs commandLineArgs = CommandLineArgs.parse(args);
134135

@@ -160,7 +161,7 @@ public static void main(final String... args) throws Exception {
160161
buildPlatformContext(config, getAbsolutePath(DEFAULT_SETTINGS_FILE_NAME), selfId);
161162

162163
final PlatformBuilder builder =
163-
new PlatformBuilder(Hedera.APP_NAME, Hedera.SWIRLD_NAME, version, hedera::newState, selfId);
164+
PlatformBuilder.create(Hedera.APP_NAME, Hedera.SWIRLD_NAME, version, hedera::newState, selfId);
164165

165166
builder.withPreviousSoftwareVersionClassId(0x6f2b1bc2df8cbd0bL /* SerializableSemVers.CLASS_ID */);
166167
builder.withPlatformContext(platformContext);

hedera-node/hedera-app/src/main/java/com/hedera/node/app/authorization/PrivilegesVerifier.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ private boolean isSystemAdmin(@NonNull final AccountID accountID) {
145145
return accountID.accountNumOrThrow() == accountsConfig.systemAdmin();
146146
}
147147

148+
private boolean hasSoftwareUpdatePrivilege(@NonNull final AccountID accountID) {
149+
return accountID.accountNumOrThrow() == accountsConfig.softwareUpdateAdmin() || isSuperUser(accountID);
150+
}
151+
148152
private boolean hasFreezePrivilege(@NonNull final AccountID accountID) {
149153
return accountID.accountNumOrThrow() == accountsConfig.freezeAdmin() || isSuperUser(accountID);
150154
}
@@ -215,7 +219,7 @@ private SystemPrivilege checkFileChange(@NonNull final AccountID accountID, fina
215219
return hasExchangeRatePrivilige(accountID) ? AUTHORIZED : UNAUTHORIZED;
216220
} else if (filesConfig.softwareUpdateRange().left() <= entityNum
217221
&& entityNum <= filesConfig.softwareUpdateRange().right()) {
218-
return hasFreezePrivilege(accountID) ? AUTHORIZED : UNAUTHORIZED;
222+
return hasSoftwareUpdatePrivilege(accountID) ? AUTHORIZED : UNAUTHORIZED;
219223
} else if (entityNum == filesConfig.throttleDefinitions()) {
220224
return hasAddressBookPrivilege(accountID) || hasExchangeRatePrivilige(accountID)
221225
? AUTHORIZED

hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleHederaState.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.swirlds.common.merkle.impl.PartialNaryMerkleInternal;
5252
import com.swirlds.common.utility.Labeled;
5353
import com.swirlds.merkle.map.MerkleMap;
54+
import com.swirlds.metrics.api.Metrics;
5455
import com.swirlds.platform.state.PlatformState;
5556
import com.swirlds.platform.system.InitTrigger;
5657
import com.swirlds.platform.system.Platform;
@@ -64,7 +65,11 @@
6465
import com.swirlds.virtualmap.VirtualMap;
6566
import edu.umd.cs.findbugs.annotations.NonNull;
6667
import java.io.IOException;
67-
import java.util.*;
68+
import java.util.Collections;
69+
import java.util.HashMap;
70+
import java.util.Map;
71+
import java.util.Objects;
72+
import java.util.Set;
6873
import java.util.concurrent.ConcurrentHashMap;
6974
import java.util.function.Supplier;
7075
import org.apache.logging.log4j.LogManager;
@@ -132,6 +137,8 @@ public class MerkleHederaState extends PartialNaryMerkleInternal implements Merk
132137
return services;
133138
}
134139

140+
private Metrics metrics;
141+
135142
/**
136143
* Maintains information about each service, and each state of each service, known by this
137144
* instance. The key is the "service-name.state-key".
@@ -185,6 +192,8 @@ public void init(
185192
final PlatformState platformState,
186193
final InitTrigger trigger,
187194
final SoftwareVersion deserializedVersion) {
195+
metrics = platform.getContext().getMetrics();
196+
188197
// If we are initialized for event stream recovery, we have to register an
189198
// extra listener to make sure we call all the required Hedera lifecycles
190199
if (trigger == EVENT_STREAM_RECOVERY) {
@@ -677,6 +686,9 @@ public void copyAndReleaseVirtualMap(@NonNull final String stateKey) {
677686
final var md = stateMetadata.get(stateKey);
678687
final VirtualMap<?, ?> virtualMap = (VirtualMap<?, ?>) findNode(md);
679688
final var mutableCopy = virtualMap.copy();
689+
if (metrics != null) {
690+
mutableCopy.registerMetrics(metrics);
691+
}
680692
setChild(findNodeIndex(serviceName, stateKey), mutableCopy);
681693
kvInstances.put(stateKey, createReadableKVState(md, mutableCopy));
682694
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.swirlds.merkle.map.MerkleMap;
5252
import com.swirlds.merkledb.MerkleDbDataSourceBuilder;
5353
import com.swirlds.merkledb.MerkleDbTableConfig;
54+
import com.swirlds.metrics.api.Metrics;
5455
import com.swirlds.virtualmap.VirtualMap;
5556
import edu.umd.cs.findbugs.annotations.NonNull;
5657
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -161,11 +162,13 @@ public void migrate(
161162
@NonNull final SemanticVersion currentVersion,
162163
@NonNull final Configuration config,
163164
@NonNull final NetworkInfo networkInfo,
165+
@NonNull final Metrics metrics,
164166
@Nullable final WritableEntityIdStore entityIdStore) {
165167
requireNonNull(hederaState);
166168
requireNonNull(currentVersion);
167169
requireNonNull(config);
168170
requireNonNull(networkInfo);
171+
requireNonNull(metrics);
169172

170173
// Figure out which schemas need to be applied based on the previous and current versions, and then for each
171174
// of those schemas, create the new states and remove the old states and migrate the data.
@@ -230,7 +233,9 @@ public void migrate(
230233
.maxNumberOfKeys(def.maxKeysHint());
231234
final var label = StateUtils.computeLabel(serviceName, stateKey);
232235
final var dsBuilder = new MerkleDbDataSourceBuilder<>(tableConfig);
233-
return new VirtualMap<>(label, dsBuilder);
236+
final var virtualMap = new VirtualMap<>(label, dsBuilder);
237+
virtualMap.registerMetrics(metrics);
238+
return virtualMap;
234239
});
235240
}
236241
});

0 commit comments

Comments
 (0)