Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: app and services to stop querying the platform for the roster #16771

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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.ThrottleDefinitions;
import com.hedera.hapi.node.transaction.TransactionBody;
import com.hedera.hapi.platform.state.PlatformState;
Expand Down Expand Up @@ -113,6 +114,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;
Expand All @@ -133,6 +135,7 @@
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;
Expand Down Expand Up @@ -351,6 +354,8 @@
@Nullable
private StartupNetworks startupNetworks;

private RosterHistory rosterHistory;

@FunctionalInterface
public interface TssBaseServiceFactory {
@NonNull
Expand Down Expand Up @@ -600,7 +605,7 @@
state,
metrics,
trigger,
RosterUtils.buildAddressBook(platform.getRoster()),
RosterUtils.buildAddressBook(this.rosterHistory.getCurrentRoster()),

Check warning on line 608 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#L608

Added line #L608 was not covered by tests
platform.getContext().getConfiguration());
}
// With the States API grounded in the working state, we can create the object graph from it
Expand All @@ -619,7 +624,7 @@
* @param state current state
* @param deserializedVersion version deserialized
* @param trigger trigger that is calling migration
* @param genesisAddressBook the genesis address book, if applicable
* @param genesisAddressBook the genesis address book, if applicable
* @param platformConfiguration platform configuration
*/
private void migrateSchemas(
Expand Down Expand Up @@ -911,6 +916,15 @@
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;
}

Check warning on line 926 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#L925-L926

Added lines #L925 - L926 were not covered by tests

/*==================================================================================================================
*
* Exposed for use by embedded Hedera
Expand Down Expand Up @@ -1001,8 +1015,14 @@
.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);

Check warning on line 1024 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#L1024

Added line #L1024 was not covered by tests
}
final var networkInfo =
new StateNetworkInfo(state, activeRoster, platform.getSelfId().id(), configProvider);
// Fully qualified so as to not confuse javadoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
.withConfiguration(configuration)
.withKeysAndCerts(keysAndCerts);

hedera.setRosterHistory(rosterHistory);

Check warning on line 316 in hedera-node/hedera-app/src/main/java/com/hedera/node/app/ServicesMain.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L316 was not covered by tests
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -55,12 +54,6 @@ static Supplier<Charset> provideNativeCharset() {
return Charset::defaultCharset;
}

@Provides
@Singleton
static IntSupplier provideFrontendThrottleSplit(@NonNull final Platform platform) {
return () -> platform.getRoster().rosterEntries().size();
}

@Binds
@Singleton
ReconnectCompleteListener bindReconnectListener(ReconnectListener reconnectListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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;
Expand Down Expand Up @@ -60,10 +61,12 @@ static ThrottleAccumulator provideBackendThrottleAccumulator(
@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::getConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public TransactionExecutor newExecutor(
final var tracerBinding =
customTracerBinding != null ? customTracerBinding : DefaultTracerBinding.DEFAULT_TRACER_BINDING;
final var executor = newExecutorComponent(state, 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<NodeInfo> nodeInfosOrThrow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down