Skip to content

Commit

Permalink
Refresh multipliers in config callback; add EET (#7781)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Tinker <[email protected]>
  • Loading branch information
tinker-michaelj authored Aug 2, 2023
1 parent 374f09b commit 7691176
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import static com.hedera.node.app.service.mono.context.properties.PropertyNames.EXPIRY_MIN_CYCLE_ENTRY_CAPACITY;
import static com.hedera.node.app.service.mono.context.properties.PropertyNames.EXPIRY_THROTTLE_RESOURCE;
import static com.hedera.node.app.service.mono.context.properties.PropertyNames.LEDGER_TOTAL_TINY_BAR_FLOAT;
import static java.util.Objects.requireNonNull;

import com.hedera.node.app.service.mono.config.FileNumbers;
import com.hedera.node.app.service.mono.context.annotations.CompositeProps;
import com.hedera.node.app.service.mono.context.domain.security.HapiOpPermissions;
import com.hedera.node.app.service.mono.context.properties.GlobalDynamicProperties;
import com.hedera.node.app.service.mono.context.properties.PropertySource;
import com.hedera.node.app.service.mono.context.properties.PropertySources;
import com.hedera.node.app.service.mono.fees.congestion.MultiplierSources;
import com.hedera.node.app.service.mono.ledger.SigImpactHistorian;
import com.hedera.node.app.service.mono.state.adapters.MerkleMapLike;
import com.hedera.node.app.service.mono.state.merkle.MerkleNetworkContext;
Expand All @@ -38,6 +40,7 @@
import com.hedera.node.app.service.mono.utils.EntityNum;
import com.hederahashgraph.api.proto.java.ServicesConfigurationList;
import com.swirlds.common.system.address.AddressBook;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
Expand All @@ -60,6 +63,7 @@ public class ConfigCallbacks {
BigDecimal.TEN.add(BigDecimal.ONE).divide(BigDecimal.TEN, MATH_CONTEXT);
private final PropertySource properties;
private final PropertySources propertySources;
private final MultiplierSources multiplierSources;
private final HapiOpPermissions hapiOpPermissions;
private final Supplier<AddressBook> addressBook;
private final GlobalDynamicProperties dynamicProps;
Expand All @@ -86,7 +90,9 @@ public ConfigCallbacks(
final Supplier<MerkleNetworkContext> networkCtx,
final Supplier<MerkleMapLike<EntityNum, MerkleStakingInfo>> stakingInfos,
final SigImpactHistorian sigImpactHistorian,
final FileNumbers fileNumbers) {
final FileNumbers fileNumbers,
@NonNull final MultiplierSources multiplierSources) {
this.multiplierSources = requireNonNull(multiplierSources);
this.dynamicProps = dynamicProps;
this.propertySources = propertySources;
this.hapiOpPermissions = hapiOpPermissions;
Expand All @@ -110,6 +116,7 @@ public Consumer<ServicesConfigurationList> propertiesCb() {
hapiThrottling.applyGasConfig();
handleThrottling.applyGasConfig();
scheduleThrottling.applyGasConfig();
multiplierSources.resetExpectations();
expiryThrottle.rebuildGiven(
properties.getStringProperty(EXPIRY_THROTTLE_RESOURCE),
properties.getAccessListProperty(EXPIRY_MIN_CYCLE_ENTRY_CAPACITY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.hedera.node.app.service.mono.context.properties.GlobalDynamicProperties;
import com.hedera.node.app.service.mono.context.properties.PropertySource;
import com.hedera.node.app.service.mono.context.properties.PropertySources;
import com.hedera.node.app.service.mono.fees.congestion.MultiplierSources;
import com.hedera.node.app.service.mono.ledger.SigImpactHistorian;
import com.hedera.node.app.service.mono.state.adapters.MerkleMapLike;
import com.hedera.node.app.service.mono.state.merkle.MerkleNetworkContext;
Expand Down Expand Up @@ -86,6 +87,9 @@ class ConfigCallbacksTest {
@Mock
private PropertySource properties;

@Mock
private MultiplierSources multiplierSources;

@Mock
private SigImpactHistorian sigImpactHistorian;

Expand All @@ -110,7 +114,8 @@ void setUp() {
() -> networkCtx,
() -> MerkleMapLike.from(stakingInfos),
sigImpactHistorian,
fileNumbers);
fileNumbers,
multiplierSources);
}

@Test
Expand Down Expand Up @@ -138,6 +143,7 @@ void propertiesCbAsExpected() {
verify(dynamicProps).reload();
verify(functionalityThrottling, times(3)).applyGasConfig();
verify(networkCtx).renumberBlocksToMatch(blockValues);
verify(multiplierSources).resetExpectations();
// and:
final var updatedNode0Info = stakingInfos.get(EntityNum.fromLong(0L));
assertStakes(updatedNode0Info, historicalMaxStake / 2, overrideMaxStake);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,33 @@
package com.hedera.services.bdd.suites.issues;

import static com.hedera.services.bdd.spec.HapiSpec.defaultHapiSpec;
import static com.hedera.services.bdd.spec.HapiSpec.propertyPreservingHapiSpec;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.fileDelete;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.uploadInitCode;
import static com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.overridingThree;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext;
import static java.util.stream.Collectors.toList;

import com.hedera.services.bdd.spec.HapiPropertySource;
import com.hedera.services.bdd.spec.HapiSpec;
import com.hedera.services.bdd.spec.keys.KeyFactory;
import com.hedera.services.bdd.suites.HapiSuite;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Assertions;

public class Issue305Spec extends HapiSuite {
private static final Logger log = LogManager.getLogger(Issue305Spec.class);
Expand All @@ -46,9 +55,11 @@ public static void main(String... args) {

@Override
public List<HapiSpec> getSpecsInSuite() {
return IntStream.range(0, 5)
final var repeatedSpecs = new ArrayList<>(IntStream.range(0, 5)
.mapToObj(ignore -> createDeleteInSameRoundWorks())
.collect(toList());
.toList());
repeatedSpecs.add(congestionMultipliersRefreshOnPropertyUpdate());
return repeatedSpecs;
}

private HapiSpec createDeleteInSameRoundWorks() {
Expand All @@ -73,6 +84,57 @@ private HapiSpec createDeleteInSameRoundWorks() {
getFileInfo(nextFileId::get).logged());
}

private HapiSpec congestionMultipliersRefreshOnPropertyUpdate() {
final var civilian = "civilian";
final var preCongestionTxn = "preCongestionTxn";
final var postCongestionTxn = "postCongestionTxn";
final var multipurposeContract = "Multipurpose";
final var normalPrice = new AtomicLong();
final var multipliedPrice = new AtomicLong();

return propertyPreservingHapiSpec("CongestionMultipliersRefreshOnPropertyUpdate")
.preserving("fees.percentCongestionMultipliers", "fees.minCongestionPeriod", "contracts.maxGasPerSec")
.given(
cryptoCreate(civilian).balance(10 * ONE_HUNDRED_HBARS),
uploadInitCode(multipurposeContract),
contractCreate(multipurposeContract).payingWith(GENESIS).logging(),
contractCall(multipurposeContract)
.payingWith(civilian)
.fee(10 * ONE_HBAR)
.sending(ONE_HBAR)
.via(preCongestionTxn),
getTxnRecord(preCongestionTxn).providingFeeTo(normalPrice::set),
overridingThree(
"contracts.maxGasPerSec", "3_000_000",
"fees.percentCongestionMultipliers", "1,5x",
"fees.minCongestionPeriod", "1"))
.when(withOpContext((spec, opLog) -> {
for (int i = 0; i < 25; i++) {
TimeUnit.MILLISECONDS.sleep(50);
allRunFor(
spec,
contractCall(multipurposeContract)
.payingWith(civilian)
.gas(200_000)
.fee(10 * ONE_HBAR)
.sending(ONE_HBAR)
.deferStatusResolution());
}
}))
.then(
contractCall(multipurposeContract)
.payingWith(civilian)
.fee(10 * ONE_HBAR)
.sending(ONE_HBAR)
.via(postCongestionTxn),
getTxnRecord(postCongestionTxn).providingFeeTo(multipliedPrice::set),
withOpContext((spec, opLog) -> Assertions.assertEquals(
5.0,
(1.0 * multipliedPrice.get()) / normalPrice.get(),
0.1,
"~5x multiplier should be in affect!")));
}

@Override
protected Logger getResultsLogger() {
return log;
Expand Down

0 comments on commit 7691176

Please sign in to comment.