Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusbechwind committed Oct 27, 2023
1 parent e9187f5 commit 732bcee
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## Unreleased changes
- Added support for GRPC V2 `GetBlockCertificates` for retrieving certificates for a block supporting ConcordiumBFT
- Added support for GRPC V2 `GetBlockCertificates` for retrieving certificates for a block supporting ConcordiumBF, i.e. a node with at least version 6.1.

## 5.1.0
- Fixed a regression that made it harder to deserialize transactions from bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ public InvokeInstanceResult invokeInstance(InvokeInstanceRequest request) {

/**
* Retrieves the {@link BlockCertificates} for a given block.
* Note that, if the block being pointed to is not a product of ConcordiumBFT, then a INVALID_ARGUMENT exception will be thrown.
* Note that, if the block being pointed to is not a product of ConcordiumBFT, i.e. created before protocol version 6, then a INVALID_ARGUMENT exception will be thrown.
* If the endpoint is not enabled by the node, then an 'UNIMPLEMENTED' exception will be thrown.
* @param block The block to query
* @return {@link BlockCertificates} of the block.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.concordium.sdk.crypto;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.Arrays;

@EqualsAndHashCode
@ToString(includeFieldNames = false)
public class BLSSignature {

private static final int FIXED_LENGTH = 48;

/**
* The bytes representing the raw aggregate signature. The bytes have a fixed length of {@value BLSSignature#FIXED_LENGTH} bytes.
*/
private final byte[] bytes;

private BLSSignature(final byte[] bytes) {
this.bytes = bytes;
}

@Builder
public static BLSSignature from(final byte[] sig) {
if (! (sig.length == 48)) {throw new IllegalArgumentException("BLSSignature must have fixed length of " + FIXED_LENGTH + " bytes"); }
return new BLSSignature(sig);
}

public byte[] getBytes() {
return Arrays.copyOf(bytes, bytes.length);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.concordium.sdk.responses.blockcertificates;

import com.concordium.sdk.responses.Round;
import lombok.*;

import java.util.Optional;

/**
* Certificates for a block for protocols supporting ConcordiumBFT.
* ConcordiumBFT progresses to a new {@link Round} either via a {@link QuorumCertificate} or a {@link TimeoutCertificate} for a particular round.
*/
@EqualsAndHashCode
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@Getter
@ToString
@EqualsAndHashCode

public class EpochFinalizationEntry {
/**
* The quorum certificate for the finalized block.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.concordium.sdk.responses.blockcertificates;

import com.concordium.sdk.crypto.BLSSignature;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -15,16 +16,18 @@
public class QuorumSignature {

/**
* The bytes representing the raw aggregate signature. The bytes have a fixed length of 48 bytes.
* The aggregate {@link BLSSignature}.
*/
private final byte[] value;
private final BLSSignature value;

/**
* Parses {@link com.concordium.grpc.v2.QuorumSignature} to {@link QuorumSignature}.
* @param sig {@link com.concordium.grpc.v2.QuorumSignature} returned by the GRPC v2 API.
* @return parsed {@link QuorumSignature}.
*/
public static QuorumSignature from(com.concordium.grpc.v2.QuorumSignature sig) {
return QuorumSignature.builder().value(sig.getValue().toByteArray()).build();
return QuorumSignature.builder()
.value(BLSSignature.from(sig.getValue().toByteArray()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.concordium.sdk.responses.blockcertificates;

import com.concordium.sdk.transactions.Hash;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -16,16 +17,16 @@
@ToString
public class SuccessorProof {
/**
* The proof represented as raw bytes. The bytes have a fixed length of 32 bytes.
* The proof.
*/
private final byte[] value;
private final Hash value;

/**
* Parses {@link com.concordium.grpc.v2.SuccessorProof} to {@link SuccessorProof}.
* @param proof {@link com.concordium.grpc.v2.SuccessorProof} returned by the GRCP v2 API.
* @return parsed {@link SuccessorProof}.
*/
public static SuccessorProof from(com.concordium.grpc.v2.SuccessorProof proof) {
return SuccessorProof.builder().value(proof.getValue().toByteArray()).build();
return SuccessorProof.builder().value(Hash.from(proof.getValue().toByteArray())).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.concordium.sdk.responses.blockcertificates;

import com.concordium.sdk.crypto.BLSSignature;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -14,16 +15,18 @@
@EqualsAndHashCode
public class TimeoutSignature {
/**
* The bytes representing the raw aggregate signature. The bytes have a fixed length of 48 bytes.
* The aggregate {@link BLSSignature}.
*/
private final byte[] value;
private final BLSSignature value;

/**
* Parses {@link com.concordium.grpc.v2.TimeoutSignature} to {@link TimeoutSignature}.
* @param sig {@link com.concordium.grpc.v2.TimeoutSignature} returned by the GRCP v2 API.
* @return parsed {@link TimeoutSignature}.
*/
public static TimeoutSignature from(com.concordium.grpc.v2.TimeoutSignature sig) {
return TimeoutSignature.builder().value(sig.getValue().toByteArray()).build();
return TimeoutSignature.builder()
.value(BLSSignature.from(sig.getValue().toByteArray()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.concordium.sdk;

import com.concordium.grpc.v2.*;
import com.concordium.sdk.crypto.BLSSignature;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.responses.BakerId;
import com.concordium.sdk.responses.Epoch;
Expand Down Expand Up @@ -100,7 +101,7 @@ public class ClientV2GetBlockCertificatesTest {
.round(Round.from(ROUND_1))
.epoch(Epoch.from(EPOCH_1))
.aggregateSignature(com.concordium.sdk.responses.blockcertificates.QuorumSignature
.builder().value(QUORUM_SIG_1)
.builder().value(BLSSignature.from(QUORUM_SIG_1))
.build())
.signatories(CLIENT_BAKER_ID_LIST_1)
.build();
Expand All @@ -110,7 +111,7 @@ public class ClientV2GetBlockCertificatesTest {
.round(Round.from(ROUND_2))
.epoch(Epoch.from(EPOCH_2))
.aggregateSignature(com.concordium.sdk.responses.blockcertificates.QuorumSignature
.builder().value(QUORUM_SIG_2)
.builder().value(BLSSignature.from(QUORUM_SIG_2))
.build())
.signatories(CLIENT_BAKER_ID_LIST_2)
.build();
Expand All @@ -122,7 +123,7 @@ public class ClientV2GetBlockCertificatesTest {
.qcRoundsFirstEpoch(CLIENT_FINALIZER_ROUND_LIST_1)
.qcRoundsSecondEpoch(CLIENT_FINALIZER_ROUND_LIST_2)
.aggregateSignature(com.concordium.sdk.responses.blockcertificates.TimeoutSignature
.builder().value(TIMEOUT_SIG_1)
.builder().value(BLSSignature.from(TIMEOUT_SIG_1))
.build())
.build();

Expand All @@ -131,7 +132,7 @@ public class ClientV2GetBlockCertificatesTest {
.finalizedQc(CLIENT_QUORUM_CERTIFICATE_1)
.successorQc(CLIENT_QUORUM_CERTIFICATE_2)
.successorProof(com.concordium.sdk.responses.blockcertificates.SuccessorProof
.builder().value(SUCCESSOR_PROOF_1).build())
.builder().value(Hash.from(SUCCESSOR_PROOF_1)).build())
.build();
// Client Block Certificates
private static final com.concordium.sdk.responses.blockcertificates.BlockCertificates CLIENT_BLOCK_CERT_WITH_QUORUM =
Expand Down

0 comments on commit 732bcee

Please sign in to comment.