Skip to content

Commit

Permalink
Merge branch 'release/0.52' into 13924-52-health-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Littley committed Jul 19, 2024
2 parents 4986b78 + e451ef0 commit 230ac89
Show file tree
Hide file tree
Showing 28 changed files with 27 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
base.example.server.port=8000
base.example.server.basePath=/swirlds
prometheus.endpointPortNumber=9999
sale.preferredStockHandling=LIFO
sale.preferredStockHandling=LIFO
2 changes: 1 addition & 1 deletion hedera-node/configuration/dev/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ staking.periodMins=1
staking.fees.nodeRewardPercentage=10
staking.fees.stakingRewardPercentage=10

contracts.knownBlockHash=
contracts.knownBlockHash=
2 changes: 1 addition & 1 deletion hedera-node/configuration/mainnet/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# hedera-config), this requirement will no longer be valid.
# It's used by modular code for property overrides, taking hedera-config/ as the base,
# with overrides from this file (configuration/mainnet/application.properties).
ledger.id=0x00
ledger.id=0x00
2 changes: 1 addition & 1 deletion hedera-node/configuration/mainnet/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#
# This file MUST match application.properties exactly as they are both a replica of file 121 on mainnet and
# this file is utilized by the mono-service config for property overrides whereas application.properties is utilized as
# an override by the hedera-config base config.
# an override by the hedera-config base config.
Original file line number Diff line number Diff line change
Expand Up @@ -7258,4 +7258,4 @@
}
]
}
]
]
2 changes: 1 addition & 1 deletion hedera-node/configuration/mainnet/upgrade/throttles.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ networkGetExecutionTime=2-50
systemDelete=2-59
systemUndelete=2-60
freeze=2-58
getAccountDetails=2-50
getAccountDetails=2-50
2 changes: 1 addition & 1 deletion hedera-node/configuration/preprod/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
contracts.chainId=298
entities.unlimitedAutoAssociationsEnabled=true
entities.unlimitedAutoAssociationsEnabled=true
2 changes: 1 addition & 1 deletion hedera-node/configuration/preprod/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ bootstrap.throttleDefsJson.resource=genesis/throttles.json
accounts.blocklist.enabled=false
accounts.blocklist.path=

contracts.knownBlockHash=
contracts.knownBlockHash=
2 changes: 1 addition & 1 deletion hedera-node/configuration/previewnet/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ accounts.blocklist.path=
contracts.evm.version.dynamic=true
contracts.maxNumWithHapiSigsAccess=0

contracts.knownBlockHash=
contracts.knownBlockHash=
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ systemUndelete=2-60
freeze=2-58
getAccountDetails=2-50
# Util
utilPrng=0-*
utilPrng=0-*
2 changes: 1 addition & 1 deletion hedera-node/configuration/testnet/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
ledger.id=0x01
contracts.chainId=296
bootstrap.genesisPublicKey=e06b22e0966108fa5d63fc6ae53f9824319b891cd4d6050dbf2b242be7e13344
contracts.knownBlockHash=
contracts.knownBlockHash=
Original file line number Diff line number Diff line change
Expand Up @@ -6852,4 +6852,4 @@
{
"expiryTime" : 1633392000
} ]
} ]
} ]
2 changes: 1 addition & 1 deletion hedera-node/configuration/testnet/upgrade/throttles.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion hedera-node/data/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ tokens.nfts.useVirtualMerkle=true
records.useConsolidatedFcq=true
cache.cryptoTransfer.warmThreads=30
contracts.maxNumWithHapiSigsAccess=0
tokens.balancesInQueries.enabled=true
tokens.balancesInQueries.enabled=true
2 changes: 1 addition & 1 deletion hedera-node/data/config/genesis.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#
# This file is needed for JRS tests of the configuration and should not be deleted until we can change it to look
# for the file in a different location
bar.test=genesis
bar.test=genesis
2 changes: 1 addition & 1 deletion hedera-node/hedera-app/data/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#
# This file is needed for unit tests of the configuration and should not be deleted!
foo.test=123
bar.test=456
bar.test=456
2 changes: 1 addition & 1 deletion hedera-node/hedera-app/data/config/genesis.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#
#
# This file is needed for unit tests of the configuration and should not be deleted!
bar.test=genesis
bar.test=genesis
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# This file is needed for unit tests of the configuration and should not be deleted!

foo.test=123Test
bar.test=456Test
bar.test=456Test
2 changes: 1 addition & 1 deletion hedera-node/hedera-app/for-test/genesis.properties.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#
# This file is needed for unit tests of the configuration and should not be deleted!

bar.test=genesisTest
bar.test=genesisTest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a=b
a=b
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@
import com.hedera.node.app.spi.workflows.PreHandleContext;
import com.hedera.node.app.spi.workflows.TransactionHandler;
import com.hedera.node.config.data.FeesConfig;
import com.hedera.node.config.data.HederaConfig;
import com.hedera.node.config.data.LedgerConfig;
import com.hedera.node.config.data.TokensConfig;
import com.swirlds.base.utility.Pair;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -172,7 +170,6 @@ public void handle(@NonNull final HandleContext context) throws HandleException
final var rejectingAccountID = op.ownerOrElse(context.payer());
final var rejections = op.rejections();

final var hederaConfig = context.configuration().getConfigData(HederaConfig.class);
final var ledgerConfig = context.configuration().getConfigData(LedgerConfig.class);
final var tokensConfig = context.configuration().getConfigData(TokensConfig.class);
validateTrue(tokensConfig.tokenRejectEnabled(), NOT_SUPPORTED);
Expand All @@ -186,18 +183,12 @@ public void handle(@NonNull final HandleContext context) throws HandleException
final var processedRejectTransfers = processRejectionsForTransfer(rejections, context, rejectingAccount);

// Apply all changes to the handleContext's states by performing the transfer to the treasuries
// Allowances will not be affected with the token reject
final var transferContext = new TransferContextImpl(context);
final var fungibleTokensStep = new AdjustFungibleTokenChangesStep(processedRejectTransfers, context.payer());
final var nftOwnersChangeStep = new NFTOwnersChangeStep(processedRejectTransfers, context.payer());
fungibleTokensStep.doIn(transferContext);
nftOwnersChangeStep.doIn(transferContext);

// Update the token allowances
if (hederaConfig.allowancesIsEnabled()) {
final var nftStore = context.storeFactory().writableStore(WritableNftStore.class);
updateFungibleAllowances(rejectingAccount, rejections, accountStore);
updateNFTAllowances(rejections, nftStore);
}
}

/**
Expand Down Expand Up @@ -290,49 +281,6 @@ private TokenTransferList processFungibleTokenRejection(
return createFungibleTransfer(tokenId, accountID, tokenRelation.balance(), token.treasuryAccountId());
}

/**
* Updates the NFT allowances in the state after the token transfers have been processed,
* by setting the spender to null.
*
* @param tokenReferences The list of tokens that were rejected.
* @param nftStore The store to access writable NFT information.
*/
private void updateNFTAllowances(
@NonNull final List<TokenReference> tokenReferences, @NonNull final WritableNftStore nftStore) {
tokenReferences.stream()
.filter(TokenReference::hasNft)
.map(reference -> getIfUsable(reference.nftOrThrow(), nftStore))
.forEach(nft -> {
if (nft.hasSpenderId()) {
nftStore.put(
nft.copyBuilder().spenderId((AccountID) null).build());
}
});
}

/**
* Updates the fungible token allowances in the state after the token transfers to the treasuries have been processed.
*
* @param rejectingAccount The account rejecting the tokens.
* @param tokenReferences The list of tokens that were rejected.
* @param accountStore The store to access writable account information.
*/
private void updateFungibleAllowances(
@NonNull final Account rejectingAccount,
@NonNull final List<TokenReference> tokenReferences,
@NonNull final WritableAccountStore accountStore) {
final var updatedFungibleTokenAllowances = new ArrayList<>(rejectingAccount.tokenAllowances());
updatedFungibleTokenAllowances.removeIf(allowance -> tokenReferences.stream()
.filter(TokenReference::hasFungibleToken)
.anyMatch(fungibleToken -> Objects.equals(fungibleToken.fungibleToken(), allowance.tokenId())));

final var updatedAccount = rejectingAccount
.copyBuilder()
.tokenAllowances(updatedFungibleTokenAllowances)
.build();
accountStore.put(updatedAccount);
}

@NonNull
@Override
public Fees calculateFees(final FeeContext feeContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ transactionBodyFormat=Random
#
#
## flag whether or not to use system accounts (i.e. account number under 100 excluding genesis and node accounts)
useSystemAccountAsPayer=false
useSystemAccountAsPayer=false
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ transactionBodyFormat=Random
#
#
## flag whether or not to use system accounts (i.e. account number under 100 excluding genesis and node accounts)
useSystemAccountAsPayer=false
useSystemAccountAsPayer=false
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
import static com.google.protobuf.ByteString.copyFromUtf8;
import static com.hedera.services.bdd.junit.TestTags.TOKEN;
import static com.hedera.services.bdd.spec.HapiSpec.defaultHapiSpec;
import static com.hedera.services.bdd.spec.assertions.AccountDetailsAsserts.accountDetailsWith;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountDetails;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenNftInfo;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoApproveAllowance;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken;
Expand All @@ -42,13 +39,9 @@
import static com.hedera.services.bdd.spec.transactions.token.HapiTokenReject.rejectingToken;
import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving;
import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.movingUnique;
import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.movingWithAllowance;
import static com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext;
import static com.hedera.services.bdd.suites.HapiSuite.DEFAULT_PAYER;
import static com.hedera.services.bdd.suites.HapiSuite.GENESIS;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_HBAR;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_HUNDRED_HBARS;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_MILLION_HBARS;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_AMOUNT_TRANSFERS_ONLY_ALLOWED_FOR_FUNGIBLE_COMMON;
Expand All @@ -60,7 +53,6 @@
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_NFT_ID;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_OWNER_ID;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SPENDER_DOES_NOT_HAVE_ALLOWANCE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_IS_PAUSED;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_REFERENCE_REPEATED;
Expand Down Expand Up @@ -213,84 +205,6 @@ final Stream<DynamicTest> tokenRejectWorksWithFungibleAndNFTTokens() {
getAccountBalance(TOKEN_TREASURY).logged().hasTokenBalance(FUNGIBLE_TOKEN_A, 1000L));
}

@HapiTest
final Stream<DynamicTest> tokenRejectWorksWithFungibleAndNFTTokensAndRemovesAllowancesCorrectly() {
return defaultHapiSpec("tokenRejectWorksWithFungibleAndNFTTokensAndRemovesAllowances")
.given(
newKeyNamed(MULTI_KEY),
cryptoCreate(ACCOUNT).balance(ONE_HUNDRED_HBARS).maxAutomaticTokenAssociations(3),
cryptoCreate(ACCOUNT_1).maxAutomaticTokenAssociations(3),
cryptoCreate(SPENDER).balance(ONE_HUNDRED_HBARS).maxAutomaticTokenAssociations(3),
cryptoCreate(TOKEN_TREASURY),
tokenCreate(FUNGIBLE_TOKEN_A)
.initialSupply(TOTAL_SUPPLY)
.adminKey(MULTI_KEY)
.supplyKey(MULTI_KEY)
.treasury(TOKEN_TREASURY),
tokenCreate(NON_FUNGIBLE_TOKEN_B)
.initialSupply(0)
.adminKey(MULTI_KEY)
.supplyKey(MULTI_KEY)
.treasury(TOKEN_TREASURY)
.tokenType(TokenType.NON_FUNGIBLE_UNIQUE),
tokenAssociate(ACCOUNT, FUNGIBLE_TOKEN_A, NON_FUNGIBLE_TOKEN_B),
mintToken(NON_FUNGIBLE_TOKEN_B, List.of(copyFromUtf8("memo"), copyFromUtf8("memo"))),
cryptoTransfer(
moving(250L, FUNGIBLE_TOKEN_A).between(TOKEN_TREASURY, ACCOUNT),
movingUnique(NON_FUNGIBLE_TOKEN_B, 1L, 2L).between(TOKEN_TREASURY, ACCOUNT)),
cryptoApproveAllowance()
.payingWith(DEFAULT_PAYER)
.addTokenAllowance(ACCOUNT, FUNGIBLE_TOKEN_A, SPENDER, 200L)
.addTokenAllowance(TOKEN_TREASURY, FUNGIBLE_TOKEN_A, ACCOUNT, 50L)
.signedBy(DEFAULT_PAYER, ACCOUNT, SPENDER, TOKEN_TREASURY)
.fee(ONE_HBAR),
// Verify Account's allowance works and exists:
cryptoTransfer(movingWithAllowance(50, FUNGIBLE_TOKEN_A).between(ACCOUNT, ACCOUNT_1))
.payingWith(SPENDER)
.signedBy(SPENDER),
getAccountDetails(ACCOUNT)
.payingWith(GENESIS)
.logged()
.has(accountDetailsWith().tokenAllowancesContaining(FUNGIBLE_TOKEN_A, SPENDER, 150)))
.when(withOpContext((spec, opLog) -> allRunFor(
spec,
// Try rejecting only when having allowance, without balance
tokenAssociate(SPENDER, FUNGIBLE_TOKEN_A),
tokenReject(SPENDER, rejectingToken(FUNGIBLE_TOKEN_A))
.hasKnownStatus(INSUFFICIENT_TOKEN_BALANCE),
tokenReject(
ACCOUNT,
rejectingToken(FUNGIBLE_TOKEN_A),
rejectingNFT(NON_FUNGIBLE_TOKEN_B, 1L),
rejectingNFT(NON_FUNGIBLE_TOKEN_B, 2L))
.via("tokenRejectRemovesAllowance"),
// Verify Spender's allowance is removed:
cryptoTransfer(movingWithAllowance(50, FUNGIBLE_TOKEN_A).between(ACCOUNT, ACCOUNT_1))
.payingWith(ACCOUNT)
.signedBy(ACCOUNT)
.hasKnownStatus(SPENDER_DOES_NOT_HAVE_ALLOWANCE))))
.then(
getTxnRecord("tokenRejectRemovesAllowance")
.andAllChildRecords()
.logged(),
getTokenNftInfo(NON_FUNGIBLE_TOKEN_B, 1L)
.hasAccountID(TOKEN_TREASURY)
.hasNoSpender(),
getTokenNftInfo(NON_FUNGIBLE_TOKEN_B, 2L)
.hasAccountID(TOKEN_TREASURY)
.hasNoSpender(),
getAccountBalance(ACCOUNT).logged().hasTokenBalance(FUNGIBLE_TOKEN_A, 0L),
getAccountDetails(ACCOUNT)
.payingWith(GENESIS)
.logged()
.has(accountDetailsWith().noAllowances()),
getAccountDetails(TOKEN_TREASURY)
.payingWith(GENESIS)
.logged()
.has(accountDetailsWith().tokenAllowancesContaining(FUNGIBLE_TOKEN_A, ACCOUNT, 50)),
getAccountBalance(TOKEN_TREASURY).logged().hasTokenBalance(FUNGIBLE_TOKEN_A, 950L));
}

@HapiTest
final Stream<DynamicTest> tokenRejectCasesWhileFreezeOrPausedOrSigRequired() {
return defaultHapiSpec("tokenRejectWorksWhileFreezeOrPausedOrSigRequired")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"stateMutability": "view",
"type": "function"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ randomTransferFromHollowAccount.bias=10
randomAccountUpdate.bias=10
randomContract.bias=1
randomContract.ceilingNum=50
randomContractDeletion.bias=10
randomContractDeletion.bias=10
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ randomAccount.bias=60
randomAccount.ceilingNum=100
randomAccountUpdate.bias=30
randomTransfer.bias=100
randomEthereumTransactionTransfer.bias=100
randomEthereumTransactionTransfer.bias=100

0 comments on commit 230ac89

Please sign in to comment.