From a8d6e2c9cab4ca6c5aeae8f3f909c3d7e0283ddf Mon Sep 17 00:00:00 2001 From: Neeharika Sompalli <52669918+Neeharika-Sompalli@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:21:31 -0500 Subject: [PATCH] fix: Fix to deterministic iteration order (#12401) Signed-off-by: Neeharika-Sompalli --- .../impl/schemas/InitialModServiceConsensusSchema.java | 4 ++-- .../token/impl/schemas/InitialModServiceTokenSchema.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hedera-node/hedera-consensus-service-impl/src/main/java/com/hedera/node/app/service/consensus/impl/schemas/InitialModServiceConsensusSchema.java b/hedera-node/hedera-consensus-service-impl/src/main/java/com/hedera/node/app/service/consensus/impl/schemas/InitialModServiceConsensusSchema.java index b014ce203664..be4503c83614 100644 --- a/hedera-node/hedera-consensus-service-impl/src/main/java/com/hedera/node/app/service/consensus/impl/schemas/InitialModServiceConsensusSchema.java +++ b/hedera-node/hedera-consensus-service-impl/src/main/java/com/hedera/node/app/service/consensus/impl/schemas/InitialModServiceConsensusSchema.java @@ -22,6 +22,7 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.hapi.node.base.TopicID; import com.hedera.hapi.node.state.consensus.Topic; +import com.hedera.node.app.service.mono.state.adapters.MerkleMapLike; import com.hedera.node.app.service.mono.state.merkle.MerkleTopic; import com.hedera.node.app.service.mono.utils.EntityNum; import com.hedera.node.app.spi.state.MigrationContext; @@ -70,8 +71,7 @@ public void migrate(@NonNull final MigrationContext ctx) { final var numTopicInsertions = new AtomicLong(); final var topicStoreRef = new AtomicReference<>(ctx.newStates().get(TOPICS_KEY)); log.info("BBM: running consensus migration..."); - - fs.forEach((k, v) -> { + MerkleMapLike.from(fs).forEachNode((k, v) -> { final var pbjTopic = stateToPbj(v); topicStoreRef.get().put(pbjTopic.topicId(), pbjTopic); if (numTopicInsertions.incrementAndGet() % 10_000 == 0) { diff --git a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/InitialModServiceTokenSchema.java b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/InitialModServiceTokenSchema.java index 62d6b8b4385d..90361e72177a 100644 --- a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/InitialModServiceTokenSchema.java +++ b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/schemas/InitialModServiceTokenSchema.java @@ -299,7 +299,7 @@ public void migrate(@NonNull final MigrationContext ctx) { // ---------- Staking Info log.info("BBM: starting staking info"); var stakingToState = ctx.newStates().get(STAKING_INFO_KEY); - stakingFs.forEach((entityNum, merkleStakingInfo) -> { + MerkleMapLike.from(stakingFs).forEachNode((entityNum, merkleStakingInfo) -> { var toStakingInfo = StakingNodeInfoStateTranslator.stakingInfoFromMerkleStakingInfo(merkleStakingInfo); stakingToState.put( EntityNumber.newBuilder() @@ -381,7 +381,7 @@ public void migrate(@NonNull final MigrationContext ctx) { } if (acctsToState.get().isModified()) ((WritableKVStateBase) acctsToState.get()).commit(); // Also persist the per-node pending reward information - stakingFs.forEach((entityNum, ignore) -> { + MerkleMapLike.from(stakingFs).forEachNode((entityNum, ignore) -> { final var toKey = new EntityNumber(entityNum.longValue()); final var info = requireNonNull(stakingToState.get(toKey)); stakingToState.put(