Skip to content

Commit 592232b

Browse files
authored
Chore/protocolparams optimization (#178)
* chore: reduced ProtocolParams to the needed fields, removed unused. Replaced mappers with classic conversion * fix: reverting the mappers. They will be optimized in a different branch * fix: mapping only relevant fields
1 parent 6caa093 commit 592232b

File tree

4 files changed

+1
-134
lines changed

4 files changed

+1
-134
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/domain/ProtocolParams.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cardanofoundation.rosetta.api.block.model.domain;
22

3-
import java.math.BigDecimal;
43
import java.math.BigInteger;
54
import java.util.Map;
65

@@ -11,7 +10,6 @@
1110

1211
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1312
import com.fasterxml.jackson.annotation.JsonInclude;
14-
import com.fasterxml.jackson.annotation.JsonProperty;
1513

1614
@Data
1715
@NoArgsConstructor
@@ -23,57 +21,20 @@ public class ProtocolParams {
2321

2422
private Integer minFeeA; //0
2523
private Integer minFeeB; //1
26-
private Integer maxBlockBodySize; //2
2724
private Integer maxTxSize; //3
28-
private Integer maxBlockHeaderSize; //4
2925
private BigInteger keyDeposit; //5
3026
private BigInteger poolDeposit; //6
31-
private Integer maxEpoch; //7
32-
@JsonProperty("nOpt")
33-
private Integer nOpt; //8
34-
private BigDecimal poolPledgeInfluence; //rational //9
35-
private BigDecimal expansionRate; //unit interval //10
36-
private BigDecimal treasuryGrowthRate; //11
37-
private BigDecimal decentralisationParam; //12
38-
private ExtraEntropy extraEntropy; //13
3927
private ProtocolVersion protocolVersion; //14
40-
@JsonProperty("minUTxOValue")
41-
private BigInteger minUtxoValue; //15
4228

4329
private BigInteger minPoolCost; //16
4430
private BigInteger adaPerUtxoByte; //17
4531

4632
//Alonzo changes
4733
private Map<String, long[]> costModels; //18
48-
private String costModelsHash;
49-
50-
//ex_unit_prices
51-
private BigDecimal priceMem; //19
52-
private BigDecimal priceStep; //19
53-
54-
//max tx ex units
55-
private BigInteger maxTxExMem; //20
56-
private BigInteger maxTxExSteps; //20
57-
58-
//max block ex units
59-
private BigInteger maxBlockExMem; //21
60-
private BigInteger maxBlockExSteps; //21
6134

6235
private Long maxValSize; //22
63-
64-
private Integer collateralPercent; //23
6536
private Integer maxCollateralInputs; //24
6637

67-
//Conway era fields
68-
// private PoolVotingThresholds poolVotingThresholds; //25
69-
// private DrepVoteThresholds drepVotingThresholds; //26
70-
private Integer committeeMinSize; //27
71-
private Integer committeeMaxTermLength; //28
72-
private Integer govActionLifetime; //29
73-
private BigInteger govActionDeposit; //30
74-
private BigInteger drepDeposit; //31
75-
private Integer drepActivity; //32
76-
7738
@Data
7839
public static class ExtraEntropy{
7940
String tag;
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cardanofoundation.rosetta.api.block.model.entity;
22

3-
import java.math.BigDecimal;
43
import java.math.BigInteger;
54
import java.util.Map;
65

@@ -12,7 +11,6 @@
1211

1312
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1413
import com.fasterxml.jackson.annotation.JsonInclude;
15-
import com.fasterxml.jackson.annotation.JsonProperty;
1614
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
1715
import com.fasterxml.jackson.databind.annotation.JsonNaming;
1816

@@ -28,52 +26,21 @@ public class ProtocolParamsEntity {
2826

2927
private Integer minFeeA; //0
3028
private Integer minFeeB; //1
31-
private Integer maxBlockSize; //2
3229
private Integer maxTxSize; //3
33-
private Integer maxBlockHeaderSize; //4
3430
private BigInteger keyDeposit; //5
3531
private BigInteger poolDeposit; //6
36-
private Integer maxEpoch; //7
37-
@JsonProperty("nopt")
38-
private Integer nOpt; //8
39-
private BigDecimal poolPledgeInfluence; //rational //9
40-
private BigDecimal expansionRate; //unit interval //10
41-
private BigDecimal treasuryGrowthRate; //11
42-
private BigDecimal decentralisationParam; //12
43-
private String extraEntropy; //13
32+
4433
private Integer protocolMajorVer; //14
4534
private Integer protocolMinorVer; //14
46-
private BigInteger minUtxo; //15
4735

4836
private BigInteger minPoolCost; //16
4937
private BigInteger adaPerUtxoByte; //17
5038

5139
//Alonzo changes
5240
private Map<String, long[]> costModels; //18
53-
private String costModelsHash;
54-
55-
//ex_unit_prices
56-
private BigDecimal priceMem; //19
57-
private BigDecimal priceStep; //19
58-
59-
//max tx ex units
60-
private BigInteger maxTxExMem; //20
61-
private BigInteger maxTxExSteps; //20
62-
63-
//max block ex units
64-
private BigInteger maxBlockExMem; //21
65-
private BigInteger maxBlockExSteps; //21
6641

6742
private Long maxValSize; //22
6843

69-
private Integer collateralPercent; //23
7044
private Integer maxCollateralInputs; //24
7145

72-
private Integer committeeMinSize; //27
73-
private Integer committeeMaxTermLength; //28
74-
private Integer govActionLifetime; //29
75-
private BigInteger govActionDeposit; //30
76-
private BigInteger drepDeposit; //31
77-
private Integer drepActivity; //32
78-
7946
}

api/src/main/java/org/cardanofoundation/rosetta/common/mapper/ProtocolParamsToEntity.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ public ProtocolParams fromEntity(ProtocolParamsEntity entity){
1919
return modelMapper.typeMap(ProtocolParamsEntity.class, ProtocolParams.class)
2020
.implicitMappings()
2121
.addMappings(mapper -> {
22-
mapper.<String>map(ProtocolParamsEntity::getExtraEntropy, (dest, v) -> dest.getExtraEntropy().setTag(v));
23-
mapper.map(ProtocolParamsEntity::getMaxBlockSize, ProtocolParams::setMaxBlockBodySize);
2422
mapper.<Integer>map(ProtocolParamsEntity::getProtocolMajorVer, (dest, v) -> dest.getProtocolVersion().setMajor(v));
2523
mapper.<Integer>map(ProtocolParamsEntity::getProtocolMinorVer, (dest, v) -> dest.getProtocolVersion().setMinor(v));
26-
mapper.map(ProtocolParamsEntity::getMinUtxo, ProtocolParams::setMinUtxoValue);
2724
})
2825
.map(entity);
2926
}
Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cardanofoundation.rosetta.common.mapper;
22

3-
import java.math.BigDecimal;
43
import java.math.BigInteger;
54
import java.util.Map;
65

@@ -38,24 +37,16 @@ void merge_Test_ok() {
3837
ProtocolParams from = ProtocolParams.builder()
3938
.costModels(Map.of("key3", new long[]{4}))
4039
.minPoolCost(BigInteger.valueOf(5))
41-
.committeeMinSize(null)
42-
.committeeMaxTermLength(6)
4340
.build();
4441
ProtocolParams to = ProtocolParams.builder()
45-
.costModelsHash("costHash6")
4642
.minPoolCost(BigInteger.valueOf(7))
47-
.committeeMinSize(8)
48-
.committeeMaxTermLength(null)
4943
.build();
5044
ProtocolParams merged = my.merge(from, to);
5145

5246
assertThat(merged.getCostModels()).hasSize(1);
5347
assertThat(merged.getCostModels().keySet()).containsAll(from.getCostModels().keySet());
5448
assertThat(merged.getCostModels().values()).containsAll(from.getCostModels().values());
5549
assertThat(merged.getMinPoolCost()).isEqualTo(from.getMinPoolCost());
56-
assertThat(merged.getCommitteeMinSize()).isEqualTo(to.getCommitteeMinSize());
57-
assertThat(merged.getCommitteeMaxTermLength()).isEqualTo(from.getCommitteeMaxTermLength());
58-
assertThat(merged.getCostModelsHash()).isEqualTo(to.getCostModelsHash());
5950
}
6051

6152
private EpochParamEntity newEpochParamEntity() {
@@ -65,81 +56,32 @@ private EpochParamEntity newEpochParamEntity() {
6556
private ProtocolParamsEntity newEpochParams() {
6657
return ProtocolParamsEntity
6758
.builder()
68-
.decentralisationParam(BigDecimal.valueOf(1))
6959
.adaPerUtxoByte(BigInteger.valueOf(2))
70-
.committeeMaxTermLength(3)
71-
.committeeMinSize(4)
72-
.drepDeposit(BigInteger.valueOf(5))
73-
.collateralPercent(6)
74-
.costModelsHash("costModelsHash7")
7560
.costModels(Map.of("key1", new long[]{0}))
76-
.extraEntropy("extraEntropy8")
77-
.expansionRate(BigDecimal.valueOf(9))
7861
.keyDeposit(BigInteger.valueOf(10))
79-
.maxBlockExMem(BigInteger.valueOf(11))
80-
.maxBlockHeaderSize(12)
81-
.maxBlockExSteps(BigInteger.valueOf(13))
82-
.maxBlockExMem(BigInteger.valueOf(14))
83-
.maxBlockSize(15)
84-
.maxEpoch(16)
85-
.maxTxExMem(BigInteger.valueOf(17))
86-
.maxTxExSteps(BigInteger.valueOf(18))
8762
.maxTxSize(19)
8863
.minFeeA(20)
8964
.minFeeB(21)
9065
.minPoolCost(BigInteger.valueOf(22))
91-
.minUtxo(BigInteger.valueOf(23))
92-
.nOpt(24)
9366
.poolDeposit(BigInteger.valueOf(25))
94-
.poolPledgeInfluence(BigDecimal.valueOf(26))
95-
.priceMem(BigDecimal.valueOf(27))
96-
.priceStep(BigDecimal.valueOf(28))
9767
.protocolMajorVer(29)
9868
.protocolMinorVer(30)
99-
.treasuryGrowthRate(BigDecimal.valueOf(31))
10069
.maxValSize(32L)
10170
.maxCollateralInputs(33)
102-
.govActionDeposit(BigInteger.valueOf(34))
103-
.govActionLifetime(35)
104-
.drepActivity(36)
10571
.build();
10672
}
10773

10874
private void assertProtocolParameters(ProtocolParams into, ProtocolParamsEntity param) {
109-
assertThat(into.getDecentralisationParam()).isEqualTo(param.getDecentralisationParam());
11075
assertThat(into.getAdaPerUtxoByte()).isEqualTo(param.getAdaPerUtxoByte());
111-
assertThat(into.getCommitteeMaxTermLength()).isEqualTo(param.getCommitteeMaxTermLength());
112-
assertThat(into.getCommitteeMinSize()).isEqualTo(param.getCommitteeMinSize());
113-
assertThat(into.getDrepDeposit()).isEqualTo(param.getDrepDeposit());
114-
assertThat(into.getCollateralPercent()).isEqualTo(param.getCollateralPercent());
115-
assertThat(into.getCostModelsHash()).isEqualTo(param.getCostModelsHash());
116-
assertThat(into.getExtraEntropy().getTag()).isEqualTo(param.getExtraEntropy());
117-
assertThat(into.getExpansionRate()).isEqualTo(param.getExpansionRate());
11876
assertThat(into.getKeyDeposit()).isEqualTo(param.getKeyDeposit());
119-
assertThat(into.getMaxBlockHeaderSize()).isEqualTo(param.getMaxBlockHeaderSize());
120-
assertThat(into.getMaxBlockBodySize()).isEqualTo(param.getMaxBlockSize());
121-
assertThat(into.getMaxBlockExSteps()).isEqualTo(param.getMaxBlockExSteps());
122-
assertThat(into.getMaxBlockExMem()).isEqualTo(param.getMaxBlockExMem());
123-
assertThat(into.getMaxEpoch()).isEqualTo(param.getMaxEpoch());
124-
assertThat(into.getMaxTxExMem()).isEqualTo(param.getMaxTxExMem());
125-
assertThat(into.getMaxTxExSteps()).isEqualTo(param.getMaxTxExSteps());
12677
assertThat(into.getMaxTxSize()).isEqualTo(param.getMaxTxSize());
12778
assertThat(into.getMinFeeA()).isEqualTo(param.getMinFeeA());
12879
assertThat(into.getMinFeeB()).isEqualTo(param.getMinFeeB());
12980
assertThat(into.getMinPoolCost()).isEqualTo(param.getMinPoolCost());
130-
assertThat(into.getMinUtxoValue()).isEqualTo(param.getMinUtxo());
131-
assertThat(into.getNOpt()).isEqualTo(param.getNOpt());
13281
assertThat(into.getPoolDeposit()).isEqualTo(param.getPoolDeposit());
133-
assertThat(into.getPoolPledgeInfluence()).isEqualTo(param.getPoolPledgeInfluence());
134-
assertThat(into.getPriceMem()).isEqualTo(param.getPriceMem());
135-
assertThat(into.getPriceStep()).isEqualTo(param.getPriceStep());
13682
assertThat(into.getProtocolVersion().getMajor()).isEqualTo(param.getProtocolMajorVer());
13783
assertThat(into.getProtocolVersion().getMinor()).isEqualTo(param.getProtocolMinorVer());
138-
assertThat(into.getTreasuryGrowthRate()).isEqualTo(param.getTreasuryGrowthRate());
13984
assertThat(into.getMaxValSize()).isEqualTo(param.getMaxValSize());
14085
assertThat(into.getMaxCollateralInputs()).isEqualTo(param.getMaxCollateralInputs());
141-
assertThat(into.getGovActionDeposit()).isEqualTo(param.getGovActionDeposit());
142-
assertThat(into.getGovActionLifetime()).isEqualTo(param.getGovActionLifetime());
143-
assertThat(into.getDrepActivity()).isEqualTo(param.getDrepActivity());
14486
}
14587
}

0 commit comments

Comments
 (0)