Skip to content

Commit

Permalink
Sync with develop
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Ananev <[email protected]>
  • Loading branch information
artemananiev committed Sep 13, 2024
2 parents 8510ead + f51f651 commit dd52d40
Show file tree
Hide file tree
Showing 216 changed files with 7,170 additions and 1,718 deletions.
2 changes: 1 addition & 1 deletion hapi/hedera-protobufs/services/state/roster/roster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message Roster {
* This list SHALL contain roster entries in natural order of ascending node ids.
* This list SHALL NOT be empty.<br/>
*/
repeated RosterEntry rosters = 1;
repeated RosterEntry roster_entries = 1;
}

/**
Expand Down
1 change: 1 addition & 0 deletions hedera-node/configuration/dev/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ balances.exportDir.path=data/accountBalances/
upgrade.artifacts.path=data/upgrade
contracts.chainId=298
contracts.maxGasPerSec=15000000000
contracts.systemContract.tokenInfo.v2.enabled=true
# Needed for end-end tests running on mod-service code
staking.periodMins=1
staking.fees.nodeRewardPercentage=10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private ParsingConstants() {
"(" + "string,string,address,string,bool,int64,bool," + TOKEN_KEY + ARRAY_BRACKETS + "," + EXPIRY + ")";
public static final String HEDERA_TOKEN_V3 =
"(" + "string,string,address,string,bool,int64,bool," + TOKEN_KEY + ARRAY_BRACKETS + "," + EXPIRY_V2 + ")";
public static final String HEDERA_TOKEN_V4 = "(" + "string,string,address,string,bool,uint32,bool," + TOKEN_KEY
+ ARRAY_BRACKETS + "," + EXPIRY + ",bytes" + ")";
public static final String TOKEN_INFO = "("
+ HEDERA_TOKEN_V2
+ ",int64,bool,bool,bool,"
Expand Down Expand Up @@ -135,8 +137,11 @@ public enum FunctionType {
HAPI_TRANSFER_FROM_NFT,
HAPI_GET_APPROVED,
HAPI_GET_FUNGIBLE_TOKEN_INFO,
HAPI_GET_FUNGIBLE_TOKEN_INFO_V2,
HAPI_GET_TOKEN_INFO,
HAPI_GET_TOKEN_INFO_V2,
HAPI_GET_NON_FUNGIBLE_TOKEN_INFO,
HAPI_GET_NON_FUNGIBLE_TOKEN_INFO_V2,
HAPI_IS_APPROVED_FOR_ALL,
HAPI_IS_KYC,
GET_TOKEN_DEFAULT_FREEZE_STATUS,
Expand Down
5 changes: 4 additions & 1 deletion hedera-node/hedera-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ val cleanRun =

tasks.clean { dependsOn(cleanRun) }

tasks.register("showHapiVersion") { doLast { println(libs.versions.hapi.proto.get()) } }
tasks.register("showHapiVersion") {
inputs.property("version", project.version)
doLast { println(inputs.properties["version"]) }
}

var updateDockerEnvTask =
tasks.register<Exec>("updateDockerEnv") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.node.app;

import static com.hedera.node.app.blocks.BlockStreamService.FAKE_RESTART_BLOCK_HASH;
import static com.hedera.node.app.info.UnavailableNetworkInfo.UNAVAILABLE_NETWORK_INFO;
import static com.hedera.node.app.records.schemas.V0490BlockRecordSchema.BLOCK_INFO_STATE_KEY;
import static com.hedera.node.app.state.merkle.VersionUtils.isSoOrdered;
Expand All @@ -36,6 +37,7 @@
import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.hapi.node.state.blockrecords.BlockInfo;
import com.hedera.hapi.util.HapiUtils;
import com.hedera.node.app.blocks.BlockStreamManager;
import com.hedera.node.app.blocks.BlockStreamService;
import com.hedera.node.app.blocks.impl.BoundaryStateChangeListener;
import com.hedera.node.app.blocks.impl.KVStateChangeListener;
Expand Down Expand Up @@ -69,6 +71,8 @@
import com.hedera.node.app.statedumpers.MerkleStateChild;
import com.hedera.node.app.store.ReadableStoreFactory;
import com.hedera.node.app.throttle.CongestionThrottleService;
import com.hedera.node.app.tss.TssBaseService;
import com.hedera.node.app.tss.impl.PlaceholderTssBaseService;
import com.hedera.node.app.version.HederaSoftwareVersion;
import com.hedera.node.app.version.ServicesSoftwareVersion;
import com.hedera.node.app.workflows.handle.HandleWorkflow;
Expand Down Expand Up @@ -190,6 +194,11 @@ public final class Hedera implements SwirldMain, PlatformStatusChangeListener {
*/
private final InstantSource instantSource;

/**
* The supplier for the TSS base service.
*/
private final Supplier<TssBaseService> tssBaseServiceSupplier;

/**
* The contract service singleton, kept as a field here to avoid constructing twice
* (once in constructor to register schemas, again inside Dagger component).
Expand All @@ -202,6 +211,12 @@ public final class Hedera implements SwirldMain, PlatformStatusChangeListener {
*/
private final FileServiceImpl fileServiceImpl;

/**
* The block stream service singleton, kept as a field here to reuse information learned
* during the state migration phase in the later initialization phase.
*/
private final BlockStreamService blockStreamService;

/**
* The bootstrap configuration provider for the network.
*/
Expand Down Expand Up @@ -268,14 +283,17 @@ public final class Hedera implements SwirldMain, PlatformStatusChangeListener {
* @param constructableRegistry the registry to register {@link RuntimeConstructable} factories with
* @param registryFactory the factory to use for creating the services registry
* @param migrator the migrator to use with the services
* @param tssBaseServiceSupplier the supplier for the TSS base service
*/
public Hedera(
@NonNull final ConstructableRegistry constructableRegistry,
@NonNull final ServicesRegistry.Factory registryFactory,
@NonNull final ServiceMigrator migrator,
@NonNull final InstantSource instantSource) {
@NonNull final InstantSource instantSource,
@NonNull final Supplier<TssBaseService> tssBaseServiceSupplier) {
requireNonNull(registryFactory);
requireNonNull(constructableRegistry);
this.tssBaseServiceSupplier = requireNonNull(tssBaseServiceSupplier);
this.serviceMigrator = requireNonNull(migrator);
this.instantSource = requireNonNull(instantSource);
logger.info(
Expand Down Expand Up @@ -306,6 +324,7 @@ public Hedera(
new SignatureExpanderImpl(),
new SignatureVerifierImpl(CryptographyHolder.get())));
contractServiceImpl = new ContractServiceImpl(appContext);
blockStreamService = new BlockStreamService(bootstrapConfig);
// Register all service schema RuntimeConstructable factories before platform init
Set.of(
new EntityIdService(),
Expand All @@ -318,7 +337,7 @@ public Hedera(
new UtilServiceImpl(),
new RecordCacheService(),
new BlockRecordService(),
new BlockStreamService(bootstrapConfig),
blockStreamService,
new FeeService(),
new CongestionThrottleService(),
new NetworkServiceImpl(),
Expand Down Expand Up @@ -775,6 +794,7 @@ private void initializeDagger(
@NonNull final InitTrigger trigger,
@NonNull final List<StateChanges.Builder> migrationStateChanges) {
final var notifications = platform.getNotificationEngine();
final var blockStreamEnabled = isBlockStreamEnabled();
// The Dagger component should be constructed every time we reach this point, even if
// it exists (this avoids any problems with mutable singleton state by reconstructing
// everything); but we must ensure the gRPC server in the old component is fully stopped,
Expand All @@ -784,6 +804,9 @@ private void initializeDagger(
notifications.unregister(PlatformStatusChangeListener.class, this);
notifications.unregister(ReconnectCompleteListener.class, daggerApp.reconnectListener());
notifications.unregister(StateWriteToDiskCompleteListener.class, daggerApp.stateWriteToDiskListener());
if (blockStreamEnabled) {
daggerApp.tssBaseService().unregisterLedgerSignatureConsumer(daggerApp.blockStreamManager());
}
}
// Fully qualified so as to not confuse javadoc
daggerApp = com.hedera.node.app.DaggerHederaInjectionComponent.builder()
Expand All @@ -804,12 +827,36 @@ private void initializeDagger(
.kvStateChangeListener(kvStateChangeListener)
.boundaryStateChangeListener(boundaryStateChangeListener)
.migrationStateChanges(migrationStateChanges)
.tssBaseService(tssBaseServiceSupplier.get())
.build();
// Initialize infrastructure for fees, exchange rates, and throttles from the working state
daggerApp.initializer().accept(state);
notifications.register(PlatformStatusChangeListener.class, this);
notifications.register(ReconnectCompleteListener.class, daggerApp.reconnectListener());
notifications.register(StateWriteToDiskCompleteListener.class, daggerApp.stateWriteToDiskListener());
if (blockStreamEnabled) {
daggerApp
.blockStreamManager()
.initLastBlockHash(
switch (trigger) {
case GENESIS -> BlockStreamManager.ZERO_BLOCK_HASH;
// FUTURE - get the actual last block hash from e.g. a reconnect teacher or disk
default -> blockStreamService
.migratedLastBlockHash()
.orElse(FAKE_RESTART_BLOCK_HASH);
});
daggerApp.tssBaseService().registerLedgerSignatureConsumer(daggerApp.blockStreamManager());
if (daggerApp.tssBaseService() instanceof PlaceholderTssBaseService placeholderTssBaseService) {
daggerApp.inject(placeholderTssBaseService);
}
}
}

private boolean isBlockStreamEnabled() {
return bootstrapConfigProvider
.getConfiguration()
.getConfigData(BlockStreamConfig.class)
.streamBlocks();
}

private static ServicesSoftwareVersion getNodeStartupVersion(@NonNull final Configuration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import com.hedera.node.app.state.WorkingStateAccessor;
import com.hedera.node.app.throttle.ThrottleServiceManager;
import com.hedera.node.app.throttle.ThrottleServiceModule;
import com.hedera.node.app.tss.TssBaseService;
import com.hedera.node.app.tss.impl.PlaceholderTssBaseService;
import com.hedera.node.app.workflows.FacilityInitModule;
import com.hedera.node.app.workflows.WorkflowsInjectionModule;
import com.hedera.node.app.workflows.handle.HandleWorkflow;
Expand Down Expand Up @@ -132,6 +134,10 @@ public interface HederaInjectionComponent {

StoreMetricsService storeMetricsService();

TssBaseService tssBaseService();

void inject(PlaceholderTssBaseService placeholderTssBaseService);

@Component.Builder
interface Builder {
@BindsInstance
Expand Down Expand Up @@ -185,6 +191,9 @@ interface Builder {
@BindsInstance
Builder migrationStateChanges(List<StateChanges.Builder> migrationStateChanges);

@BindsInstance
Builder tssBaseService(TssBaseService tssBaseService);

HederaInjectionComponent build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,45 @@

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;
import static com.swirlds.logging.legacy.LogMarker.EXCEPTION;
import static com.swirlds.platform.builder.PlatformBuildConstants.DEFAULT_CONFIG_FILE_NAME;
import static com.swirlds.platform.builder.PlatformBuildConstants.DEFAULT_SETTINGS_FILE_NAME;
import static com.swirlds.platform.builder.internal.StaticPlatformBuilder.getMetricsProvider;
import static com.swirlds.platform.builder.internal.StaticPlatformBuilder.setupGlobalMetrics;
import static com.swirlds.platform.config.internal.PlatformConfigUtils.checkConfiguration;
import static com.swirlds.platform.crypto.CryptoStatic.initNodeSecurity;
import static com.swirlds.platform.state.signed.StartupStateUtils.getInitialState;
import static com.swirlds.platform.system.SystemExitCode.CONFIGURATION_ERROR;
import static com.swirlds.platform.system.SystemExitCode.NODE_ADDRESS_MISMATCH;
import static com.swirlds.platform.system.SystemExitUtils.exitSystem;
import static com.swirlds.platform.system.address.AddressBookUtils.createRoster;
import static com.swirlds.platform.system.address.AddressBookUtils.initializeAddressBook;
import static com.swirlds.platform.util.BootstrapUtils.checkNodesToRun;
import static com.swirlds.platform.util.BootstrapUtils.getNodesToRun;
import static java.util.Objects.requireNonNull;

import com.hedera.node.app.services.OrderedServiceMigrator;
import com.hedera.node.app.services.ServicesRegistryImpl;
import com.hedera.node.app.tss.impl.PlaceholderTssBaseService;
import com.swirlds.base.time.Time;
import com.swirlds.common.constructable.ConstructableRegistry;
import com.swirlds.common.constructable.RuntimeConstructable;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.crypto.CryptographyFactory;
import com.swirlds.common.crypto.CryptographyHolder;
import com.swirlds.common.io.filesystem.FileSystemManager;
import com.swirlds.common.io.utility.FileUtils;
import com.swirlds.common.io.utility.RecycleBin;
import com.swirlds.common.merkle.crypto.MerkleCryptoFactory;
import com.swirlds.common.merkle.crypto.MerkleCryptographyFactory;
import com.swirlds.common.platform.NodeId;
import com.swirlds.config.api.Configuration;
import com.swirlds.config.api.ConfigurationBuilder;
import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource;
import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource;
import com.swirlds.platform.CommandLineArgs;
import com.swirlds.platform.ParameterProvider;
import com.swirlds.platform.builder.PlatformBuilder;
import com.swirlds.platform.config.legacy.ConfigurationException;
import com.swirlds.platform.config.legacy.LegacyConfigProperties;
Expand Down Expand Up @@ -154,7 +170,7 @@ public static void main(final String... args) throws Exception {

// Determine which node to run locally
// Load config.txt address book file and parse address book
final AddressBook addressBook = loadAddressBook(DEFAULT_CONFIG_FILE_NAME);
final AddressBook bootstrapAddressBook = loadAddressBook(DEFAULT_CONFIG_FILE_NAME);
// parse command line arguments
final CommandLineArgs commandLineArgs = CommandLineArgs.parse(args);

Expand All @@ -169,7 +185,7 @@ public static void main(final String... args) throws Exception {
// get the list of configured nodes from the address book
// for each node in the address book, check if it has a local IP (local to this computer)
// additionally if a command line arg is supplied then limit matching nodes to that node id
final List<NodeId> nodesToRun = getNodesToRun(addressBook, commandLineArgs.localNodesToStart());
final List<NodeId> nodesToRun = getNodesToRun(bootstrapAddressBook, commandLineArgs.localNodesToStart());
// hard exit if no nodes are configured to run
checkNodesToRun(nodesToRun);

Expand All @@ -178,19 +194,58 @@ public static void main(final String... args) throws Exception {
final SoftwareVersion version = hedera.getSoftwareVersion();
logger.info("Starting node {} with version {}", selfId, version);

final PlatformBuilder platformBuilder = PlatformBuilder.create(
Hedera.APP_NAME,
Hedera.SWIRLD_NAME,
final var configuration = buildConfiguration();
final var keysAndCerts =
initNodeSecurity(bootstrapAddressBook, configuration).get(selfId);

setupGlobalMetrics(configuration);
final var metrics = getMetricsProvider().createPlatformMetrics(selfId);
final var time = Time.getCurrent();
final var fileSystemManager = FileSystemManager.create(configuration);
final var recycleBin =
RecycleBin.create(metrics, configuration, getStaticThreadManager(), time, fileSystemManager, selfId);

final var cryptography = CryptographyFactory.create();
CryptographyHolder.set(cryptography);
// the AddressBook is not changed after this point, so we calculate the hash now
cryptography.digestSync(bootstrapAddressBook);

// Initialize the Merkle cryptography
final var merkleCryptography = MerkleCryptographyFactory.create(configuration, cryptography);
MerkleCryptoFactory.set(merkleCryptography);

// Create the platform context
final var platformContext = PlatformContext.create(
configuration,
Time.getCurrent(),
metrics,
cryptography,
FileSystemManager.create(configuration),
recycleBin,
merkleCryptography);
// Create initial state for the platform
final var initialState = getInitialState(
platformContext,
version,
hedera::newMerkleStateRoot,
SignedStateFileUtils::readState,
selfId);
Hedera.APP_NAME,
Hedera.SWIRLD_NAME,
selfId,
bootstrapAddressBook);

// Initialize the address book and set on platform builder
final var addressBook =
initializeAddressBook(selfId, version, initialState, bootstrapAddressBook, platformContext);

// Add additional configuration to the platform
final Configuration configuration = buildConfiguration();
platformBuilder.withConfiguration(configuration);
platformBuilder.withCryptography(CryptographyFactory.create());
platformBuilder.withTime(Time.getCurrent());
// Follow the Inversion of Control pattern by injecting all needed dependencies into the PlatformBuilder.
final var platformBuilder = PlatformBuilder.create(
Hedera.APP_NAME, Hedera.SWIRLD_NAME, version, initialState, selfId)
.withPlatformContext(platformContext)
.withConfiguration(configuration)
.withAddressBook(addressBook)
.withRoster(createRoster(addressBook))
.withKeysAndCerts(keysAndCerts);

// IMPORTANT: A surface-level reading of this method will undersell the centrality
// of the Hedera instance. It is actually omnipresent throughout both the startup
Expand Down Expand Up @@ -233,13 +288,15 @@ private static Configuration buildConfiguration() {
.withSource(SystemPropertiesConfigSource.getInstance());
rethrowIO(() ->
BootstrapUtils.setupConfigBuilder(configurationBuilder, getAbsolutePath(DEFAULT_SETTINGS_FILE_NAME)));
return configurationBuilder.build();
final Configuration configuration = configurationBuilder.build();
checkConfiguration(configuration);
return configuration;
}

/**
* Selects the node to run locally from either the command line arguments or the address book.
*
* @param nodesToRun the list of nodes configured to run based on the address book.
* @param nodesToRun the list of nodes configured to run based on the address book.
* @param localNodesToStart the node ids specified on the command line.
* @return the node which should be run locally.
* @throws ConfigurationException if more than one node would be started or the requested node is not configured.
Expand Down Expand Up @@ -288,6 +345,7 @@ private static AddressBook loadAddressBook(@NonNull final String addressBookPath
try {
final LegacyConfigProperties props =
LegacyConfigPropertiesLoader.loadConfigFile(FileUtils.getAbsolutePath(addressBookPath));
props.appConfig().ifPresent(c -> ParameterProvider.getInstance().setParameters(c.params()));
return props.getAddressBook();
} catch (final Exception e) {
logger.error(EXCEPTION.getMarker(), "Error loading address book", e);
Expand All @@ -301,6 +359,7 @@ private static Hedera newHedera() {
ConstructableRegistry.getInstance(),
ServicesRegistryImpl::new,
new OrderedServiceMigrator(),
InstantSource.system());
InstantSource.system(),
PlaceholderTssBaseService::new);
}
}
Loading

0 comments on commit dd52d40

Please sign in to comment.