Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(www): adding change proposer round and value to consensus info votes #892

Merged
merged 4 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions types/vote/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ func (v *Vote) Verify(pubKey *bls.PublicKey) error {
return pubKey.Verify(v.SignBytes(), v.Signature())
}

func (v *Vote) IsCPVote() bool {
if v.data.Type == VoteTypeCPPreVote ||
v.data.Type == VoteTypeCPMainVote ||
v.data.Type == VoteTypeCPDecided {
return true
}
return false
}

// BasicCheck performs a basic check on the vote.
func (v *Vote) BasicCheck() error {
if !v.data.Type.IsValid() {
Expand All @@ -209,9 +218,7 @@ func (v *Vote) BasicCheck() error {
Reason: "invalid round",
}
}
if v.data.Type == VoteTypeCPPreVote ||
v.data.Type == VoteTypeCPMainVote ||
v.data.Type == VoteTypeCPDecided {
if v.IsCPVote() {
if v.data.CPVote == nil {
return errors.Errorf(errors.ErrInvalidVote, "should have cp data")
}
Expand Down
9 changes: 9 additions & 0 deletions www/grpc/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,19 @@
}

func voteToProto(v *vote.Vote) *pactus.VoteInfo {
cpRound := int32(0)
cpValue := int32(0)
if v.IsCPVote() {
cpRound = int32(v.CPRound())
cpValue = int32(v.CPValue())

Check warning on line 267 in www/grpc/blockchain.go

View check run for this annotation

Codecov / codecov/patch

www/grpc/blockchain.go#L266-L267

Added lines #L266 - L267 were not covered by tests
}

return &pactus.VoteInfo{
Type: pactus.VoteType(v.Type()),
Voter: v.Signer().String(),
BlockHash: v.BlockHash().Bytes(),
Round: int32(v.Round()),
CpRound: cpRound,
CpValue: cpValue,
}
}
3 changes: 3 additions & 0 deletions www/grpc/buf/grpc-gateway.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ http:
- selector: pactus.Blockchain.GetBlockchainInfo
get: "/v1/blockchain/info"

- selector: pactus.Blockchain.GetConsensusInfo
get: "/v1/blockchain/consensusInfo"

- selector: pactus.Blockchain.GetPublicKey
get: "/v1/blockchain/public_keys/address/{address}"

Expand Down
28 changes: 28 additions & 0 deletions www/grpc/gen/dart/blockchain.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,8 @@ class VoteInfo extends $pb.GeneratedMessage {
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'voter')
..a<$core.List<$core.int>>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'blockHash', $pb.PbFieldType.OY)
..a<$core.int>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'round', $pb.PbFieldType.O3)
..a<$core.int>(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'cpRound', $pb.PbFieldType.O3)
..a<$core.int>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'cpValue', $pb.PbFieldType.O3)
..hasRequiredFields = false
;

Expand All @@ -1493,6 +1495,8 @@ class VoteInfo extends $pb.GeneratedMessage {
$core.String? voter,
$core.List<$core.int>? blockHash,
$core.int? round,
$core.int? cpRound,
$core.int? cpValue,
}) {
final _result = create();
if (type != null) {
Expand All @@ -1507,6 +1511,12 @@ class VoteInfo extends $pb.GeneratedMessage {
if (round != null) {
_result.round = round;
}
if (cpRound != null) {
_result.cpRound = cpRound;
}
if (cpValue != null) {
_result.cpValue = cpValue;
}
return _result;
}
factory VoteInfo.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
Expand Down Expand Up @@ -1565,6 +1575,24 @@ class VoteInfo extends $pb.GeneratedMessage {
$core.bool hasRound() => $_has(3);
@$pb.TagNumber(4)
void clearRound() => clearField(4);

@$pb.TagNumber(5)
$core.int get cpRound => $_getIZ(4);
@$pb.TagNumber(5)
set cpRound($core.int v) { $_setSignedInt32(4, v); }
@$pb.TagNumber(5)
$core.bool hasCpRound() => $_has(4);
@$pb.TagNumber(5)
void clearCpRound() => clearField(5);

@$pb.TagNumber(6)
$core.int get cpValue => $_getIZ(5);
@$pb.TagNumber(6)
set cpValue($core.int v) { $_setSignedInt32(5, v); }
@$pb.TagNumber(6)
$core.bool hasCpValue() => $_has(5);
@$pb.TagNumber(6)
void clearCpValue() => clearField(6);
}

class ConsensusInfo extends $pb.GeneratedMessage {
Expand Down
4 changes: 3 additions & 1 deletion www/grpc/gen/dart/blockchain.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ const VoteInfo$json = const {
const {'1': 'voter', '3': 2, '4': 1, '5': 9, '10': 'voter'},
const {'1': 'block_hash', '3': 3, '4': 1, '5': 12, '10': 'blockHash'},
const {'1': 'round', '3': 4, '4': 1, '5': 5, '10': 'round'},
const {'1': 'cp_round', '3': 5, '4': 1, '5': 5, '10': 'cpRound'},
const {'1': 'cp_value', '3': 6, '4': 1, '5': 5, '10': 'cpValue'},
],
};

/// Descriptor for `VoteInfo`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List voteInfoDescriptor = $convert.base64Decode('CghWb3RlSW5mbxIkCgR0eXBlGAEgASgOMhAucGFjdHVzLlZvdGVUeXBlUgR0eXBlEhQKBXZvdGVyGAIgASgJUgV2b3RlchIdCgpibG9ja19oYXNoGAMgASgMUglibG9ja0hhc2gSFAoFcm91bmQYBCABKAVSBXJvdW5k');
final $typed_data.Uint8List voteInfoDescriptor = $convert.base64Decode('CghWb3RlSW5mbxIkCgR0eXBlGAEgASgOMhAucGFjdHVzLlZvdGVUeXBlUgR0eXBlEhQKBXZvdGVyGAIgASgJUgV2b3RlchIdCgpibG9ja19oYXNoGAMgASgMUglibG9ja0hhc2gSFAoFcm91bmQYBCABKAVSBXJvdW5kEhkKCGNwX3JvdW5kGAUgASgFUgdjcFJvdW5kEhkKCGNwX3ZhbHVlGAYgASgFUgdjcFZhbHVl');
@$core.Deprecated('Use consensusInfoDescriptor instead')
const ConsensusInfo$json = const {
'1': 'ConsensusInfo',
Expand Down
Loading
Loading