Search in sources :

Example 1 with GasLimitDeterministicThrottle

use of com.hedera.services.throttles.GasLimitDeterministicThrottle in project hedera-services by hashgraph.

the class MerkleNetworkContextTest method serializeWorks.

@Test
void serializeWorks() throws IOException {
    // setup:
    var out = mock(SerializableDataOutputStream.class);
    InOrder inOrder = inOrder(out, seqNo, serdes);
    throttling = mock(FunctionalityThrottling.class);
    gasLimitDeterministicThrottle = mock(GasLimitDeterministicThrottle.class);
    // and:
    var active = activeThrottles();
    given(throttling.allActiveThrottles()).willReturn(active);
    given(throttling.gasLimitThrottle()).willReturn(gasLimitDeterministicThrottle);
    given(gasLimitDeterministicThrottle.usageSnapshot()).willReturn(gasLimitUsageSnapshot);
    // when:
    subject.updateSnapshotsFrom(throttling);
    // and:
    subject.serialize(out);
    // expect:
    inOrder.verify(serdes).writeNullableInstant(fromJava(consensusTimeOfLastHandledTxn), out);
    inOrder.verify(seqNo).serialize(out);
    inOrder.verify(out).writeSerializable(midnightRateSet, true);
    // and:
    inOrder.verify(out).writeInt(3);
    for (int i = 0; i < 3; i++) {
        inOrder.verify(out).writeLong(used[i]);
        inOrder.verify(serdes).writeNullableInstant(fromJava(lastUseds[i]), out);
    }
    // and:
    inOrder.verify(out).writeInt(2);
    for (int i = 0; i < 2; i++) {
        inOrder.verify(serdes).writeNullableInstant(fromJava(congestionStarts()[i]), out);
    }
    inOrder.verify(out).writeLong(lastScannedEntity);
    inOrder.verify(out).writeLong(entitiesScannedThisSecond);
    inOrder.verify(out).writeLong(entitiesTouchedThisSecond);
    inOrder.verify(out).writeInt(stateVersion);
    inOrder.verify(serdes).writeNullableInstant(fromJava(lastMidnightBoundaryCheck), out);
    inOrder.verify(out).writeLong(preparedUpdateFileNum);
    inOrder.verify(out).writeByteArray(preparedUpdateFileHash);
}
Also used : InOrder(org.mockito.InOrder) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) FunctionalityThrottling(com.hedera.services.throttling.FunctionalityThrottling) Test(org.junit.jupiter.api.Test)

Example 2 with GasLimitDeterministicThrottle

use of com.hedera.services.throttles.GasLimitDeterministicThrottle in project hedera-services by hashgraph.

the class MerkleNetworkContextTest method setup.

@BeforeEach
void setup() {
    congestionStarts = new Instant[] { Instant.ofEpochSecond(1_234_567L, 54321L), Instant.ofEpochSecond(1_234_789L, 12345L) };
    consensusTimeOfLastHandledTxn = Instant.ofEpochSecond(1_234_567L, 54321L);
    lastMidnightBoundaryCheck = consensusTimeOfLastHandledTxn.minusSeconds(123L);
    seqNo = mock(SequenceNumber.class);
    given(seqNo.current()).willReturn(1234L);
    seqNoCopy = mock(SequenceNumber.class);
    given(seqNo.copy()).willReturn(seqNoCopy);
    midnightRateSet = new ExchangeRates(1, 14, 1_234_567L, 1, 15, 2_345_678L);
    midnightRateSetCopy = midnightRateSet.copy();
    usageSnapshots = new DeterministicThrottle.UsageSnapshot[] { new DeterministicThrottle.UsageSnapshot(123L, consensusTimeOfLastHandledTxn), new DeterministicThrottle.UsageSnapshot(456L, consensusTimeOfLastHandledTxn.plusSeconds(1L)) };
    gasLimitDeterministicThrottle = new GasLimitDeterministicThrottle(1234);
    gasLimitUsageSnapshot = new DeterministicThrottle.UsageSnapshot(1234L, consensusTimeOfLastHandledTxn);
    serdes = mock(DomainSerdes.class, RETURNS_DEEP_STUBS);
    MerkleNetworkContext.serdes = serdes;
    subject = new MerkleNetworkContext(consensusTimeOfLastHandledTxn, seqNo, lastScannedEntity, midnightRateSet);
    subject.setUsageSnapshots(usageSnapshots);
    subject.setGasThrottleUsageSnapshot(gasLimitUsageSnapshot);
    subject.setCongestionLevelStarts(congestionStarts());
    subject.setStateVersion(stateVersion);
    subject.updateAutoRenewSummaryCounts((int) entitiesScannedThisSecond, (int) entitiesTouchedThisSecond);
    subject.setLastMidnightBoundaryCheck(lastMidnightBoundaryCheck);
    subject.setPreparedUpdateFileNum(preparedUpdateFileNum);
    subject.setPreparedUpdateFileHash(preparedUpdateFileHash);
}
Also used : SequenceNumber(com.hedera.services.state.submerkle.SequenceNumber) ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) DeterministicThrottle(com.hedera.services.throttles.DeterministicThrottle) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with GasLimitDeterministicThrottle

use of com.hedera.services.throttles.GasLimitDeterministicThrottle in project hedera-services by hashgraph.

the class TxnAwareHandleThrottlingTest method gasLimitThrottleWorks.

@Test
void gasLimitThrottleWorks() {
    GasLimitDeterministicThrottle gasLimitDeterministicThrottle = new GasLimitDeterministicThrottle(1234);
    given(delegate.gasLimitThrottle()).willReturn(gasLimitDeterministicThrottle);
    GasLimitDeterministicThrottle gasLimitDeterministicThrottle1 = subject.gasLimitThrottle();
    assertEquals(gasLimitDeterministicThrottle, gasLimitDeterministicThrottle1);
}
Also used : GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) Test(org.junit.jupiter.api.Test)

Example 4 with GasLimitDeterministicThrottle

use of com.hedera.services.throttles.GasLimitDeterministicThrottle in project hedera-services by hashgraph.

the class DeterministicThrottling method applyGasConfig.

@Override
public void applyGasConfig() {
    long capacity;
    if (consensusThrottled) {
        if (dynamicProperties.shouldThrottleByGas() && dynamicProperties.consensusThrottleGasLimit() == 0) {
            log.warn(GAS_THROTTLE_AT_ZERO_WARNING_TPL, "Consensus");
            return;
        } else {
            capacity = dynamicProperties.consensusThrottleGasLimit();
        }
    } else {
        if (dynamicProperties.shouldThrottleByGas() && dynamicProperties.frontendThrottleGasLimit() == 0) {
            log.warn(GAS_THROTTLE_AT_ZERO_WARNING_TPL, "Frontend");
            return;
        } else {
            capacity = dynamicProperties.frontendThrottleGasLimit();
        }
    }
    gasThrottle = new GasLimitDeterministicThrottle(capacity);
    final var configDesc = "Resolved " + (consensusThrottled ? "consensus" : "frontend") + " gas throttle -\n  " + gasThrottle.getCapacity() + " gas/sec (throttling " + (dynamicProperties.shouldThrottleByGas() ? "ON" : "OFF") + ")";
    log.info(configDesc);
}
Also used : GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle)

Aggregations

GasLimitDeterministicThrottle (com.hedera.services.throttles.GasLimitDeterministicThrottle)4 Test (org.junit.jupiter.api.Test)2 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)1 ExchangeRates (com.hedera.services.state.submerkle.ExchangeRates)1 SequenceNumber (com.hedera.services.state.submerkle.SequenceNumber)1 DeterministicThrottle (com.hedera.services.throttles.DeterministicThrottle)1 FunctionalityThrottling (com.hedera.services.throttling.FunctionalityThrottling)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 InOrder (org.mockito.InOrder)1