Skip to content

Commit f4164ca

Browse files
authored
fix: Protocol parameters are to be fetched from the DB
1 parent 5db564e commit f4164ca

File tree

4 files changed

+73
-57
lines changed

4 files changed

+73
-57
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public ProtocolParams merge(ProtocolParams from, ProtocolParams to){
3535
notNullMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull());
3636
notNullMapper.map(from, to);
3737
return to;
38-
3938
}
4039

4140
}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package org.cardanofoundation.rosetta.common.mapper;
22

3-
import static java.util.Optional.ofNullable;
4-
53
import lombok.AllArgsConstructor;
6-
import org.cardanofoundation.rosetta.api.block.model.domain.ProtocolParams;
7-
import org.cardanofoundation.rosetta.common.annotation.OpenApiMapper;
4+
85
import org.modelmapper.ModelMapper;
96
import org.openapitools.client.model.ProtocolParameters;
107

8+
import org.cardanofoundation.rosetta.api.block.model.domain.ProtocolParams;
9+
import org.cardanofoundation.rosetta.common.annotation.OpenApiMapper;
10+
11+
import static java.util.Optional.ofNullable;
12+
1113
@OpenApiMapper
1214
@AllArgsConstructor
1315
public class ProtocolParamsToRosettaProtocolParameters {
@@ -18,14 +20,14 @@ public ProtocolParameters toProtocolParameters(ProtocolParams model) {
1820
return ofNullable(modelMapper.getTypeMap(ProtocolParams.class, ProtocolParameters.class))
1921
.orElseGet(() -> modelMapper.createTypeMap(ProtocolParams.class, ProtocolParameters.class))
2022
.addMappings(mapper -> {
21-
2223
mapper.map(ProtocolParams::getAdaPerUtxoByte, ProtocolParameters::setCoinsPerUtxoSize);
23-
mapper.map(ProtocolParams::getMaxCollateralInputs, ProtocolParameters::setMaxCollateralInputs);
24+
mapper.map(ProtocolParams::getMaxCollateralInputs,
25+
ProtocolParameters::setMaxCollateralInputs);
2426
mapper.map(ProtocolParams::getMinFeeA, ProtocolParameters::setMinFeeCoefficient);
2527
mapper.map(ProtocolParams::getMinFeeB, ProtocolParameters::setMinFeeConstant);
26-
mapper.map(source -> source.getProtocolVersion().getMajor(), ProtocolParameters::setProtocol);
27-
28-
29-
}).map(model);
28+
mapper.map(source -> source.getProtocolVersion().getMajor(),
29+
ProtocolParameters::setProtocol);
30+
})
31+
.map(model);
3032
}
3133
}

api/src/main/java/org/cardanofoundation/rosetta/common/services/impl/PostgresLedgerDataProviderService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.cardanofoundation.rosetta.api.account.model.domain.Utxo;
2020
import org.cardanofoundation.rosetta.api.account.model.entity.AddressBalanceEntity;
2121
import org.cardanofoundation.rosetta.api.account.model.entity.AddressUtxoEntity;
22+
import org.cardanofoundation.rosetta.api.account.model.entity.StakeAddressBalanceEntity;
2223
import org.cardanofoundation.rosetta.api.account.model.repository.AddressBalanceRepository;
2324
import org.cardanofoundation.rosetta.api.account.model.repository.AddressUtxoRepository;
2425
import org.cardanofoundation.rosetta.api.block.mapper.BlockToEntity;
@@ -35,7 +36,6 @@
3536
import org.cardanofoundation.rosetta.api.block.model.domain.StakeRegistration;
3637
import org.cardanofoundation.rosetta.api.block.model.entity.BlockEntity;
3738
import org.cardanofoundation.rosetta.api.block.model.entity.ProtocolParamsEntity;
38-
import org.cardanofoundation.rosetta.api.account.model.entity.StakeAddressBalanceEntity;
3939
import org.cardanofoundation.rosetta.api.block.model.entity.TxnEntity;
4040
import org.cardanofoundation.rosetta.api.block.model.entity.UtxoKey;
4141
import org.cardanofoundation.rosetta.api.block.model.repository.BlockRepository;
@@ -225,8 +225,9 @@ public List<BlockTx> findTransactionsByBlock(Long blockNumber, String blockHash)
225225
public ProtocolParams findProtocolParametersFromIndexerAndConfig() {
226226
ProtocolParamsEntity paramsEntity = epochParamRepository.findLatestProtocolParams();
227227
ProtocolParams protocolParams = mapperProtocolParams.fromEntity(paramsEntity);
228+
ProtocolParams protocolParametersFromConfigFile = protocolParamService.getProtocolParameters();
228229

229-
return mapperProtocolParams.merge(protocolParamService.getProtocolParameters(), protocolParams);
230+
return mapperProtocolParams.merge(protocolParams, protocolParametersFromConfigFile);
230231
}
231232

232233
private Utxo createUtxoModel(List<Currency> currencies, AddressUtxoEntity entity) {

api/src/test/java/org/cardanofoundation/rosetta/common/mapper/ProtocolParamsToEntityTest.java

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.math.BigDecimal;
44
import java.math.BigInteger;
5-
import java.time.LocalDateTime;
65
import java.util.Map;
76

87
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,62 +22,39 @@ class ProtocolParamsToEntityTest extends BaseMapperTest {
2322

2423
@Test
2524
void fromEntity_Test_ok() {
26-
2725
EpochParamEntity from = newEpochParamEntity();
2826

2927
ProtocolParams into = my.fromEntity(from.getParams());
3028
var param = from.getParams();
31-
assertThat(into.getDecentralisationParam()).isEqualTo(param.getDecentralisationParam());
32-
assertThat(into.getAdaPerUtxoByte()).isEqualTo(param.getAdaPerUtxoByte());
33-
assertThat(into.getCommitteeMaxTermLength()).isEqualTo(param.getCommitteeMaxTermLength());
34-
assertThat(into.getCommitteeMinSize()).isEqualTo(param.getCommitteeMinSize());
35-
assertThat(into.getDrepDeposit()).isEqualTo(param.getDrepDeposit());
36-
assertThat(into.getCollateralPercent()).isEqualTo(param.getCollateralPercent());
37-
assertThat(into.getCostModelsHash()).isEqualTo(param.getCostModelsHash());
38-
assertThat(into.getExtraEntropy().getTag()).isEqualTo(param.getExtraEntropy());
39-
assertThat(into.getExpansionRate()).isEqualTo(param.getExpansionRate());
40-
assertThat(into.getKeyDeposit()).isEqualTo(param.getKeyDeposit());
41-
assertThat(into.getMaxBlockExMem()).isEqualTo(param.getMaxBlockExMem());
42-
assertThat(into.getMaxBlockHeaderSize()).isEqualTo(param.getMaxBlockHeaderSize());
43-
assertThat(into.getMaxBlockBodySize()).isEqualTo(param.getMaxBlockSize());
44-
assertThat(into.getMaxBlockExSteps()).isEqualTo(param.getMaxBlockExSteps());
45-
assertThat(into.getMaxBlockExMem()).isEqualTo(param.getMaxBlockExMem());
46-
assertThat(into.getMaxEpoch()).isEqualTo(param.getMaxEpoch());
47-
assertThat(into.getMaxTxExMem()).isEqualTo(param.getMaxTxExMem());
48-
assertThat(into.getMaxTxExSteps()).isEqualTo(param.getMaxTxExSteps());
49-
assertThat(into.getMaxTxSize()).isEqualTo(param.getMaxTxSize());
50-
assertThat(into.getMinFeeA()).isEqualTo(param.getMinFeeA());
51-
assertThat(into.getMinFeeB()).isEqualTo(param.getMinFeeB());
52-
assertThat(into.getMinPoolCost()).isEqualTo(param.getMinPoolCost());
53-
assertThat(into.getMinUtxo()).isEqualTo(param.getMinUtxo());
54-
assertThat(into.getNOpt()).isEqualTo(param.getNOpt());
55-
assertThat(into.getPoolDeposit()).isEqualTo(param.getPoolDeposit());
56-
assertThat(into.getPoolPledgeInfluence()).isEqualTo(param.getPoolPledgeInfluence());
57-
assertThat(into.getPriceMem()).isEqualTo(param.getPriceMem());
58-
assertThat(into.getPriceStep()).isEqualTo(param.getPriceStep());
59-
assertThat(into.getProtocolVersion().getMajor()).isEqualTo(param.getProtocolMajorVer());
60-
assertThat(into.getProtocolVersion().getMinor()).isEqualTo(param.getProtocolMinorVer());
61-
assertThat(into.getTreasuryGrowthRate()).isEqualTo(param.getTreasuryGrowthRate());
62-
assertThat(into.getMaxValSize()).isEqualTo(param.getMaxValSize());
63-
assertThat(into.getMaxCollateralInputs()).isEqualTo(param.getMaxCollateralInputs());
64-
assertThat(into.getGovActionDeposit()).isEqualTo(param.getGovActionDeposit());
65-
assertThat(into.getGovActionLifetime()).isEqualTo(param.getGovActionLifetime());
66-
assertThat(into.getDrepActivity()).isEqualTo(param.getDrepActivity());
29+
assertProtocolParameters(into, param);
6730

68-
assertThat(into.getCostModels().size()).isEqualTo(1);
31+
assertThat(into.getCostModels()).hasSize(1);
6932
assertThat(into.getCostModels().keySet()).containsAll(param.getCostModels().keySet());
7033
assertThat(into.getCostModels().values()).containsAll(param.getCostModels().values());
7134
}
7235

7336
@Test
7437
void merge_Test_ok() {
75-
ProtocolParams from = ProtocolParams.builder().costModels(Map.of("key3", new long[]{4})).build();
76-
ProtocolParams to = ProtocolParams.builder().costModelsHash("costHash6").build();
38+
ProtocolParams from = ProtocolParams.builder()
39+
.costModels(Map.of("key3", new long[]{4}))
40+
.minPoolCost(BigInteger.valueOf(5))
41+
.committeeMinSize(null)
42+
.committeeMaxTermLength(6)
43+
.build();
44+
ProtocolParams to = ProtocolParams.builder()
45+
.costModelsHash("costHash6")
46+
.minPoolCost(BigInteger.valueOf(7))
47+
.committeeMinSize(8)
48+
.committeeMaxTermLength(null)
49+
.build();
7750
ProtocolParams merged = my.merge(from, to);
78-
assertThat(merged.getCostModels().size()).isEqualTo(1);
51+
52+
assertThat(merged.getCostModels()).hasSize(1);
7953
assertThat(merged.getCostModels().keySet()).containsAll(from.getCostModels().keySet());
8054
assertThat(merged.getCostModels().values()).containsAll(from.getCostModels().values());
81-
55+
assertThat(merged.getMinPoolCost()).isEqualTo(from.getMinPoolCost());
56+
assertThat(merged.getCommitteeMinSize()).isEqualTo(to.getCommitteeMinSize());
57+
assertThat(merged.getCommitteeMaxTermLength()).isEqualTo(from.getCommitteeMaxTermLength());
8258
assertThat(merged.getCostModelsHash()).isEqualTo(to.getCostModelsHash());
8359
}
8460

@@ -131,4 +107,42 @@ private ProtocolParamsEntity newEpochParams() {
131107
.drepActivity(36)
132108
.build();
133109
}
134-
}
110+
111+
private void assertProtocolParameters(ProtocolParams into, ProtocolParamsEntity param) {
112+
assertThat(into.getDecentralisationParam()).isEqualTo(param.getDecentralisationParam());
113+
assertThat(into.getAdaPerUtxoByte()).isEqualTo(param.getAdaPerUtxoByte());
114+
assertThat(into.getCommitteeMaxTermLength()).isEqualTo(param.getCommitteeMaxTermLength());
115+
assertThat(into.getCommitteeMinSize()).isEqualTo(param.getCommitteeMinSize());
116+
assertThat(into.getDrepDeposit()).isEqualTo(param.getDrepDeposit());
117+
assertThat(into.getCollateralPercent()).isEqualTo(param.getCollateralPercent());
118+
assertThat(into.getCostModelsHash()).isEqualTo(param.getCostModelsHash());
119+
assertThat(into.getExtraEntropy().getTag()).isEqualTo(param.getExtraEntropy());
120+
assertThat(into.getExpansionRate()).isEqualTo(param.getExpansionRate());
121+
assertThat(into.getKeyDeposit()).isEqualTo(param.getKeyDeposit());
122+
assertThat(into.getMaxBlockHeaderSize()).isEqualTo(param.getMaxBlockHeaderSize());
123+
assertThat(into.getMaxBlockBodySize()).isEqualTo(param.getMaxBlockSize());
124+
assertThat(into.getMaxBlockExSteps()).isEqualTo(param.getMaxBlockExSteps());
125+
assertThat(into.getMaxBlockExMem()).isEqualTo(param.getMaxBlockExMem());
126+
assertThat(into.getMaxEpoch()).isEqualTo(param.getMaxEpoch());
127+
assertThat(into.getMaxTxExMem()).isEqualTo(param.getMaxTxExMem());
128+
assertThat(into.getMaxTxExSteps()).isEqualTo(param.getMaxTxExSteps());
129+
assertThat(into.getMaxTxSize()).isEqualTo(param.getMaxTxSize());
130+
assertThat(into.getMinFeeA()).isEqualTo(param.getMinFeeA());
131+
assertThat(into.getMinFeeB()).isEqualTo(param.getMinFeeB());
132+
assertThat(into.getMinPoolCost()).isEqualTo(param.getMinPoolCost());
133+
assertThat(into.getMinUtxo()).isEqualTo(param.getMinUtxo());
134+
assertThat(into.getNOpt()).isEqualTo(param.getNOpt());
135+
assertThat(into.getPoolDeposit()).isEqualTo(param.getPoolDeposit());
136+
assertThat(into.getPoolPledgeInfluence()).isEqualTo(param.getPoolPledgeInfluence());
137+
assertThat(into.getPriceMem()).isEqualTo(param.getPriceMem());
138+
assertThat(into.getPriceStep()).isEqualTo(param.getPriceStep());
139+
assertThat(into.getProtocolVersion().getMajor()).isEqualTo(param.getProtocolMajorVer());
140+
assertThat(into.getProtocolVersion().getMinor()).isEqualTo(param.getProtocolMinorVer());
141+
assertThat(into.getTreasuryGrowthRate()).isEqualTo(param.getTreasuryGrowthRate());
142+
assertThat(into.getMaxValSize()).isEqualTo(param.getMaxValSize());
143+
assertThat(into.getMaxCollateralInputs()).isEqualTo(param.getMaxCollateralInputs());
144+
assertThat(into.getGovActionDeposit()).isEqualTo(param.getGovActionDeposit());
145+
assertThat(into.getGovActionLifetime()).isEqualTo(param.getGovActionLifetime());
146+
assertThat(into.getDrepActivity()).isEqualTo(param.getDrepActivity());
147+
}
148+
}

0 commit comments

Comments
 (0)