Skip to content

Commit

Permalink
fix to deterministic iteration order
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
  • Loading branch information
Neeharika-Sompalli committed Mar 27, 2024
1 parent 6e57fd8 commit 7495457
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public void migrate(@NonNull final MigrationContext ctx) {
final var topicStoreRef = new AtomicReference<>(ctx.newStates().<TopicID, Topic>get(TOPICS_KEY));
log.info("BBM: running consensus migration...");

fs.forEach((k, v) -> {
final var pbjTopic = stateToPbj(v);
fs.keySet().stream().sorted().forEach(k -> {
final var topic = fs.get(k);
final var pbjTopic = stateToPbj(topic);
topicStoreRef.get().put(pbjTopic.topicId(), pbjTopic);
if (numTopicInsertions.incrementAndGet() % 10_000 == 0) {
// Make sure we are flushing data to disk as we go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ 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) -> {
stakingFs.keySet().stream().sorted().forEach(entityNum -> {
final var merkleStakingInfo = stakingFs.get(entityNum);
var toStakingInfo = StakingNodeInfoStateTranslator.stakingInfoFromMerkleStakingInfo(merkleStakingInfo);
stakingToState.put(
EntityNumber.newBuilder()
Expand Down Expand Up @@ -385,7 +386,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) -> {
stakingFs.keySet().stream().sorted().forEach(entityNum -> {
final var toKey = new EntityNumber(entityNum.longValue());
final var info = requireNonNull(stakingToState.get(toKey));
stakingToState.put(
Expand Down

0 comments on commit 7495457

Please sign in to comment.