Skip to content

Commit 28e36b2

Browse files
author
Mateusz Czeladka
committed
feat: propagation supports is not recommended without open db transaction and can lead to connection leak issues.
1 parent dc55d83 commit 28e36b2

File tree

7 files changed

+27
-28
lines changed

7 files changed

+27
-28
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/account/service/LedgerAccountServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import lombok.extern.slf4j.Slf4j;
1010

1111
import org.springframework.stereotype.Component;
12-
import org.springframework.transaction.annotation.Propagation;
1312
import org.springframework.transaction.annotation.Transactional;
1413
import org.openapitools.client.model.Currency;
1514

@@ -24,7 +23,7 @@
2423
@Slf4j
2524
@RequiredArgsConstructor
2625
@Component
27-
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
26+
@Transactional(readOnly = true)
2827
public class LedgerAccountServiceImpl implements LedgerAccountService {
2928

3029
private final AddressUtxoRepository addressUtxoRepository;

api/src/main/java/org/cardanofoundation/rosetta/api/block/controller/BlockApiImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BlockApiImpl implements BlockApi {
3434

3535
@Override
3636
public ResponseEntity<BlockResponse> block(@RequestBody BlockRequest blockRequest) {
37-
if(offlineMode) {
37+
if (offlineMode) {
3838
throw ExceptionFactory.notSupportedInOfflineMode();
3939
}
4040
networkService.verifyNetworkRequest(blockRequest.getNetworkIdentifier());
@@ -51,7 +51,7 @@ public ResponseEntity<BlockResponse> block(@RequestBody BlockRequest blockReques
5151
@Override
5252
public ResponseEntity<BlockTransactionResponse> blockTransaction(
5353
@RequestBody BlockTransactionRequest blockReq) {
54-
if(offlineMode) {
54+
if (offlineMode) {
5555
throw ExceptionFactory.notSupportedInOfflineMode();
5656
}
5757
networkService.verifyNetworkRequest(blockReq.getNetworkIdentifier());
@@ -63,6 +63,6 @@ public ResponseEntity<BlockTransactionResponse> blockTransaction(
6363
BlockTx blockTx = blockService.getBlockTransaction(blockId, blockHash, txHash);
6464

6565
return ResponseEntity.ok(mapper.mapToBlockTransactionResponse(blockTx));
66-
6766
}
67+
6868
}

api/src/main/java/org/cardanofoundation/rosetta/api/block/service/BlockServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import lombok.extern.slf4j.Slf4j;
77

88
import org.springframework.stereotype.Service;
9-
import org.springframework.transaction.annotation.Propagation;
109
import org.springframework.transaction.annotation.Transactional;
1110

1211
import org.cardanofoundation.rosetta.api.block.model.domain.Block;
@@ -17,7 +16,7 @@
1716
@Slf4j
1817
@Service
1918
@RequiredArgsConstructor
20-
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
19+
@Transactional(readOnly = true)
2120
public class BlockServiceImpl implements BlockService {
2221

2322
private final LedgerBlockService ledgerBlockService;

api/src/main/java/org/cardanofoundation/rosetta/api/block/service/LedgerBlockServiceImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import lombok.extern.slf4j.Slf4j;
1616

1717
import org.springframework.stereotype.Component;
18-
import org.springframework.transaction.annotation.Propagation;
1918
import org.springframework.transaction.annotation.Transactional;
2019
import org.apache.commons.lang3.ObjectUtils;
2120

@@ -49,11 +48,9 @@
4948
@Slf4j
5049
@RequiredArgsConstructor
5150
@Component
52-
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
51+
@Transactional(readOnly = true)
5352
public class LedgerBlockServiceImpl implements LedgerBlockService {
5453

55-
private final ProtocolParamService protocolParamService;
56-
5754
private final BlockRepository blockRepository;
5855
private final TxRepository txRepository;
5956
private final StakeRegistrationRepository stakeRegistrationRepository;

api/src/main/java/org/cardanofoundation/rosetta/api/search/service/LedgerSearchServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.springframework.data.domain.PageRequest;
1212
import org.springframework.data.domain.Pageable;
1313
import org.springframework.stereotype.Service;
14-
import org.springframework.transaction.annotation.Propagation;
1514
import org.springframework.transaction.annotation.Transactional;
1615
import org.openapitools.client.model.Operator;
1716

@@ -26,7 +25,7 @@
2625
@Slf4j
2726
@Service
2827
@RequiredArgsConstructor
29-
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
28+
@Transactional(readOnly = true)
3029
public class LedgerSearchServiceImpl implements LedgerSearchService {
3130

3231
private final TxRepository txRepository;

api/src/main/java/org/cardanofoundation/rosetta/api/search/service/SearchServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import lombok.extern.slf4j.Slf4j;
88

99
import org.springframework.stereotype.Service;
10-
import org.springframework.transaction.annotation.Propagation;
1110
import org.springframework.transaction.annotation.Transactional;
1211
import org.apache.commons.lang3.ObjectUtils;
1312
import org.openapitools.client.model.AccountIdentifier;
@@ -25,7 +24,7 @@
2524
@Slf4j
2625
@Service
2726
@RequiredArgsConstructor
28-
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
27+
@Transactional(readOnly = true)
2928
public class SearchServiceImpl implements SearchService {
3029

3130
private final BlockMapper blockMapper;

api/src/main/java/org/cardanofoundation/rosetta/common/services/ProtocolParamServiceImpl.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.cardanofoundation.rosetta.common.services;
22

3-
import java.io.*;
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
47
import java.math.BigInteger;
58
import java.nio.charset.StandardCharsets;
69
import java.util.Optional;
@@ -13,7 +16,6 @@
1316
import org.springframework.cache.annotation.Cacheable;
1417
import org.springframework.scheduling.annotation.Scheduled;
1518
import org.springframework.stereotype.Service;
16-
import org.springframework.transaction.annotation.Propagation;
1719
import org.springframework.transaction.annotation.Transactional;
1820
import org.apache.commons.io.IOUtils;
1921
import org.json.JSONObject;
@@ -32,10 +34,13 @@ public class ProtocolParamServiceImpl implements ProtocolParamService {
3234

3335
@Value("${cardano.rosetta.OFFLINE_MODE}")
3436
private boolean offlineMode;
37+
3538
@Value("${cardano.rosetta.GENESIS_SHELLEY_PATH}")
3639
private String genesisShelleyPath;
40+
3741
@Value("${cardano.rosetta.GENESIS_ALONZO_PATH}")
3842
private String genesisAlonzoPath;
43+
3944
@Value("${cardano.rosetta.GENESIS_CONWAY_PATH}")
4045
private String genesisConwayPath;
4146

@@ -45,26 +50,27 @@ public class ProtocolParamServiceImpl implements ProtocolParamService {
4550

4651
@Override
4752
@Cacheable(value = "protocolParamsCache")
48-
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
53+
@Transactional(readOnly = true)
4954
public ProtocolParams findProtocolParameters() {
50-
if(!offlineMode) {
51-
log.info("Fetching protocol parameters from the indexer");
55+
if (!offlineMode) {
56+
log.info("Fetching protocol parameters from the indexer...");
57+
5258
Optional<LocalProtocolParamsEntity> protocolParams = localProtocolParamsRepository.getLocalProtocolParams();
53-
log.debug("Protocol parameters fetched from the indexer: {} \nand saved in cachedProtocolParams",
54-
protocolParams);
55-
if(protocolParams.isEmpty()) {
59+
log.debug("Protocol parameters fetched from the indexer: {} \nand saved in cachedProtocolParams", protocolParams);
60+
61+
if (protocolParams.isEmpty()) {
5662
ProtocolParamsEntity paramsEntity = epochParamRepository.findLatestProtocolParams();
63+
5764
return mapperProtocolParams.mapProtocolParamsToEntity(paramsEntity);
58-
} else {
59-
return protocolParams.get().getProtocolParams();
6065
}
61-
} else {
62-
return getProtocolParamsFromGenesisFiles();
66+
67+
return protocolParams.get().getProtocolParams();
6368
}
69+
70+
return getProtocolParamsFromGenesisFiles();
6471
}
6572

6673
private ProtocolParams getProtocolParamsFromGenesisFiles() {
67-
6874
ProtocolParams protocolParams = new ProtocolParams();
6975
File genesisShelley = new File(genesisShelleyPath);
7076
if(genesisShelley.exists()) {

0 commit comments

Comments
 (0)