Skip to content

Commit

Permalink
Merge pull request #597 from cardano-foundation/develop
Browse files Browse the repository at this point in the history
chore(release): merge summit2024 changes to main to make a new release
  • Loading branch information
rcmorano authored Nov 7, 2024
2 parents 31ab0e9 + 58d25c2 commit 6b99ce8
Show file tree
Hide file tree
Showing 115 changed files with 5,853 additions and 2,289 deletions.
34 changes: 23 additions & 11 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ main, develop ]
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
- '[0-9]+.[0-9]+.[0-9]+'
pull_request:
types: [ opened, synchronize ]
workflow_dispatch:
Expand Down Expand Up @@ -53,17 +54,6 @@ jobs:
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}"
- name: Dispatch successful build event to private repo
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-dispatch-event@main
with:
EVENT_TYPE: "${{ github.event_name }}-${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }}-${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }}"
GITHUB_TOKEN: ${{ secrets.PRIVATE_REPO_PAT }}
GITHUB_REPO: ${{ secrets.PRIVATE_REPO }}
TRIGGERING_EVENT: ${{ github.event_name }}
TRIGGERING_REF: ${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }}
TRIGGERING_BRANCH: ${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }}
GIT_SHORT_COMMIT: ${{ steps.cf-gha-baseline.outputs.GIT_SHORT_COMMIT }}

ui-summit-2024:
runs-on: ${{ fromJson(vars.RUNS_ON) }}
env:
Expand All @@ -88,10 +78,31 @@ jobs:
- name: 🌍 earthly (docker build and push)
run: |
earthly +${{ env.APP_NAME }} \
--VITE_VERSION=${{ steps.cf-gha-baseline.outputs.GIT_SHORT_COMMIT }} \
--PUSH=${DOCKER_PUSH} \
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}"
dispatch-build-success-event:
runs-on: ${{ fromJson(vars.RUNS_ON) }}
needs:
- ui-summit-2024
steps:
- name: Checkout
uses: actions/checkout@v4

- name: ⛮ cf-gha-baseline
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main
id: cf-gha-baseline
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRIVATE_DOCKER_REGISTRY_URL: ${{ env.PRIVATE_DOCKER_REGISTRY_URL }}
PRIVATE_DOCKER_REGISTRY_USER: ${{ env.PRIVATE_DOCKER_REGISTRY_USER }}
PRIVATE_DOCKER_REGISTRY_PASS: ${{ env.PRIVATE_DOCKER_REGISTRY_PASS }}
HUB_DOCKER_COM_USER: ${{ secrets.HUB_DOCKER_COM_USER }}
HUB_DOCKER_COM_PASS: ${{ secrets.HUB_DOCKER_COM_PASS }}
DOCKER_REGISTRIES: "${{ secrets.DOCKER_REGISTRIES }}"

- name: Dispatch successful build event to private repo
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-dispatch-event@main
with:
Expand All @@ -101,4 +112,5 @@ jobs:
TRIGGERING_EVENT: ${{ github.event_name }}
TRIGGERING_REF: ${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }}
TRIGGERING_BRANCH: ${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }}
TRIGGERING_GHRUNID: ${{ github.run_id }}
GIT_SHORT_COMMIT: ${{ steps.cf-gha-baseline.outputs.GIT_SHORT_COMMIT }}
3 changes: 2 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ user-verification-service:

ui-summit-2024:
ARG EARTHLY_TARGET_NAME
ARG VITE_VERSION=0.1.0
LET DOCKER_IMAGE_NAME=${DOCKER_IMAGES_PREFIX}-${EARTHLY_TARGET_NAME}

WAIT
FROM DOCKERFILE ./ui/summit-2024
FROM DOCKERFILE --build-arg VITE_VERSION=${VITE_VERSION} ./ui/summit-2024
END
WAIT
SAVE IMAGE ${DOCKER_IMAGE_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.cardano.foundation.voting.repository.VoteRepository;
import org.cardanofoundation.cip30.CIP30Verifier;

import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.function.Function;

Expand All @@ -26,12 +27,13 @@ public static Function<VoteRepository.CompactVote, byte[]> createSerialiserFunct
case KERI -> {
val message = vote.getSignature().getBytes();
val payload = vote.getPayload().map(String::getBytes).orElse(new byte[0]);
val totalLength = message.length + payload.length;

val result = new byte[message.length + payload.length];
val buffer = ByteBuffer.allocate(totalLength);
buffer.put(message);
buffer.put(payload);

System.arraycopy(message, 0, result, 0, payload.length);

yield blake2bHash256(result);
yield blake2bHash256(buffer.array());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public class CardanoSubmitApiBlockchainTransactionSubmissionService implements B

private final HttpClient httpClient;

private final String blockfrostApiKey;

@Override
@SneakyThrows
public String submitTransaction(byte[] txData) {
var txTransactionSubmitPostRequest = HttpRequest.newBuilder()
.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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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> 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<Transaction> 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> 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<Transaction> 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);
// }
//
//}
Loading

0 comments on commit 6b99ce8

Please sign in to comment.