Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update default cost model during Conway HF #418

Merged
merged 24 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
80eb095
chore: Update default cost model during Conway HF
satran004 Aug 30, 2024
a4a1593
Merge branch 'master' into cost_model
satran004 Sep 5, 2024
e72ba2b
chore: Change Map to LinkedHashMap to maintain the ordering
satran004 Sep 5, 2024
d1f8f5b
chore: Update CostModels from Map to LinkedHashMap to maintain origin…
satran004 Sep 5, 2024
184581c
chore: Return minFeeReferenceScriptByte in Ogmios backe and HashMap t…
satran004 Sep 5, 2024
4e983fa
chore: Added Plutus ops for V3
satran004 Sep 5, 2024
1953490
chore: New abstract method getLanguage to return Language
satran004 Sep 5, 2024
db7900c
chore: Handle Plutus V3
satran004 Sep 5, 2024
1e6a078
chore: CostModels is now a LinkedHashMap instead of Map and Ogmios PP…
satran004 Sep 5, 2024
10befbc
chore: Reference script resolver
satran004 Sep 5, 2024
aa07e29
chore: Add reference scripts
satran004 Sep 5, 2024
ffb88f3
chore: Conway era script data hash changes
satran004 Sep 5, 2024
514da26
chore: Ignore resolving reference scripts if reference scripts are ad…
satran004 Sep 5, 2024
3de4d36
chore: fixed tests
satran004 Sep 5, 2024
ebeb2e5
chore: Add a new overloaded method to pay a single Amount
satran004 Sep 7, 2024
1557dbf
chore: Adjust tests for Conway era related serialization changes
satran004 Sep 7, 2024
6d47e23
chore: Updated cost model -> languageview for V3
satran004 Sep 7, 2024
f3292af
feat: Conway era serialization change 258 tag for set.
satran004 Sep 7, 2024
74add54
feat: Adjust script data hash for Plutus V3
satran004 Sep 7, 2024
0c083e2
chore: Conway era changes
satran004 Sep 7, 2024
3d0fe07
feat: Update Koios and Ogmios backend service for latest Conway era c…
satran004 Sep 7, 2024
3ad9bb1
chore: Set era to Babbage for babbage era specific failed tests
satran004 Sep 7, 2024
eec470b
chore: Fixed test
satran004 Sep 7, 2024
9b3a912
chore: Merge with master
satran004 Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading