From 24af8e2c096f17ddd9742c9afe0dba3a32d610bb Mon Sep 17 00:00:00 2001 From: Mateusz Czeladka Date: Mon, 23 Sep 2024 11:30:50 +0200 Subject: [PATCH 1/2] fix: disable rollback handler for good. --- .../voting/service/yaci/RollbackHandler.java | 252 +++++++++--------- 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/yaci/RollbackHandler.java b/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/yaci/RollbackHandler.java index 3f99ace76..0709958f5 100644 --- a/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/yaci/RollbackHandler.java +++ b/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/yaci/RollbackHandler.java @@ -1,126 +1,126 @@ -package org.cardano.foundation.voting.service.yaci; - -import com.bloxbean.cardano.yaci.core.model.Block; -import com.bloxbean.cardano.yaci.core.model.Era; -import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Point; -import com.bloxbean.cardano.yaci.helper.BlockSync; -import com.bloxbean.cardano.yaci.helper.listener.BlockChainDataListener; -import com.bloxbean.cardano.yaci.helper.model.Transaction; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import lombok.extern.slf4j.Slf4j; -import org.cardano.foundation.voting.client.ChainFollowerClient; -import org.cardano.foundation.voting.domain.ChainNetwork; -import org.cardano.foundation.voting.domain.WellKnownPointWithProtocolMagic; -import org.cardano.foundation.voting.service.merkle_tree.VoteCommitmentService; -import org.cardano.foundation.voting.service.merkle_tree.VoteMerkleProofService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Optional; - -@Component -@Slf4j -@ConditionalOnProperty(prefix = "rollback.handling", value = "enabled", havingValue = "true") -public class RollbackHandler { - - @Value("${cardano.node.ip}") - private String cardanoNodeIp; - - @Value("${cardano.node.port}") - private int cardanoNodePort; - - @Autowired - private ChainNetwork chainNetwork; - - @Autowired - private ChainFollowerClient chainFollowerClient; - - @Autowired - private VoteMerkleProofService voteMerkleProofService; - - @Autowired - private VoteCommitmentService voteCommitmentService; - - @Autowired - private WellKnownPointWithProtocolMagic wellKnownPointWithProtocolMagic; - - private Optional blockSync = Optional.empty(); - - @PostConstruct - public void init() { - log.info("Starting cardano block sync on network: {}...", chainNetwork); - - if (wellKnownPointWithProtocolMagic.wellKnownPointForNetwork().isEmpty()) { - log.warn("Well known point is not known. Skipping rollback handler / sync..."); - return; - } - - var wellKnownPoint = wellKnownPointWithProtocolMagic.wellKnownPointForNetwork().orElseThrow(); - - var protocolMagic = wellKnownPointWithProtocolMagic.protocolMagic(); - var blockSync = startBlockSync(protocolMagic, wellKnownPoint); - - this.blockSync = Optional.of(blockSync); - } - - private BlockSync startBlockSync(long protocolMagic, Point wellKnownPoint) { - var blockSync = new BlockSync(cardanoNodeIp, cardanoNodePort, protocolMagic, wellKnownPoint); - blockSync.startSyncFromTip(new BlockChainDataListener() { - - @Override - public void onBlock(Era era, Block block, List transactions) { - var headerBody = block.getHeader().getHeaderBody(); - - log.info("Block's slot:{}, hash:{}, blockNo:{}", headerBody.getSlot(), headerBody.getBlockHash(), headerBody.getBlockNumber()); - } - - @Override - public void onRollback(Point point) { - var allCommitmentWindowOpenEventsE = chainFollowerClient.findAllCommitmentWindowOpenEvents(); - - if (allCommitmentWindowOpenEventsE.isEmpty()) { - var issue = allCommitmentWindowOpenEventsE.swap().get(); - log.warn("Failed to get eventSummaries issue: {}, will try again in some time (on next rollback)...", issue.toString()); - - return; - } - - var allCommitmentWindowOpenEvents = allCommitmentWindowOpenEventsE.get(); - - if (allCommitmentWindowOpenEvents.isEmpty()) { - log.info("No commitment window open events found. Skipping rollback handler..."); - - return; - } - - var absoluteSlot = point.getSlot(); - - for (var eventSummary : allCommitmentWindowOpenEvents) { - String eventId = eventSummary.id(); - - log.info("Processing rollback for eventId: {}, absoluteSlot: {}", eventId, absoluteSlot); - - int updatedVoteProofs = voteMerkleProofService.softDeleteAllProofsAfterSlot(eventId, absoluteSlot); - - log.info("Soft deleted {} vote proofs after slot: {} for eventId: {}", updatedVoteProofs, absoluteSlot, eventId); - } - - } - - }); - - return blockSync; - } - - @PreDestroy - public void destroy() { - log.info("Stopping block sync..."); - - blockSync.ifPresent(BlockSync::stop); - } - -} +//package org.cardano.foundation.voting.service.yaci; +// +//import com.bloxbean.cardano.yaci.core.model.Block; +//import com.bloxbean.cardano.yaci.core.model.Era; +//import com.bloxbean.cardano.yaci.core.protocol.chainsync.messages.Point; +//import com.bloxbean.cardano.yaci.helper.BlockSync; +//import com.bloxbean.cardano.yaci.helper.listener.BlockChainDataListener; +//import com.bloxbean.cardano.yaci.helper.model.Transaction; +//import jakarta.annotation.PostConstruct; +//import jakarta.annotation.PreDestroy; +//import lombok.extern.slf4j.Slf4j; +//import org.cardano.foundation.voting.client.ChainFollowerClient; +//import org.cardano.foundation.voting.domain.ChainNetwork; +//import org.cardano.foundation.voting.domain.WellKnownPointWithProtocolMagic; +//import org.cardano.foundation.voting.service.merkle_tree.VoteCommitmentService; +//import org.cardano.foundation.voting.service.merkle_tree.VoteMerkleProofService; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +//import org.springframework.stereotype.Component; +// +//import java.util.List; +//import java.util.Optional; +// +//@Component +//@Slf4j +//@ConditionalOnProperty(prefix = "rollback.handling", value = "enabled", havingValue = "true") +//public class RollbackHandler { +// +// @Value("${cardano.node.ip}") +// private String cardanoNodeIp; +// +// @Value("${cardano.node.port}") +// private int cardanoNodePort; +// +// @Autowired +// private ChainNetwork chainNetwork; +// +// @Autowired +// private ChainFollowerClient chainFollowerClient; +// +// @Autowired +// private VoteMerkleProofService voteMerkleProofService; +// +// @Autowired +// private VoteCommitmentService voteCommitmentService; +// +// @Autowired +// private WellKnownPointWithProtocolMagic wellKnownPointWithProtocolMagic; +// +// private Optional blockSync = Optional.empty(); +// +// @PostConstruct +// public void init() { +// log.info("Starting cardano block sync on network: {}...", chainNetwork); +// +// if (wellKnownPointWithProtocolMagic.wellKnownPointForNetwork().isEmpty()) { +// log.warn("Well known point is not known. Skipping rollback handler / sync..."); +// return; +// } +// +// var wellKnownPoint = wellKnownPointWithProtocolMagic.wellKnownPointForNetwork().orElseThrow(); +// +// var protocolMagic = wellKnownPointWithProtocolMagic.protocolMagic(); +// var blockSync = startBlockSync(protocolMagic, wellKnownPoint); +// +// this.blockSync = Optional.of(blockSync); +// } +// +// private BlockSync startBlockSync(long protocolMagic, Point wellKnownPoint) { +// var blockSync = new BlockSync(cardanoNodeIp, cardanoNodePort, protocolMagic, wellKnownPoint); +// blockSync.startSyncFromTip(new BlockChainDataListener() { +// +// @Override +// public void onBlock(Era era, Block block, List transactions) { +// var headerBody = block.getHeader().getHeaderBody(); +// +// log.info("Block's slot:{}, hash:{}, blockNo:{}", headerBody.getSlot(), headerBody.getBlockHash(), headerBody.getBlockNumber()); +// } +// +// @Override +// public void onRollback(Point point) { +// var allCommitmentWindowOpenEventsE = chainFollowerClient.findAllCommitmentWindowOpenEvents(); +// +// if (allCommitmentWindowOpenEventsE.isEmpty()) { +// var issue = allCommitmentWindowOpenEventsE.swap().get(); +// log.warn("Failed to get eventSummaries issue: {}, will try again in some time (on next rollback)...", issue.toString()); +// +// return; +// } +// +// var allCommitmentWindowOpenEvents = allCommitmentWindowOpenEventsE.get(); +// +// if (allCommitmentWindowOpenEvents.isEmpty()) { +// log.info("No commitment window open events found. Skipping rollback handler..."); +// +// return; +// } +// +// var absoluteSlot = point.getSlot(); +// +// for (var eventSummary : allCommitmentWindowOpenEvents) { +// String eventId = eventSummary.id(); +// +// log.info("Processing rollback for eventId: {}, absoluteSlot: {}", eventId, absoluteSlot); +// +// int updatedVoteProofs = voteMerkleProofService.softDeleteAllProofsAfterSlot(eventId, absoluteSlot); +// +// log.info("Soft deleted {} vote proofs after slot: {} for eventId: {}", updatedVoteProofs, absoluteSlot, eventId); +// } +// +// } +// +// }); +// +// return blockSync; +// } +// +// @PreDestroy +// public void destroy() { +// log.info("Stopping block sync..."); +// +// blockSync.ifPresent(BlockSync::stop); +// } +// +//} From 94585c2412d76959f1dc72c242c07d9142c73ba1 Mon Sep 17 00:00:00 2001 From: "Roberto C. Morano" Date: Thu, 19 Sep 2024 10:51:27 +0200 Subject: [PATCH 2/2] feat(vote-commitment): added blockfrost auth header for submit api --- .../foundation/voting/config/BlockchainDataConfig.java | 5 +++-- ...rdanoSubmitApiBlockchainTransactionSubmissionService.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/config/BlockchainDataConfig.java b/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/config/BlockchainDataConfig.java index 9208d633f..e53b741d4 100644 --- a/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/config/BlockchainDataConfig.java +++ b/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/config/BlockchainDataConfig.java @@ -29,8 +29,9 @@ public BlockchainTransactionSubmissionService backendServiceTransactionSubmissio @Bean @Profile( value = { "prod", "dev--preprod" } ) public BlockchainTransactionSubmissionService cardanoSummitTransactionSubmissionService(HttpClient httpClient, - @Value("${cardano.tx.submit.api.url}") String cardanoSubmitApiUrl) { - return new CardanoSubmitApiBlockchainTransactionSubmissionService(cardanoSubmitApiUrl, httpClient); + @Value("${cardano.tx.submit.api.url}") String cardanoSubmitApiUrl, + @Value("${blockfrost.api.key}") String blockfrostApiKey) { + return new CardanoSubmitApiBlockchainTransactionSubmissionService(cardanoSubmitApiUrl, httpClient, blockfrostApiKey); } } diff --git a/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/blockchain_state/cardano_submit_api/CardanoSubmitApiBlockchainTransactionSubmissionService.java b/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/blockchain_state/cardano_submit_api/CardanoSubmitApiBlockchainTransactionSubmissionService.java index f85d00c76..314d5cd2e 100644 --- a/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/blockchain_state/cardano_submit_api/CardanoSubmitApiBlockchainTransactionSubmissionService.java +++ b/backend-services/vote-commitment-app/src/main/java/org/cardano/foundation/voting/service/blockchain_state/cardano_submit_api/CardanoSubmitApiBlockchainTransactionSubmissionService.java @@ -19,6 +19,8 @@ public class CardanoSubmitApiBlockchainTransactionSubmissionService implements B private final HttpClient httpClient; + private final String blockfrostApiKey; + @Override @SneakyThrows public String submitTransaction(byte[] txData) { @@ -26,6 +28,7 @@ public String submitTransaction(byte[] txData) { .uri(URI.create(cardanoSubmitApiUrl)) .POST(HttpRequest.BodyPublishers.ofByteArray(txData)) .header("Content-Type", "application/cbor") + .header("project_id", blockfrostApiKey) .build(); var r = httpClient.send(txTransactionSubmitPostRequest, HttpResponse.BodyHandlers.ofString());