|
5 | 5 | import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS; |
6 | 6 | import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS_BUT_MISSING_EXPECTED_OPERATION; |
7 | 7 | import static com.hedera.hapi.util.HapiUtils.asTimestamp; |
8 | | -import static com.hedera.node.app.hapi.utils.EntityType.ACCOUNT; |
9 | 8 | import static com.hedera.node.app.hapi.utils.keys.KeyUtils.IMMUTABILITY_SENTINEL_KEY; |
10 | 9 | import static com.hedera.node.app.service.addressbook.impl.schemas.V053AddressBookSchema.parseEd25519NodeAdminKeysFrom; |
11 | 10 | import static com.hedera.node.app.service.entityid.impl.schemas.V0490EntityIdSchema.ENTITY_ID_STATE_ID; |
12 | 11 | import static com.hedera.node.app.service.entityid.impl.schemas.V0590EntityIdSchema.ENTITY_COUNTS_STATE_ID; |
13 | 12 | import static com.hedera.node.app.service.file.impl.schemas.V0490FileSchema.dispatchSynthFileUpdate; |
14 | 13 | 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; |
16 | 14 | import static com.hedera.node.app.service.token.impl.schemas.V0610TokenSchema.dispatchSynthNodeRewards; |
17 | 15 | import static com.hedera.node.app.spi.workflows.HandleContext.TransactionCategory.NODE; |
18 | 16 | import static com.hedera.node.app.util.FileUtilities.createFileID; |
|
25 | 23 | import static java.util.Objects.requireNonNull; |
26 | 24 | import static org.hiero.consensus.roster.RosterUtils.formatNodeName; |
27 | 25 |
|
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; |
31 | 26 | import com.hedera.hapi.node.addressbook.NodeCreateTransactionBody; |
32 | 27 | import com.hedera.hapi.node.addressbook.NodeDeleteTransactionBody; |
33 | 28 | import com.hedera.hapi.node.addressbook.NodeUpdateTransactionBody; |
34 | | -import com.hedera.hapi.node.base.AccountAmount; |
35 | 29 | import com.hedera.hapi.node.base.AccountID; |
36 | 30 | import com.hedera.hapi.node.base.CurrentAndNextFeeSchedule; |
37 | 31 | import com.hedera.hapi.node.base.Duration; |
38 | 32 | import com.hedera.hapi.node.base.Key; |
39 | 33 | import com.hedera.hapi.node.base.ResponseCodeEnum; |
40 | 34 | import com.hedera.hapi.node.base.ServiceEndpoint; |
41 | 35 | import com.hedera.hapi.node.base.TransactionID; |
42 | | -import com.hedera.hapi.node.base.TransferList; |
43 | 36 | import com.hedera.hapi.node.state.common.EntityNumber; |
44 | 37 | import com.hedera.hapi.node.state.entity.EntityCounts; |
45 | 38 | import com.hedera.hapi.node.state.roster.RosterEntry; |
46 | | -import com.hedera.hapi.node.state.token.Account; |
47 | 39 | import com.hedera.hapi.node.state.token.StakingNodeInfo; |
48 | 40 | import com.hedera.hapi.node.token.CryptoCreateTransactionBody; |
49 | | -import com.hedera.hapi.node.token.CryptoTransferTransactionBody; |
50 | 41 | import com.hedera.hapi.node.transaction.TransactionBody; |
51 | 42 | import com.hedera.node.app.blocks.BlockStreamManager; |
52 | 43 | import com.hedera.node.app.blocks.impl.ImmediateStateChangeListener; |
|
94 | 85 | import com.swirlds.config.api.Configuration; |
95 | 86 | import com.swirlds.platform.system.InitTrigger; |
96 | 87 | import com.swirlds.state.State; |
97 | | -import com.swirlds.state.spi.CommittableWritableStates; |
98 | 88 | import com.swirlds.state.spi.WritableSingletonState; |
99 | 89 | import edu.umd.cs.findbugs.annotations.NonNull; |
100 | 90 | import java.io.IOException; |
|
103 | 93 | import java.nio.file.Files; |
104 | 94 | import java.nio.file.Paths; |
105 | 95 | import java.time.Instant; |
106 | | -import java.util.ArrayList; |
107 | 96 | import java.util.Arrays; |
108 | 97 | import java.util.EnumSet; |
109 | 98 | import java.util.List; |
@@ -409,84 +398,6 @@ ctx, createFileID(filesConfig.hapiPermissions(), config), bytes), |
409 | 398 | autoNodeAdminKeyUpdates.tryIfPresent(adminConfig.upgradeSysFilesLoc(), systemContext); |
410 | 399 | } |
411 | 400 |
|
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 | | - |
490 | 401 | /** |
491 | 402 | * Dispatches a synthetic node reward crypto transfer for the given active node accounts. |
492 | 403 | * If the {@link NodesConfig#minPerPeriodNodeRewardUsd()} is greater than zero, inactive nodes will receive the minimum node |
|
0 commit comments