Skip to content

Commit

Permalink
chore: testing
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Sep 20, 2024
1 parent aa75ff7 commit ff769f4
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit ff769f4

Please sign in to comment.