Skip to content

Commit

Permalink
chore: Update default cost model during Conway HF (#418)
Browse files Browse the repository at this point in the history
* chore: Update default cost model during Conway HF

* chore: Change Map to LinkedHashMap to maintain the ordering

* chore: Update CostModels from Map to LinkedHashMap to maintain original order

* chore: Return minFeeReferenceScriptByte in Ogmios backe and HashMap to LinkedHashMap

* chore: Added Plutus ops for V3

* chore: New abstract method getLanguage to return Language

* chore: Handle Plutus V3

* chore: CostModels is now a LinkedHashMap instead of Map and Ogmios PP change

* chore: Reference script resolver

* chore: Add reference scripts

* chore: Conway era script data hash changes

* chore: Ignore resolving reference scripts if reference scripts are added through withReferenceSctip() and V3 tests

* chore: fixed tests

* chore: Add a new overloaded method to pay a single Amount

* chore: Adjust tests for Conway era related serialization changes

* chore: Updated cost model -> languageview for V3

* feat: Conway era serialization change 258 tag for set.

* feat: Adjust script data hash for Plutus V3

* chore: Conway era changes

* feat: Update Koios and Ogmios backend service for latest Conway era changes

* chore: Set era to Babbage for babbage era specific failed tests

* chore: Fixed test
  • Loading branch information
satran004 authored Sep 10, 2024
1 parent 8b5b9a8 commit 83b8eac
Show file tree
Hide file tree
Showing 60 changed files with 2,500 additions and 1,257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ public static Result<List<EvaluationResult>> processEvaluateResponse(Response<Ob
redeemerTag = RedeemerTag.Spend;
else if ("mint".equals(splits[0]))
redeemerTag = RedeemerTag.Mint;
else if ("certificate".equals(splits[0]))
else if ("cert".equals(splits[0]) || "publish".equals(splits[0]) || "certificate".equals(splits[0]))
redeemerTag = RedeemerTag.Cert;
else if ("withdrawal".equals(splits[0]))
else if ("reward".equals(splits[0]) || "withdrawal".equals(splits[0]) || "withdraw".equals(splits[0]))
redeemerTag = RedeemerTag.Reward;
else if ("vote".equals(splits[0]))
redeemerTag = RedeemerTag.Voting;
else if ("propose".equals(splits[0]))
redeemerTag = RedeemerTag.Proposing;
else
throw new RuntimeException("Invalid RedeemerTag in evaluateTx reponse: " + splits[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.math.BigInteger;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

Expand Down Expand Up @@ -59,7 +62,7 @@ void testGetProtocolParameters() throws ApiException {
System.out.println(JsonUtil.getPrettyJson(protocolParams));

assertThat(protocolParams, notNullValue());
assertThat(protocolParams.getMinUtxo(), is("4310"));
assertThat(protocolParams.getMinUtxo(), is("0"));
assertThat(protocolParams.getPoolDeposit(), is("500000000"));
}

Expand All @@ -78,5 +81,29 @@ void testGetLatestProtocolParameters() throws ApiException {
assertThat(protocolParams.getCoinsPerUtxoSize(), is("4310"));
assertThat(protocolParams.getEMax(), notNullValue());
assertThat(protocolParams.getNOpt(), notNullValue());

assertThat(protocolParams.getPvtMotionNoConfidence(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getPvtCommitteeNormal(),greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getPvtCommitteeNormal(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getPvtHardForkInitiation(), greaterThan(new BigDecimal(0)));

assertThat(protocolParams.getDvtMotionNoConfidence(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getDvtCommitteeNormal(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getDvtCommitteeNoConfidence(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getDvtUpdateToConstitution(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getDvtHardForkInitiation(), greaterThan(new BigDecimal(0)));
// assertThat(protocolParams.getDvtPPNetworkGroup(), greaterThan(new BigDecimal(0)));
// assertThat(protocolParams.getDvtPPEconomicGroup(), greaterThan(new BigDecimal(0)));
// assertThat(protocolParams.getDvtPPTechnicalGroup(), greaterThan(new BigDecimal(0)));
// assertThat(protocolParams.getDvtPPGovGroup(), greaterThan(new BigDecimal(0)));
assertThat(protocolParams.getDvtTreasuryWithdrawal(), greaterThan(new BigDecimal(0)));

assertThat(protocolParams.getCommitteeMinSize(), notNullValue());
assertThat(protocolParams.getCommitteeMaxTermLength(), greaterThan(0));
assertThat(protocolParams.getGovActionLifetime(), greaterThan(0));
assertThat(protocolParams.getGovActionDeposit(), greaterThan(BigInteger.ZERO));
assertThat(protocolParams.getDrepDeposit(), greaterThan(BigInteger.ZERO));
assertThat(protocolParams.getDrepActivity(), greaterThan(0));
assertThat(protocolParams.getMinFeeRefScriptCostPerByte(), greaterThan(BigDecimal.ZERO));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,63 +179,58 @@ private Result<ProtocolParams> convertToProtocolParams(EpochParams epochParams)
if (epochParams.getCoinsPerUtxoSize() != null) {
protocolParams.setCoinsPerUtxoSize(epochParams.getCoinsPerUtxoSize());
}
if (epochParams.getDvtPPNetworkGroup() != null) {
protocolParams.setDvtPPNetworkGroup(epochParams.getDvtPPNetworkGroup());
}
if (epochParams.getDvtPPEconomicGroup() != null) {
protocolParams.setDvtPPEconomicGroup(epochParams.getDvtPPEconomicGroup());
}
if (epochParams.getDvtPPTechnicalGroup() != null) {
protocolParams.setDvtPPTechnicalGroup(epochParams.getDvtPPTechnicalGroup());
}
if (epochParams.getDvtPPGovGroup() != null) {
protocolParams.setDvtPPGovGroup(epochParams.getDvtPPGovGroup());
}
if (epochParams.getDvtTreasuryWithdrawal() != null) {
protocolParams.setDvtTreasuryWithdrawal(epochParams.getDvtTreasuryWithdrawal());
}
if (epochParams.getCommitteeMinSize() != null) {
protocolParams.setCommitteeMinSize(epochParams.getCommitteeMinSize());
}
if (epochParams.getCommitteeMaxTermLength() != null) {
protocolParams.setCommitteeMaxTermLength(epochParams.getCommitteeMaxTermLength());
}
if (epochParams.getGovActionLifetime() != null) {
protocolParams.setGovActionLifetime(epochParams.getGovActionLifetime());
}

//Pool voting threshold
protocolParams.setPvtMotionNoConfidence(epochParams.getPvtMotionNoConfidence());
protocolParams.setPvtCommitteeNormal(epochParams.getPvtCommitteeNormal());
protocolParams.setPvtCommitteeNoConfidence(epochParams.getPvtCommitteeNoConfidence());
protocolParams.setPvtHardForkInitiation(epochParams.getPvtHardForkInitiation());
protocolParams.setPvtPPSecurityGroup(epochParams.getPvtppSecurityGroup());

//Drep vote thresholds
protocolParams.setDvtMotionNoConfidence(epochParams.getDvtMotionNoConfidence());
protocolParams.setDvtCommitteeNormal(epochParams.getDvtCommitteeNormal());
protocolParams.setDvtCommitteeNoConfidence(epochParams.getDvtCommitteeNoConfidence());
protocolParams.setDvtUpdateToConstitution(epochParams.getDvtUpdateToConstitution());
protocolParams.setDvtHardForkInitiation(epochParams.getDvtHardForkInitiation());

protocolParams.setDvtPPNetworkGroup(epochParams.getDvtPPNetworkGroup());
protocolParams.setDvtPPEconomicGroup(epochParams.getDvtPPEconomicGroup());
protocolParams.setDvtPPTechnicalGroup(epochParams.getDvtPPTechnicalGroup());
protocolParams.setDvtPPGovGroup(epochParams.getDvtPPGovGroup());
protocolParams.setDvtTreasuryWithdrawal(epochParams.getDvtTreasuryWithdrawal());

protocolParams.setCommitteeMinSize(epochParams.getCommitteeMinSize());
protocolParams.setCommitteeMaxTermLength(epochParams.getCommitteeMaxTermLength());
protocolParams.setGovActionLifetime(epochParams.getGovActionLifetime());
if (epochParams.getGovActionDeposit() != null) {
protocolParams.setGovActionDeposit(new BigInteger(epochParams.getGovActionDeposit()));
protocolParams.setGovActionDeposit(new BigInteger(epochParams.getGovActionDeposit().trim()));
}
if (epochParams.getDrepDeposit() != null) {
protocolParams.setDrepDeposit(new BigInteger(epochParams.getDrepDeposit()));
}
if (epochParams.getDrepActivity() != null) {
protocolParams.setDrepActivity(epochParams.getDrepActivity());
}
if (epochParams.getMinFeeRefScriptCostPerByte() != null) {
protocolParams.setMinFeeRefScriptCostPerByte(epochParams.getMinFeeRefScriptCostPerByte());
protocolParams.setDrepDeposit(new BigInteger(epochParams.getDrepDeposit().trim()));
}
protocolParams.setDrepActivity(epochParams.getDrepActivity());
protocolParams.setMinFeeRefScriptCostPerByte(epochParams.getMinFeeRefScriptCostPerByte());

return Result.success("OK").withValue(protocolParams).code(200);
}

private Map<String, Map<String, Long>> convertToCostModels(JsonNode costModelsJsonNode) {
private LinkedHashMap<String, LinkedHashMap<String, Long>> convertToCostModels(JsonNode costModelsJsonNode) {
String costModelsJson = costModelsJsonNode.asText();
try {
costModelsJson = objectMapper.writeValueAsString(costModelsJsonNode);
} catch (JsonProcessingException ignored) {}
try {
Map<String, Map<String, Long>> result2 = objectMapper.readValue(costModelsJson, new TypeReference<>() {});
LinkedHashMap<String, LinkedHashMap<String, Long>> result2 = objectMapper.readValue(costModelsJson, new TypeReference<LinkedHashMap>() {});
return result2;
} catch (JsonProcessingException ignored) {}
Map<String, Map<String, Long>> res = new HashMap<>();
LinkedHashMap<String, LinkedHashMap<String, Long>> res = new LinkedHashMap<>();
try {
Map<String, List<Long>> result = objectMapper.readValue(costModelsJson, new TypeReference<>() {});
LinkedHashMap<String, List<Long>> result = objectMapper.readValue(costModelsJson, new TypeReference<LinkedHashMap>() {});
final AtomicInteger plutusV1IndexHolder = new AtomicInteger();
Map<String, Long> plutusV1CostModelsMap = new HashMap<>();
LinkedHashMap<String, Long> plutusV1CostModelsMap = new LinkedHashMap<>();
final AtomicInteger plutusV2IndexHolder = new AtomicInteger();
Map<String, Long> plutusV2CostModelsMap = new HashMap<>();
final AtomicInteger plutusV3IndexHolder = new AtomicInteger();
Map<String, Long> plutusV3CostModelsMap = new HashMap<>();
LinkedHashMap<String, Long> plutusV2CostModelsMap = new LinkedHashMap<>();
result.forEach((key, value) -> {
if (key.equals("PlutusV1")) {
value.forEach(aLong -> {
Expand All @@ -250,13 +245,6 @@ private Map<String, Map<String, Long>> convertToCostModels(JsonNode costModelsJs
});
res.put(key, plutusV2CostModelsMap);
}
// else if (key.equals("PlutusV3")) {
// value.forEach(aLong -> {
// final int index = plutusV3IndexHolder.getAndIncrement();
// plutusV3CostModelsMap.put(PlutusOps.getOperations(3).get(index), aLong);
// });
// res.put(key, plutusV3CostModelsMap);
// } TODO Uncomment after adding V3_OPS
});
} catch (JsonProcessingException ignored) {}
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -29,5 +31,6 @@ public void testGetLatestProtocolParameters() throws ApiException {
assertEquals(protocolParams.getCollateralPercent().intValue(), 150);
assertThat(protocolParams.getEMax()).isNotNull();
assertThat(protocolParams.getNOpt()).isNotNull();
assertThat(protocolParams.getMinFeeRefScriptCostPerByte()).isEqualTo(BigDecimal.valueOf(15.0));
}
}
Loading

0 comments on commit 83b8eac

Please sign in to comment.