From ff769f4d80872fa34997d6303dc100b1c9479e38 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 20 Sep 2024 15:36:03 +0300 Subject: [PATCH] chore: testing Signed-off-by: Ivan Ivanov --- .../handle/throttle/DispatchUsageManager.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/throttle/DispatchUsageManager.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/throttle/DispatchUsageManager.java index 70760b0ba452..af440bb52ad5 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/throttle/DispatchUsageManager.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/throttle/DispatchUsageManager.java @@ -44,6 +44,7 @@ import com.swirlds.state.spi.info.NetworkInfo; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.EnumSet; +import java.util.Random; import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; @@ -71,8 +72,8 @@ public DispatchUsageManager( } /** - * Tracks usage of the given dispatch before it is sent to a handler. This is only checked for contract - * operations now. This code will be moved into the contract-service module in the future. + * Tracks usage of the given dispatch before it is sent to a handler. This is only checked for contract operations + * now. This code will be moved into the contract-service module in the future. * * @param dispatch the dispatch * @throws ThrottleException if the dispatch should be throttled @@ -85,6 +86,11 @@ public void screenForCapacity(@NonNull final Dispatch dispatch) throws ThrottleE throttleServiceManager.resetThrottlesUnconditionally(readableStates); final var isThrottled = networkUtilizationManager.trackTxn(dispatch.txnInfo(), dispatch.consensusNow(), dispatch.stack()); + Random random = new Random(); + int number = random.nextInt(3); + if (number == 1 && dispatch.txnInfo().functionality().equals(HederaFunctionality.TRANSACTION_GET_RECEIPT)) { + throw ThrottleException.newNativeThrottleException(); + } if (networkUtilizationManager.wasLastTxnGasThrottled()) { throw ThrottleException.newGasThrottleException(); } else if (isThrottled) { @@ -95,6 +101,7 @@ public void screenForCapacity(@NonNull final Dispatch dispatch) throws ThrottleE /** * Tracks the final work done by handling this user transaction. + * * @param dispatch the dispatch */ public void finalizeAndSaveUsage(@NonNull final Dispatch dispatch) { @@ -115,6 +122,7 @@ public void finalizeAndSaveUsage(@NonNull final Dispatch dispatch) { /** * Tracks the work done for a dispatch that stopped after charging fees. + * * @param dispatch the dispatch */ public void trackFeePayments(@NonNull final Dispatch dispatch) { @@ -146,8 +154,8 @@ private void leakUnusedGas(@NonNull final Dispatch dispatch) { } /** - * Reclaims the throttle capacity for a failed dispatch that tried to implicitly - * perform {@link HederaFunctionality#CRYPTO_CREATE} operations. + * Reclaims the throttle capacity for a failed dispatch that tried to implicitly perform + * {@link HederaFunctionality#CRYPTO_CREATE} operations. * * @param dispatch the dispatch */ @@ -162,8 +170,8 @@ private void reclaimFailedCryptoCreateCapacity(@NonNull final Dispatch dispatch) } /** - * Reclaims the throttle capacity for a failed dispatch that tried to - * perform {@link HederaFunctionality#TOKEN_ASSOCIATE_TO_ACCOUNT} operations for Auto Association. + * Reclaims the throttle capacity for a failed dispatch that tried to perform + * {@link HederaFunctionality#TOKEN_ASSOCIATE_TO_ACCOUNT} operations for Auto Association. * * @param dispatch the dispatch */ @@ -188,7 +196,7 @@ private boolean usedSelfFrontendThrottleCapacity( final int numUsedCapacity, @NonNull final TransactionBody txnBody) { return numUsedCapacity > 0 && txnBody.nodeAccountIDOrThrow() - .equals(networkInfo.selfNodeInfo().accountId()); + .equals(networkInfo.selfNodeInfo().accountId()); } /**