Skip to content

Commit

Permalink
feat: propagation supports is not recommended without open db transac…
Browse files Browse the repository at this point in the history
…tion and can lead to connection leak issues.
  • Loading branch information
Mateusz Czeladka committed Mar 5, 2025
1 parent dc55d83 commit 28e36b2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.openapitools.client.model.Currency;

Expand All @@ -24,7 +23,7 @@
@Slf4j
@RequiredArgsConstructor
@Component
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Transactional(readOnly = true)
public class LedgerAccountServiceImpl implements LedgerAccountService {

private final AddressUtxoRepository addressUtxoRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class BlockApiImpl implements BlockApi {

@Override
public ResponseEntity<BlockResponse> block(@RequestBody BlockRequest blockRequest) {
if(offlineMode) {
if (offlineMode) {
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(blockRequest.getNetworkIdentifier());
Expand All @@ -51,7 +51,7 @@ public ResponseEntity<BlockResponse> block(@RequestBody BlockRequest blockReques
@Override
public ResponseEntity<BlockTransactionResponse> blockTransaction(
@RequestBody BlockTransactionRequest blockReq) {
if(offlineMode) {
if (offlineMode) {
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(blockReq.getNetworkIdentifier());
Expand All @@ -63,6 +63,6 @@ public ResponseEntity<BlockTransactionResponse> blockTransaction(
BlockTx blockTx = blockService.getBlockTransaction(blockId, blockHash, txHash);

return ResponseEntity.ok(mapper.mapToBlockTransactionResponse(blockTx));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import org.cardanofoundation.rosetta.api.block.model.domain.Block;
Expand All @@ -17,7 +16,7 @@
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Transactional(readOnly = true)
public class BlockServiceImpl implements BlockService {

private final LedgerBlockService ledgerBlockService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang3.ObjectUtils;

Expand Down Expand Up @@ -49,11 +48,9 @@
@Slf4j
@RequiredArgsConstructor
@Component
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Transactional(readOnly = true)
public class LedgerBlockServiceImpl implements LedgerBlockService {

private final ProtocolParamService protocolParamService;

private final BlockRepository blockRepository;
private final TxRepository txRepository;
private final StakeRegistrationRepository stakeRegistrationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.openapitools.client.model.Operator;

Expand All @@ -26,7 +25,7 @@
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Transactional(readOnly = true)
public class LedgerSearchServiceImpl implements LedgerSearchService {

private final TxRepository txRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang3.ObjectUtils;
import org.openapitools.client.model.AccountIdentifier;
Expand All @@ -25,7 +24,7 @@
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Transactional(readOnly = true)
public class SearchServiceImpl implements SearchService {

private final BlockMapper blockMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.cardanofoundation.rosetta.common.services;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
Expand All @@ -13,7 +16,6 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
Expand All @@ -32,10 +34,13 @@ public class ProtocolParamServiceImpl implements ProtocolParamService {

@Value("${cardano.rosetta.OFFLINE_MODE}")
private boolean offlineMode;

@Value("${cardano.rosetta.GENESIS_SHELLEY_PATH}")
private String genesisShelleyPath;

@Value("${cardano.rosetta.GENESIS_ALONZO_PATH}")
private String genesisAlonzoPath;

@Value("${cardano.rosetta.GENESIS_CONWAY_PATH}")
private String genesisConwayPath;

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

@Override
@Cacheable(value = "protocolParamsCache")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
@Transactional(readOnly = true)
public ProtocolParams findProtocolParameters() {
if(!offlineMode) {
log.info("Fetching protocol parameters from the indexer");
if (!offlineMode) {
log.info("Fetching protocol parameters from the indexer...");

Optional<LocalProtocolParamsEntity> protocolParams = localProtocolParamsRepository.getLocalProtocolParams();
log.debug("Protocol parameters fetched from the indexer: {} \nand saved in cachedProtocolParams",
protocolParams);
if(protocolParams.isEmpty()) {
log.debug("Protocol parameters fetched from the indexer: {} \nand saved in cachedProtocolParams", protocolParams);

if (protocolParams.isEmpty()) {
ProtocolParamsEntity paramsEntity = epochParamRepository.findLatestProtocolParams();

return mapperProtocolParams.mapProtocolParamsToEntity(paramsEntity);
} else {
return protocolParams.get().getProtocolParams();
}
} else {
return getProtocolParamsFromGenesisFiles();

return protocolParams.get().getProtocolParams();
}

return getProtocolParamsFromGenesisFiles();
}

private ProtocolParams getProtocolParamsFromGenesisFiles() {

ProtocolParams protocolParams = new ProtocolParams();
File genesisShelley = new File(genesisShelleyPath);
if(genesisShelley.exists()) {
Expand Down

0 comments on commit 28e36b2

Please sign in to comment.