Skip to content

Commit ec3fb55

Browse files
authored
chore: Cleanup legacy system account cleanup code (#21849)
Signed-off-by: Derek Riley <derek.riley@swirldslabs.com>
1 parent b233f68 commit ec3fb55

File tree

3 files changed

+0
-310
lines changed

3 files changed

+0
-310
lines changed

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/HandleWorkflow.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ public class HandleWorkflow {
162162
private final PlatformStateFacade platformStateFacade;
163163
// Flag to indicate whether we have checked for transplant updates after JVM started
164164
private boolean checkedForTransplant;
165-
// Flag whether the 0.65 system account cleanup has been done; can be removed after that release
166-
private boolean systemAccountCleanupDone;
167165

168166
@Inject
169167
public HandleWorkflow(
@@ -519,11 +517,6 @@ writableTokenStates, new WritableEntityIdStoreImpl(writableEntityIdStates)),
519517
// Only update this if we are relying on RecordManager state for post-upgrade processing
520518
blockRecordManager.markMigrationRecordsStreamed();
521519
}
522-
} else {
523-
if (!systemAccountCleanupDone) {
524-
// Ensure the system account cleanup is finished post-upgrade
525-
systemAccountCleanupDone = systemTransactions.do066SystemAccountCleanup(consensusNow, state);
526-
}
527520
}
528521

529522
final var topLevelTxn =

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/record/SystemTransactions.java

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS;
66
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS_BUT_MISSING_EXPECTED_OPERATION;
77
import static com.hedera.hapi.util.HapiUtils.asTimestamp;
8-
import static com.hedera.node.app.hapi.utils.EntityType.ACCOUNT;
98
import static com.hedera.node.app.hapi.utils.keys.KeyUtils.IMMUTABILITY_SENTINEL_KEY;
109
import static com.hedera.node.app.service.addressbook.impl.schemas.V053AddressBookSchema.parseEd25519NodeAdminKeysFrom;
1110
import static com.hedera.node.app.service.entityid.impl.schemas.V0490EntityIdSchema.ENTITY_ID_STATE_ID;
1211
import static com.hedera.node.app.service.entityid.impl.schemas.V0590EntityIdSchema.ENTITY_COUNTS_STATE_ID;
1312
import static com.hedera.node.app.service.file.impl.schemas.V0490FileSchema.dispatchSynthFileUpdate;
1413
import static com.hedera.node.app.service.file.impl.schemas.V0490FileSchema.parseConfigList;
15-
import static com.hedera.node.app.service.token.impl.schemas.V0490TokenSchema.ACCOUNTS_STATE_ID;
1614
import static com.hedera.node.app.service.token.impl.schemas.V0610TokenSchema.dispatchSynthNodeRewards;
1715
import static com.hedera.node.app.spi.workflows.HandleContext.TransactionCategory.NODE;
1816
import static com.hedera.node.app.util.FileUtilities.createFileID;
@@ -25,28 +23,21 @@
2523
import static java.util.Objects.requireNonNull;
2624
import static org.hiero.consensus.roster.RosterUtils.formatNodeName;
2725

28-
import com.hedera.hapi.block.stream.BlockItem;
29-
import com.hedera.hapi.block.stream.output.StateChange;
30-
import com.hedera.hapi.block.stream.output.StateChanges;
3126
import com.hedera.hapi.node.addressbook.NodeCreateTransactionBody;
3227
import com.hedera.hapi.node.addressbook.NodeDeleteTransactionBody;
3328
import com.hedera.hapi.node.addressbook.NodeUpdateTransactionBody;
34-
import com.hedera.hapi.node.base.AccountAmount;
3529
import com.hedera.hapi.node.base.AccountID;
3630
import com.hedera.hapi.node.base.CurrentAndNextFeeSchedule;
3731
import com.hedera.hapi.node.base.Duration;
3832
import com.hedera.hapi.node.base.Key;
3933
import com.hedera.hapi.node.base.ResponseCodeEnum;
4034
import com.hedera.hapi.node.base.ServiceEndpoint;
4135
import com.hedera.hapi.node.base.TransactionID;
42-
import com.hedera.hapi.node.base.TransferList;
4336
import com.hedera.hapi.node.state.common.EntityNumber;
4437
import com.hedera.hapi.node.state.entity.EntityCounts;
4538
import com.hedera.hapi.node.state.roster.RosterEntry;
46-
import com.hedera.hapi.node.state.token.Account;
4739
import com.hedera.hapi.node.state.token.StakingNodeInfo;
4840
import com.hedera.hapi.node.token.CryptoCreateTransactionBody;
49-
import com.hedera.hapi.node.token.CryptoTransferTransactionBody;
5041
import com.hedera.hapi.node.transaction.TransactionBody;
5142
import com.hedera.node.app.blocks.BlockStreamManager;
5243
import com.hedera.node.app.blocks.impl.ImmediateStateChangeListener;
@@ -94,7 +85,6 @@
9485
import com.swirlds.config.api.Configuration;
9586
import com.swirlds.platform.system.InitTrigger;
9687
import com.swirlds.state.State;
97-
import com.swirlds.state.spi.CommittableWritableStates;
9888
import com.swirlds.state.spi.WritableSingletonState;
9989
import edu.umd.cs.findbugs.annotations.NonNull;
10090
import java.io.IOException;
@@ -103,7 +93,6 @@
10393
import java.nio.file.Files;
10494
import java.nio.file.Paths;
10595
import java.time.Instant;
106-
import java.util.ArrayList;
10796
import java.util.Arrays;
10897
import java.util.EnumSet;
10998
import java.util.List;
@@ -409,84 +398,6 @@ ctx, createFileID(filesConfig.hapiPermissions(), config), bytes),
409398
autoNodeAdminKeyUpdates.tryIfPresent(adminConfig.upgradeSysFilesLoc(), systemContext);
410399
}
411400

412-
/**
413-
* Cleans up council-controlled system accounts that are no longer needed.
414-
* @param now the current time
415-
* @param state the state to clean up
416-
* @return true if the cleanup was finished, false otherwise
417-
*/
418-
public boolean do066SystemAccountCleanup(@NonNull final Instant now, @NonNull final State state) {
419-
requireNonNull(state);
420-
requireNonNull(now);
421-
final AtomicReference<AccountID> legacyAccountId = new AtomicReference<>();
422-
final Consumer<Consumer<List<StateChange>>> removeLegacyAccount = cb -> {
423-
if (streamMode != RECORDS) {
424-
immediateStateChangeListener.resetKvStateChanges(null);
425-
}
426-
// On success, actually remove the legacy account from state
427-
final var tokenStates = state.getWritableStates(TokenService.NAME);
428-
final var accountsState = tokenStates.<AccountID, Account>get(ACCOUNTS_STATE_ID);
429-
accountsState.remove(legacyAccountId.get());
430-
((CommittableWritableStates) tokenStates).commit();
431-
if (streamMode != RECORDS) {
432-
final var changes = immediateStateChangeListener.getKvStateChanges();
433-
if (!changes.isEmpty()) {
434-
cb.accept(changes);
435-
}
436-
}
437-
// And decrement the entity count for the account type
438-
final var entityStates = state.getWritableStates(EntityIdService.NAME);
439-
final var entityCounters = new WritableEntityIdStoreImpl(entityStates);
440-
entityCounters.adjustEntityCount(ACCOUNT, -1);
441-
((CommittableWritableStates) entityStates).commit();
442-
};
443-
// System context for dispatching CryptoTransfer with an onSuccess callback
444-
// that completely removes the legacy account from state after the dispatch
445-
// sweeping its dust HBAR into the fee collection account 0.0.98
446-
final var systemContext = newSystemContext(
447-
now,
448-
state,
449-
dispatch -> removeLegacyAccount.accept(
450-
changes -> dispatch.streamBuilder().stateChanges(changes)),
451-
UseReservedConsensusTimes.YES,
452-
TriggerStakePeriodSideEffects.YES);
453-
long i = FIRST_SYSTEM_FILE_ENTITY;
454-
final var feeCollectionId = idFactory.newAccountId(configProvider
455-
.getConfiguration()
456-
.getConfigData(LedgerConfig.class)
457-
.fundingAccount());
458-
final var accountsState = state.getReadableStates(TokenService.NAME).<AccountID, Account>get(ACCOUNTS_STATE_ID);
459-
for (; i < FIRST_POST_SYSTEM_FILE_ENTITY && systemContext.hasDispatchesRemaining(); i++) {
460-
final var accountId = idFactory.newAccountId(i);
461-
final var legacyAccount = accountsState.get(accountId);
462-
if (legacyAccount != null) {
463-
legacyAccountId.set(accountId);
464-
final long balance = legacyAccount.tinybarBalance();
465-
if (balance > 0) {
466-
log.info("Sweeping {} tinybars from {} @ {}", balance, accountId, systemContext.now());
467-
systemContext.dispatchAdmin(b -> b.cryptoTransfer(CryptoTransferTransactionBody.newBuilder()
468-
.transfers(TransferList.newBuilder()
469-
.accountAmounts(List.of(
470-
AccountAmount.newBuilder()
471-
.accountID(accountId)
472-
.amount(-balance)
473-
.build(),
474-
AccountAmount.newBuilder()
475-
.accountID(feeCollectionId)
476-
.amount(+balance)
477-
.build()))
478-
.build())));
479-
} else {
480-
log.info("Removing zero-balance legacy account {} @ {}", accountId, systemContext.now());
481-
removeLegacyAccount.accept(changes -> blockStreamManager.writeItem((t) -> BlockItem.newBuilder()
482-
.stateChanges(new StateChanges(t, new ArrayList<>(changes)))
483-
.build()));
484-
}
485-
}
486-
}
487-
return i == FIRST_POST_SYSTEM_FILE_ENTITY;
488-
}
489-
490401
/**
491402
* Dispatches a synthetic node reward crypto transfer for the given active node accounts.
492403
* If the {@link NodesConfig#minPerPeriodNodeRewardUsd()} is greater than zero, inactive nodes will receive the minimum node

0 commit comments

Comments
 (0)