Skip to content

Commit

Permalink
fix: Fix to deterministic iteration order (#12401)
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
  • Loading branch information
Neeharika-Sompalli authored and imalygin committed Apr 17, 2024
1 parent 2fae105 commit ddb358a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,8 +71,7 @@ public void migrate(@NonNull final MigrationContext ctx) {
final var numTopicInsertions = new AtomicLong();
final var topicStoreRef = new AtomicReference<>(ctx.newStates().<TopicID, Topic>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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void migrate(@NonNull final MigrationContext ctx) {
// ---------- Staking Info
log.info("BBM: starting staking info");
var stakingToState = ctx.newStates().<EntityNumber, StakingNodeInfo>get(STAKING_INFO_KEY);
stakingFs.forEach((entityNum, merkleStakingInfo) -> {
MerkleMapLike.from(stakingFs).forEachNode((entityNum, merkleStakingInfo) -> {
var toStakingInfo = StakingNodeInfoStateTranslator.stakingInfoFromMerkleStakingInfo(merkleStakingInfo);
stakingToState.put(
EntityNumber.newBuilder()
Expand Down Expand Up @@ -385,7 +385,7 @@ public void migrate(@NonNull final MigrationContext ctx) {
if (acctsToState.get().isModified()) ((WritableKVStateBase) acctsToState.get()).commit();
if (aliasesState.get().isModified()) ((WritableKVStateBase) aliasesState.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(
Expand Down

0 comments on commit ddb358a

Please sign in to comment.