Skip to content

Commit

Permalink
Merge branch 'develop' into 15315-remove-all-usages-of-configurationh…
Browse files Browse the repository at this point in the history
…older-in-the-state

# Conflicts:
#	platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java
  • Loading branch information
thenswan committed Sep 20, 2024
2 parents 30dddb1 + aa75ff7 commit a7d0685
Show file tree
Hide file tree
Showing 44 changed files with 254 additions and 318 deletions.
4 changes: 2 additions & 2 deletions hedera-dependency-versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ dependencies.constraints {
api("com.google.jimfs:jimfs:1.2") {
because("com.google.jimfs")
}
api("com.google.protobuf:protobuf-java:3.25.4") {
api("com.google.protobuf:protobuf-java:4.28.2") {
because("com.google.protobuf")
}
api("com.google.protobuf:protobuf-java-util:3.25.4") {
api("com.google.protobuf:protobuf-java-util:4.28.2") {
because("com.google.protobuf.util")
}
api("com.hedera.pbj:pbj-runtime:0.9.2") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.swirlds.common.merkle.impl.PartialMerkleLeaf;
import com.swirlds.common.platform.NodeId;
import com.swirlds.platform.SwirldsPlatform;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -200,7 +200,7 @@ public synchronized CryptocurrencyDemoState copy() {
}

@Override
public void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
round.forEachEventTransaction((event, transaction) -> handleTransaction(event.getCreatorId(), transaction));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.swirlds.common.io.streams.SerializableDataOutputStream;
import com.swirlds.common.merkle.MerkleLeaf;
import com.swirlds.common.merkle.impl.PartialMerkleLeaf;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.SwirldState;
import com.swirlds.platform.system.transaction.Transaction;
Expand Down Expand Up @@ -99,7 +99,7 @@ private HelloSwirldDemoState(final HelloSwirldDemoState sourceState) {
}

@Override
public synchronized void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public synchronized void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
round.forEachTransaction(this::handleTransaction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.swirlds.common.io.streams.SerializableDataOutputStream;
import com.swirlds.common.merkle.MerkleLeaf;
import com.swirlds.common.merkle.impl.PartialMerkleLeaf;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.SwirldState;

Expand Down Expand Up @@ -69,7 +69,7 @@ private StatsDemoState(final StatsDemoState sourceState) {
}

@Override
public void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {}
public void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.swirlds.common.utility.StackTrace;
import com.swirlds.platform.config.AddressBookConfig;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -182,7 +183,7 @@ public void init(
* {@inheritDoc}
*/
@Override
public void handleConsensusRound(@NonNull final Round round, @NonNull final PlatformStateAccessor platformState) {
public void handleConsensusRound(@NonNull final Round round, @NonNull final PlatformStateModifier platformState) {
Objects.requireNonNull(round, "the round cannot be null");
Objects.requireNonNull(platformState, "the platform state cannot be null");
throwIfImmutable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.swirlds.common.merkle.impl.PartialMerkleLeaf;
import com.swirlds.common.utility.NonCryptographicHashing;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -249,7 +250,7 @@ public void preHandle(@NonNull final Event event) {
* Writes the round and its contents to a log on disk
*/
@Override
public void handleConsensusRound(final @NonNull Round round, final @NonNull PlatformStateAccessor platformState) {
public void handleConsensusRound(final @NonNull Round round, final @NonNull PlatformStateModifier platformState) {
Objects.requireNonNull(round);
Objects.requireNonNull(platformState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.swirlds.common.platform.NodeId;
import com.swirlds.common.utility.ByteUtils;
import com.swirlds.platform.scratchpad.Scratchpad;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -172,7 +172,7 @@ public void init(
* {@inheritDoc}
*/
@Override
public void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
final Iterator<ConsensusEvent> eventIterator = round.iterator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.swirlds.merkledb.MerkleDbDataSourceBuilder;
import com.swirlds.merkledb.MerkleDbTableConfig;
import com.swirlds.merkledb.config.MerkleDbConfig;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -251,7 +251,7 @@ public void init(
* {@inheritDoc}
*/
@Override
public void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
for (final Iterator<ConsensusEvent> eventIt = round.iterator(); eventIt.hasNext(); ) {
final ConsensusEvent event = eventIt.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import com.swirlds.merkle.test.fixtures.map.pta.MapKey;
import com.swirlds.platform.ParameterProvider;
import com.swirlds.platform.Utilities;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ private void handleControlTransaction(
* Handle the freeze transaction type.
*/
private void handleFreezeTransaction(
final TestTransaction testTransaction, final PlatformStateAccessor platformState) {
final TestTransaction testTransaction, final PlatformStateModifier platformState) {
final FreezeTransaction freezeTx = testTransaction.getFreezeTransaction();
FreezeTransactionHandler.freeze(freezeTx, platformState);
}
Expand All @@ -1093,7 +1093,7 @@ protected void preHandleTransaction(final Transaction transaction) {
}

@Override
public synchronized void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public synchronized void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
if (!initialized.get()) {
throw new IllegalStateException("handleConsensusRound() called before init()");
Expand Down Expand Up @@ -1125,7 +1125,7 @@ private void updateTransactionCounters() {
private void handleConsensusTransaction(
final ConsensusEvent event,
final ConsensusTransaction trans,
final PlatformStateAccessor platformState,
final PlatformStateModifier platformState,
final long roundNum) {
if (trans.isSystem()) {
return;
Expand Down Expand Up @@ -1164,7 +1164,7 @@ private void handleTransaction(
@NonNull final Instant timeCreated,
@NonNull final Instant timestamp,
@NonNull final ConsensusTransaction trans,
@NonNull final PlatformStateAccessor platformState) {
@NonNull final PlatformStateModifier platformState) {
if (getConfig().isAppendSig()) {
try {
final TestTransactionWrapper testTransactionWrapper = TestTransactionWrapper.parseFrom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.swirlds.demo.platform.freeze;

import com.swirlds.demo.platform.fs.stresstest.proto.FreezeTransaction;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import java.time.Instant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -28,7 +28,7 @@ public class FreezeTransactionHandler {
private static final Logger logger = LogManager.getLogger(FreezeTransactionHandler.class);
private static final Marker LOGM_FREEZE = MarkerManager.getMarker("FREEZE");

public static boolean freeze(final FreezeTransaction transaction, final PlatformStateAccessor platformState) {
public static boolean freeze(final FreezeTransaction transaction, final PlatformStateModifier platformState) {
logger.debug(LOGM_FREEZE, "Handling FreezeTransaction: " + transaction);
try {
platformState.setFreezeTime(Instant.ofEpochSecond(transaction.getStartTimeEpochSecond()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.swirlds.common.io.streams.SerializableDataOutputStream;
import com.swirlds.common.merkle.MerkleLeaf;
import com.swirlds.common.merkle.impl.PartialMerkleLeaf;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.SwirldState;
import com.swirlds.platform.system.events.Event;
Expand Down Expand Up @@ -129,7 +129,7 @@ public void preHandle(final Event event) {
* {@inheritDoc}
*/
@Override
public void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
round.forEachTransaction(this::handleTransaction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.swirlds.common.merkle.MerkleLeaf;
import com.swirlds.common.merkle.impl.PartialMerkleLeaf;
import com.swirlds.common.utility.ByteUtils;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.Round;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void preHandle(final Event event) {
* {@inheritDoc}
*/
@Override
public void handleConsensusRound(final Round round, final PlatformStateAccessor platformState) {
public void handleConsensusRound(final Round round, final PlatformStateModifier platformState) {
throwIfImmutable();
round.forEachTransaction(this::handleTransaction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.swirlds.platform.config.DefaultConfiguration;
import com.swirlds.platform.consensus.SyntheticSnapshot;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.state.signed.ReservedSignedState;
import com.swirlds.platform.state.snapshot.DeserializedSignedState;
import com.swirlds.platform.state.snapshot.SignedStateFileReader;
Expand Down Expand Up @@ -75,7 +76,7 @@ public Integer call() throws IOException, ExecutionException, InterruptedExcepti
final DeserializedSignedState deserializedSignedState =
SignedStateFileReader.readStateFile(platformContext, statePath, SignedStateFileUtils::readState);
try (final ReservedSignedState reservedSignedState = deserializedSignedState.reservedSignedState()) {
final PlatformStateAccessor platformState =
final PlatformStateModifier platformState =
reservedSignedState.get().getState().getWritablePlatformState();
platformState.bulkUpdate(v -> {
System.out.printf("Replacing platform data %n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.swirlds.platform.internal.ConsensusRound;
import com.swirlds.platform.metrics.RoundHandlingMetrics;
import com.swirlds.platform.state.MerkleRoot;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.state.SwirldStateManager;
import com.swirlds.platform.state.signed.ReservedSignedState;
import com.swirlds.platform.state.signed.SignedState;
Expand Down Expand Up @@ -215,12 +215,12 @@ public StateAndRound handleConsensusRound(@NonNull final ConsensusRound consensu
}

/**
* Populate the {@link PlatformStateAccessor} with all needed data for this round.
* Populate the {@link PlatformStateModifier} with all needed data for this round.
*
* @param round the consensus round
*/
private void updatePlatformState(@NonNull final ConsensusRound round) {
final PlatformStateAccessor platformState =
final PlatformStateModifier platformState =
swirldStateManager.getConsensusState().getWritablePlatformState();
platformState.bulkUpdate(v -> {
v.setRound(round.getRoundNum());
Expand All @@ -238,7 +238,7 @@ private void updatePlatformState(@NonNull final ConsensusRound round) {
* @throws InterruptedException if this thread is interrupted
*/
private void updateRunningEventHash(@NonNull final ConsensusRound round) throws InterruptedException {
final PlatformStateAccessor platformState =
final PlatformStateModifier platformState =
swirldStateManager.getConsensusState().getWritablePlatformState();

if (writeLegacyRunningEventHash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.swirlds.platform.recovery.internal.StreamedRound;
import com.swirlds.platform.state.MerkleRoot;
import com.swirlds.platform.state.PlatformStateAccessor;
import com.swirlds.platform.state.PlatformStateModifier;
import com.swirlds.platform.state.signed.ReservedSignedState;
import com.swirlds.platform.state.signed.SignedState;
import com.swirlds.platform.state.snapshot.SignedStateFileReader;
Expand Down Expand Up @@ -380,7 +381,7 @@ private static ReservedSignedState handleNextRound(
new DefaultEventHasher().hashEvent(lastEvent);

final PlatformStateAccessor newReadablePlatformState = newState.getReadablePlatformState();
final PlatformStateAccessor newWritablePlatformState = newState.getWritablePlatformState();
final PlatformStateModifier newWritablePlatformState = newState.getWritablePlatformState();
final PlatformStateAccessor previousReadablePlatformState =
previousState.get().getState().getReadablePlatformState();

Expand Down Expand Up @@ -478,7 +479,7 @@ static ConsensusEvent getLastEvent(final Round round) {
static void applyTransactions(
final SwirldState immutableState,
final SwirldState mutableState,
final PlatformStateAccessor platformState,
final PlatformStateModifier platformState,
final Round round) {

mutableState.throwIfImmutable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void modifyStateForBirthRoundMigration(
}

final MerkleRoot state = initialState.getState();
final PlatformStateAccessor writablePlatformState = state.getWritablePlatformState();
final PlatformStateModifier writablePlatformState = state.getWritablePlatformState();

final boolean alreadyMigrated = writablePlatformState.getFirstVersionInBirthRoundMode() != null;
if (alreadyMigrated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private GenesisStateBuilder() {}
*/
public static void initGenesisPlatformState(
final PlatformContext platformContext,
final PlatformStateAccessor platformState,
final PlatformStateModifier platformState,
final AddressBook addressBook,
final SoftwareVersion appVersion) {
platformState.bulkUpdate(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public interface MerkleRoot extends MerkleInternal {
@NonNull
SwirldState getSwirldState();

/**
* This method makes sure that the platform state is initialized.
* If it's already initialized, it does nothing.
*/
void initPlatformState();

/**
* Get readable platform state.
* Works on both - mutable and immutable {@link MerkleRoot} and, therefore, this method should be preferred.
Expand All @@ -48,14 +54,14 @@ public interface MerkleRoot extends MerkleInternal {
* @return mutable platform state
*/
@NonNull
PlatformStateAccessor getWritablePlatformState();
PlatformStateModifier getWritablePlatformState();

/**
* Set the platform state.
*
* @param platformState the platform state
*/
void updatePlatformState(@NonNull final PlatformStateAccessor platformState);
void updatePlatformState(@NonNull final PlatformStateModifier platformState);

/**
* Generate a string that describes this state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public interface MerkleStateLifecycles {
/**
* Called when a {@link MerkleStateRoot} needs to ensure its {@link PlatformStateAccessor} implementation
* Called when a {@link MerkleStateRoot} needs to ensure its {@link PlatformStateModifier} implementation
* is initialized.
*
* @param state the root of the state to be initialized
Expand Down
Loading

0 comments on commit a7d0685

Please sign in to comment.