Skip to content

Commit

Permalink
Merge branch 'develop' into 16035-throttled-tx-metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Rader <kim.rader@swirldslabs.com>
  • Loading branch information
kimbor authored Oct 25, 2024
2 parents e9a3502 + 59843dd commit af07b2d
Show file tree
Hide file tree
Showing 37 changed files with 2,424 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-flow-pull-request-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ jobs:
with:
ref: ${{ github.event.inputs.ref || '' }}
java-distribution: temurin
java-version: 21
java-version: 21.0.4
secrets:
gradle-cache-username: ${{ secrets.GRADLE_CACHE_USERNAME }}
gradle-cache-password: ${{ secrets.GRADLE_CACHE_PASSWORD }}
Expand Down
36 changes: 25 additions & 11 deletions .github/workflows/zxcron-extended-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,33 @@ jobs:
- name: Check for tags
id: check-tags-exist
run: |
XTS_COMMIT=$(git rev-list -n 1 ${XTS_CANDIDATE_TAG})
# Check if the tag exists and if so grab its commit id
set +e
git branch --contains ${XTS_COMMIT} | grep --quiet develop >/dev/null 2>&1
XTS_COMMIT=$(git rev-list -n 1 "${XTS_CANDIDATE_TAG}") >/dev/null 2>&1
XTS_COMMIT_FOUND="${?}"
set -e
# Cancel out if the tag does not exist
if [[ "${XTS_COMMIT_FOUND}" -ne 0 ]]; then
gh run cancel ${{ github.run_id }}
fi
# Check if the tag exists on the develop branch
set +e
git branch --contains "${XTS_COMMIT}" | grep --quiet develop >/dev/null 2>&1
BRANCH_ON_DEVELOP="${?}"
set -e
if [[ -n "${XTS_COMMIT}" && "${BRANCH_ON_DEVELOP}" -eq 0 ]]; then
# If the tag exists on the Develop Branch set the output variables as appropriate
# Otherwise cancel out
if [[ "${BRANCH_ON_DEVELOP}" -eq 0 ]]; then
echo "xts-tag-exists=true" >> $GITHUB_OUTPUT
echo "xts-tag-commit=${XTS_COMMIT}" >> $GITHUB_OUTPUT
echo "### Commit has been tagged as an XTS-Candidate" >> $GITHUB_STEP_SUMMARY
echo "xts-tag-commit=${XTS_COMMIT}" >> $GITHUB_STEP_SUMMARY
git push --delete origin ${XTS_CANDIDATE_TAG}
git tag -d ${XTS_CANDIDATE_TAG}
git push --delete origin "${XTS_CANDIDATE_TAG}"
git tag -d "${XTS_CANDIDATE_TAG}"
else
gh run cancel ${{ github.run_id }}
fi
Expand Down Expand Up @@ -152,14 +167,13 @@ jobs:
name: Tag as XTS-Passing
runs-on: network-node-linux-medium
needs:
# - abbreviated-panel
- abbreviated-panel
- extended-test-suite
- fetch-xts-candidate
# - hedera-node-jrs-panel
# if: ${{ needs.abbreviated-panel.result == 'success' ||
# needs.extended-test-suite.result == 'success' ||
# needs.hedera-node-jrs-panel.result == 'success' }}
if: ${{ needs.extended-test-suite.result == 'success' }}
- hedera-node-jrs-panel
if: ${{ needs.abbreviated-panel.result == 'success' ||
needs.extended-test-suite.result == 'success' ||
needs.hedera-node-jrs-panel.result == 'success' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zxcron-promote-build-candidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

- name: Checkout Tagged Code
id: checkout-tagged-code
if: ${{ needs.determine-build-candidate.build-candidate-exists == 'true' }}
if: ${{ needs.determine-build-candidate.outputs.build-candidate-exists == 'true' }}
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: '0'
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/zxf-prepare-extended-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,19 @@ jobs:
# move the tag if successful
- name: Tag Code and push
run: |
git push --delete origin "${XTS_CANDIDATE_TAG}"
git tag --delete "${XTS_CANDIDATE_TAG}"
# Check if the tag exists
set +e
git rev-list -n 1 "${XTS_CANDIDATE_TAG}" >/dev/null 2>&1
XTS_COMMIT_FOUND="${?}"
set -e
# Delete the tag if it does exist
if [[ "${XTS_COMMIT_FOUND}" -eq 0 ]]; then
git push --delete origin "${XTS_CANDIDATE_TAG}"
git tag -d "${XTS_CANDIDATE_TAG}"
fi
# Create the new tag
git tag --annotate "${XTS_CANDIDATE_TAG}" --message "chore: tagging commit for XTS promotion"
git push --set-upstream origin --tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,19 @@ public synchronized boolean shouldThrottle(@NonNull TransactionInfo txnInfo, Sta
*
* @param queryFunction the functionality of the query
* @param query the query to update the throttle requirements for
* @param state the current state of the node
* @param queryPayerId the payer id of the query
* @return whether the query should be throttled
*/
public synchronized boolean shouldThrottle(
@NonNull final HederaFunctionality queryFunction,
@NonNull final Query query,
@NonNull final State state,
@Nullable AccountID queryPayerId) {
requireNonNull(query);
requireNonNull(queryFunction);
setDecisionTime(instantSource.instant());
return frontendThrottle.checkAndEnforceThrottle(queryFunction, lastDecisionTime, query, queryPayerId);
return frontendThrottle.checkAndEnforceThrottle(queryFunction, lastDecisionTime, query, state, queryPayerId);
}

private void setDecisionTime(@NonNull final Instant time) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.hedera.hapi.node.base.HederaFunctionality.CONTRACT_CALL_LOCAL;
import static com.hedera.hapi.node.base.HederaFunctionality.CONTRACT_CREATE;
import static com.hedera.hapi.node.base.HederaFunctionality.CRYPTO_CREATE;
import static com.hedera.hapi.node.base.HederaFunctionality.CRYPTO_GET_ACCOUNT_BALANCE;
import static com.hedera.hapi.node.base.HederaFunctionality.CRYPTO_TRANSFER;
import static com.hedera.hapi.node.base.HederaFunctionality.ETHEREUM_TRANSACTION;
import static com.hedera.hapi.node.base.HederaFunctionality.TOKEN_ASSOCIATE_TO_ACCOUNT;
Expand Down Expand Up @@ -171,13 +172,15 @@ public boolean checkAndEnforceThrottle(
* @param queryFunction the functionality of the query
* @param now the time at which the query is being processed
* @param query the query to update the throttle requirements for
* @param state the current state of the node
* @param queryPayerId the payer id of the query
* @return whether the query should be throttled
*/
public boolean checkAndEnforceThrottle(
@NonNull final HederaFunctionality queryFunction,
@NonNull final Instant now,
@NonNull final Query query,
@NonNull final State state,
@Nullable final AccountID queryPayerId) {
final var configuration = configProvider.getConfiguration();
if (throttleExempt(queryPayerId, configuration)) {
Expand All @@ -197,13 +200,37 @@ public boolean checkAndEnforceThrottle(
if (manager == null) {
return true;
}
if (!manager.allReqsMetAt(now)) {

final boolean allReqMet;
if (queryFunction == CRYPTO_GET_ACCOUNT_BALANCE
&& configuration.getConfigData(TokensConfig.class).countingGetBalanceThrottleEnabled()) {
final var accountStore = new ReadableStoreFactory(state).getStore(ReadableAccountStore.class);
final var tokenConfig = configuration.getConfigData(TokensConfig.class);
final int associationCount =
Math.clamp(getAssociationCount(query, accountStore), 1, tokenConfig.maxRelsPerInfoQuery());
allReqMet = manager.allReqsMetAt(now, associationCount, ONE_TO_ONE);
} else {
allReqMet = manager.allReqsMetAt(now);
}

if (!allReqMet) {
reclaimLastAllowedUse();
return true;
}
return false;
}

private int getAssociationCount(@NonNull final Query query, @NonNull final ReadableAccountStore accountStore) {
final var accountID = query.cryptogetAccountBalanceOrThrow().accountID();
if (accountID != null) {
final var account = accountStore.getAccountById(accountID);
if (account != null) {
return account.numberAssociations();
}
}
return 0;
}

/**
* Updates the throttle requirements for given number of transactions of same functionality and returns whether they should be throttled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void handleQuery(@NonNull final Bytes requestBuffer, @NonNull final Buffe
handler.validate(context);

// 5. Check query throttles
if (shouldCharge && synchronizedThrottleAccumulator.shouldThrottle(function, query, payerID)) {
if (shouldCharge && synchronizedThrottleAccumulator.shouldThrottle(function, query, state, payerID)) {
workflowMetrics.incrementThrottled(function);
throw new PreCheckException(BUSY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ void verifyCheckAndEnforceThrottleIsCalled() {
void verifyCheckAndEnforceThrottleQueryIsCalled() {
// given
final var query = mock(Query.class);
final var state = mock(State.class);
final var accountID = mock(AccountID.class);

// when
subject.shouldThrottle(HederaFunctionality.CONTRACT_CREATE, query, accountID);
subject.shouldThrottle(HederaFunctionality.CONTRACT_CREATE, query, state, accountID);

// then
verify(throttleAccumulator, times(1))
.checkAndEnforceThrottle(eq(HederaFunctionality.CONTRACT_CREATE), any(), eq(query), eq(accountID));
.checkAndEnforceThrottle(
eq(HederaFunctionality.CONTRACT_CREATE), any(), eq(query), eq(state), eq(accountID));
}
}
Loading

0 comments on commit af07b2d

Please sign in to comment.