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);
}
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);
}
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);
}
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);
}
Aggregations