Search in sources :

Example 1 with ThrottleDefinitions

use of com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions in project hedera-services by hashgraph.

the class HapiThrottlingTest method delegatesRebuild.

@Test
void delegatesRebuild() {
    // setup:
    ThrottleDefinitions defs = new ThrottleDefinitions();
    // when:
    subject.rebuildFor(defs);
    // then:
    verify(delegate).rebuildFor(defs);
}
Also used : ThrottleDefinitions(com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions) Test(org.junit.jupiter.api.Test)

Example 2 with ThrottleDefinitions

use of com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions in project hedera-services by hashgraph.

the class TxnAwareHandleThrottlingTest method otherMethodsPassThrough.

@Test
void otherMethodsPassThrough() {
    // setup:
    ThrottleDefinitions defs = new ThrottleDefinitions();
    List<DeterministicThrottle> whatever = List.of(DeterministicThrottle.withTps(1));
    given(delegate.allActiveThrottles()).willReturn(whatever);
    given(delegate.activeThrottlesFor(HederaFunctionality.CryptoTransfer)).willReturn(whatever);
    // when:
    var all = subject.allActiveThrottles();
    var onlyXfer = subject.activeThrottlesFor(HederaFunctionality.CryptoTransfer);
    subject.rebuildFor(defs);
    // then:
    verify(delegate).rebuildFor(defs);
    assertSame(whatever, all);
    assertSame(whatever, onlyXfer);
}
Also used : ThrottleDefinitions(com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) DeterministicThrottle(com.hedera.services.throttles.DeterministicThrottle) Test(org.junit.jupiter.api.Test)

Example 3 with ThrottleDefinitions

use of com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions in project hedera-services by hashgraph.

the class DeterministicThrottling method rebuildFor.

@Override
public void rebuildFor(ThrottleDefinitions defs) {
    List<DeterministicThrottle> newActiveThrottles = new ArrayList<>();
    EnumMap<HederaFunctionality, List<Pair<DeterministicThrottle, Integer>>> reqLists = new EnumMap<>(HederaFunctionality.class);
    int n = capacitySplitSource.getAsInt();
    for (var bucket : defs.getBuckets()) {
        try {
            var mapping = bucket.asThrottleMapping(n);
            var throttle = mapping.getLeft();
            var reqs = mapping.getRight();
            for (var req : reqs) {
                reqLists.computeIfAbsent(req.getLeft(), ignore -> new ArrayList<>()).add(Pair.of(throttle, req.getRight()));
            }
            newActiveThrottles.add(throttle);
        } catch (IllegalStateException badBucket) {
            log.error("When constructing bucket '{}' from state: {}", bucket.getName(), badBucket.getMessage());
        }
    }
    EnumMap<HederaFunctionality, ThrottleReqsManager> newFunctionReqs = new EnumMap<>(HederaFunctionality.class);
    reqLists.forEach((function, reqs) -> newFunctionReqs.put(function, new ThrottleReqsManager(reqs)));
    functionReqs = newFunctionReqs;
    activeThrottles = newActiveThrottles;
    logResolvedDefinitions();
}
Also used : MiscUtils.scheduledFunctionOf(com.hedera.services.utils.MiscUtils.scheduledFunctionOf) DeterministicThrottle(com.hedera.services.throttles.DeterministicThrottle) ScheduleCreate(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleCreate) CryptoCreate(com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoCreate) TxnAccessor(com.hedera.services.utils.TxnAccessor) ArrayList(java.util.ArrayList) MiscUtils.isGasThrottled(com.hedera.services.utils.MiscUtils.isGasThrottled) Pair(org.apache.commons.lang3.tuple.Pair) IntSupplier(java.util.function.IntSupplier) CryptoTransfer(com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoTransfer) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) AliasResolver(com.hedera.services.grpc.marshalling.AliasResolver) Query(com.hederahashgraph.api.proto.java.Query) EnumMap(java.util.EnumMap) Instant(java.time.Instant) SchedulableTransactionBody(com.hederahashgraph.api.proto.java.SchedulableTransactionBody) GlobalDynamicProperties(com.hedera.services.context.properties.GlobalDynamicProperties) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AliasResolver.usesAliases(com.hedera.services.grpc.marshalling.AliasResolver.usesAliases) ThrottleDefinitions(com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) TokenMint(com.hederahashgraph.api.proto.java.HederaFunctionality.TokenMint) ThrottleReqOpsScaleFactor(com.hedera.services.sysfiles.domain.throttling.ThrottleReqOpsScaleFactor) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) AliasManager(com.hedera.services.ledger.accounts.AliasManager) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) ArrayList(java.util.ArrayList) DeterministicThrottle(com.hedera.services.throttles.DeterministicThrottle) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) TokenMint(com.hederahashgraph.api.proto.java.HederaFunctionality.TokenMint) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap)

Aggregations

ThrottleDefinitions (com.hedera.services.sysfiles.domain.throttling.ThrottleDefinitions)3 DeterministicThrottle (com.hedera.services.throttles.DeterministicThrottle)2 GasLimitDeterministicThrottle (com.hedera.services.throttles.GasLimitDeterministicThrottle)2 Test (org.junit.jupiter.api.Test)2 GlobalDynamicProperties (com.hedera.services.context.properties.GlobalDynamicProperties)1 AliasResolver (com.hedera.services.grpc.marshalling.AliasResolver)1 AliasResolver.usesAliases (com.hedera.services.grpc.marshalling.AliasResolver.usesAliases)1 AliasManager (com.hedera.services.ledger.accounts.AliasManager)1 ThrottleReqOpsScaleFactor (com.hedera.services.sysfiles.domain.throttling.ThrottleReqOpsScaleFactor)1 MiscUtils.isGasThrottled (com.hedera.services.utils.MiscUtils.isGasThrottled)1 MiscUtils.scheduledFunctionOf (com.hedera.services.utils.MiscUtils.scheduledFunctionOf)1 TxnAccessor (com.hedera.services.utils.TxnAccessor)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1 CryptoCreate (com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoCreate)1 CryptoTransfer (com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoTransfer)1 ScheduleCreate (com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleCreate)1 TokenMint (com.hederahashgraph.api.proto.java.HederaFunctionality.TokenMint)1 Query (com.hederahashgraph.api.proto.java.Query)1 SchedulableTransactionBody (com.hederahashgraph.api.proto.java.SchedulableTransactionBody)1 TokenMintTransactionBody (com.hederahashgraph.api.proto.java.TokenMintTransactionBody)1