Skip to content

Commit

Permalink
feat(grpc): add Proposal to ConsensusInfo API (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxipaz authored Aug 23, 2024
1 parent 0ec6670 commit 4e7052d
Show file tree
Hide file tree
Showing 14 changed files with 2,484 additions and 396 deletions.
26 changes: 25 additions & 1 deletion www/grpc/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (s *blockchainServer) GetConsensusInfo(_ context.Context,
_ *pactus.GetConsensusInfoRequest,
) (*pactus.GetConsensusInfoResponse, error) {
instances := make([]*pactus.ConsensusInfo, 0)
var proposal *pactus.Proposal

for _, cons := range s.consMgr.Instances() {
height, round := cons.HeightRound()
votes := cons.AllVotes()
Expand All @@ -67,9 +69,31 @@ func (s *blockchainServer) GetConsensusInfo(_ context.Context,
Round: int32(round),
Votes: voteInfos,
})

if proposal == nil && cons.Proposal() != nil {
// All instances have the same proposal, so we just need to fill proposal once.
p := cons.Proposal()

var blockData string
if p.Block() != nil {
data, err := p.Block().Bytes()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

blockData = string(data)
}

proposal = &pactus.Proposal{
Height: p.Height(),
Round: int32(p.Round()),
BlockData: blockData,
SignatureData: string(p.Signature().Bytes()),
}
}
}

return &pactus.GetConsensusInfoResponse{Instances: instances}, nil
return &pactus.GetConsensusInfoResponse{Instances: instances, Proposal: proposal}, nil
}

func (s *blockchainServer) GetBlockHash(_ context.Context,
Expand Down
105 changes: 105 additions & 0 deletions www/grpc/gen/dart/blockchain.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1027,17 +1027,22 @@ class GetConsensusInfoRequest extends $pb.GeneratedMessage {
class GetConsensusInfoResponse extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'GetConsensusInfoResponse', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..pc<ConsensusInfo>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'instances', $pb.PbFieldType.PM, subBuilder: ConsensusInfo.create)
..aOM<Proposal>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'proposal', subBuilder: Proposal.create)
..hasRequiredFields = false
;

GetConsensusInfoResponse._() : super();
factory GetConsensusInfoResponse({
$core.Iterable<ConsensusInfo>? instances,
Proposal? proposal,
}) {
final _result = create();
if (instances != null) {
_result.instances.addAll(instances);
}
if (proposal != null) {
_result.proposal = proposal;
}
return _result;
}
factory GetConsensusInfoResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
Expand All @@ -1063,6 +1068,17 @@ class GetConsensusInfoResponse extends $pb.GeneratedMessage {

@$pb.TagNumber(1)
$core.List<ConsensusInfo> get instances => $_getList(0);

@$pb.TagNumber(6)
Proposal get proposal => $_getN(1);
@$pb.TagNumber(6)
set proposal(Proposal v) { setField(6, v); }
@$pb.TagNumber(6)
$core.bool hasProposal() => $_has(1);
@$pb.TagNumber(6)
void clearProposal() => clearField(6);
@$pb.TagNumber(6)
Proposal ensureProposal() => $_ensure(1);
}

class GetTxPoolContentRequest extends $pb.GeneratedMessage {
Expand Down Expand Up @@ -1837,6 +1853,95 @@ class ConsensusInfo extends $pb.GeneratedMessage {
$core.List<VoteInfo> get votes => $_getList(4);
}

class Proposal extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Proposal', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..a<$core.int>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'height', $pb.PbFieldType.OU3)
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'round', $pb.PbFieldType.O3)
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'blockData')
..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'signatureData')
..hasRequiredFields = false
;

Proposal._() : super();
factory Proposal({
$core.int? height,
$core.int? round,
$core.String? blockData,
$core.String? signatureData,
}) {
final _result = create();
if (height != null) {
_result.height = height;
}
if (round != null) {
_result.round = round;
}
if (blockData != null) {
_result.blockData = blockData;
}
if (signatureData != null) {
_result.signatureData = signatureData;
}
return _result;
}
factory Proposal.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory Proposal.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
Proposal clone() => Proposal()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
Proposal copyWith(void Function(Proposal) updates) => super.copyWith((message) => updates(message as Proposal)) as Proposal; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static Proposal create() => Proposal._();
Proposal createEmptyInstance() => create();
static $pb.PbList<Proposal> createRepeated() => $pb.PbList<Proposal>();
@$core.pragma('dart2js:noInline')
static Proposal getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<Proposal>(create);
static Proposal? _defaultInstance;

@$pb.TagNumber(1)
$core.int get height => $_getIZ(0);
@$pb.TagNumber(1)
set height($core.int v) { $_setUnsignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasHeight() => $_has(0);
@$pb.TagNumber(1)
void clearHeight() => clearField(1);

@$pb.TagNumber(2)
$core.int get round => $_getIZ(1);
@$pb.TagNumber(2)
set round($core.int v) { $_setSignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasRound() => $_has(1);
@$pb.TagNumber(2)
void clearRound() => clearField(2);

@$pb.TagNumber(3)
$core.String get blockData => $_getSZ(2);
@$pb.TagNumber(3)
set blockData($core.String v) { $_setString(2, v); }
@$pb.TagNumber(3)
$core.bool hasBlockData() => $_has(2);
@$pb.TagNumber(3)
void clearBlockData() => clearField(3);

@$pb.TagNumber(4)
$core.String get signatureData => $_getSZ(3);
@$pb.TagNumber(4)
set signatureData($core.String v) { $_setString(3, v); }
@$pb.TagNumber(4)
$core.bool hasSignatureData() => $_has(3);
@$pb.TagNumber(4)
void clearSignatureData() => clearField(4);
}

class BlockchainApi {
$pb.RpcClient _client;
BlockchainApi(this._client);
Expand Down
17 changes: 16 additions & 1 deletion www/grpc/gen/dart/blockchain.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@ const GetConsensusInfoResponse$json = const {
'1': 'GetConsensusInfoResponse',
'2': const [
const {'1': 'instances', '3': 1, '4': 3, '5': 11, '6': '.pactus.ConsensusInfo', '10': 'instances'},
const {'1': 'proposal', '3': 6, '4': 1, '5': 11, '6': '.pactus.Proposal', '10': 'proposal'},
],
};

/// Descriptor for `GetConsensusInfoResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getConsensusInfoResponseDescriptor = $convert.base64Decode('ChhHZXRDb25zZW5zdXNJbmZvUmVzcG9uc2USMwoJaW5zdGFuY2VzGAEgAygLMhUucGFjdHVzLkNvbnNlbnN1c0luZm9SCWluc3RhbmNlcw==');
final $typed_data.Uint8List getConsensusInfoResponseDescriptor = $convert.base64Decode('ChhHZXRDb25zZW5zdXNJbmZvUmVzcG9uc2USMwoJaW5zdGFuY2VzGAEgAygLMhUucGFjdHVzLkNvbnNlbnN1c0luZm9SCWluc3RhbmNlcxIsCghwcm9wb3NhbBgGIAEoCzIQLnBhY3R1cy5Qcm9wb3NhbFIIcHJvcG9zYWw=');
@$core.Deprecated('Use getTxPoolContentRequestDescriptor instead')
const GetTxPoolContentRequest$json = const {
'1': 'GetTxPoolContentRequest',
Expand Down Expand Up @@ -342,6 +343,19 @@ const ConsensusInfo$json = const {

/// Descriptor for `ConsensusInfo`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List consensusInfoDescriptor = $convert.base64Decode('Cg1Db25zZW5zdXNJbmZvEhgKB2FkZHJlc3MYASABKAlSB2FkZHJlc3MSFgoGYWN0aXZlGAIgASgIUgZhY3RpdmUSFgoGaGVpZ2h0GAMgASgNUgZoZWlnaHQSFAoFcm91bmQYBCABKAVSBXJvdW5kEiYKBXZvdGVzGAUgAygLMhAucGFjdHVzLlZvdGVJbmZvUgV2b3Rlcw==');
@$core.Deprecated('Use proposalDescriptor instead')
const Proposal$json = const {
'1': 'Proposal',
'2': const [
const {'1': 'height', '3': 1, '4': 1, '5': 13, '10': 'height'},
const {'1': 'round', '3': 2, '4': 1, '5': 5, '10': 'round'},
const {'1': 'block_data', '3': 3, '4': 1, '5': 9, '10': 'blockData'},
const {'1': 'signature_data', '3': 4, '4': 1, '5': 9, '10': 'signatureData'},
],
};

/// Descriptor for `Proposal`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List proposalDescriptor = $convert.base64Decode('CghQcm9wb3NhbBIWCgZoZWlnaHQYASABKA1SBmhlaWdodBIUCgVyb3VuZBgCIAEoBVIFcm91bmQSHQoKYmxvY2tfZGF0YRgDIAEoCVIJYmxvY2tEYXRhEiUKDnNpZ25hdHVyZV9kYXRhGAQgASgJUg1zaWduYXR1cmVEYXRh');
const $core.Map<$core.String, $core.dynamic> BlockchainServiceBase$json = const {
'1': 'Blockchain',
'2': const [
Expand Down Expand Up @@ -382,6 +396,7 @@ const $core.Map<$core.String, $core.Map<$core.String, $core.dynamic>> Blockchain
'.pactus.GetConsensusInfoResponse': GetConsensusInfoResponse$json,
'.pactus.ConsensusInfo': ConsensusInfo$json,
'.pactus.VoteInfo': VoteInfo$json,
'.pactus.Proposal': Proposal$json,
'.pactus.GetAccountRequest': GetAccountRequest$json,
'.pactus.GetAccountResponse': GetAccountResponse$json,
'.pactus.AccountInfo': AccountInfo$json,
Expand Down
37 changes: 36 additions & 1 deletion www/grpc/gen/docs/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,42 @@ committee.
The change-proposer value of the vote.
</td>
</tr>
</tbody>
<tr>
<td class="fw-bold">proposal</td>
<td> Proposal</td>
<td>
The proposal of the consensus info.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.height</td>
<td> uint32</td>
<td>
The height of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.round</td>
<td> int32</td>
<td>
The round of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.block_data</td>
<td> string</td>
<td>
The block data of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.signature_data</td>
<td> string</td>
<td>
The signature data of the proposal.
</td>
</tr>
</tbody>
</table>

### GetAccount <span id="pactus.Blockchain.GetAccount" class="rpc-badge"></span>
Expand Down
37 changes: 36 additions & 1 deletion www/grpc/gen/docs/json-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,42 @@ committee.
The change-proposer value of the vote.
</td>
</tr>
</tbody>
<tr>
<td class="fw-bold">proposal</td>
<td> object</td>
<td>
The proposal of the consensus info.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.height</td>
<td> numeric</td>
<td>
The height of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.round</td>
<td> numeric</td>
<td>
The round of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.block_data</td>
<td> string</td>
<td>
The block data of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.signature_data</td>
<td> string</td>
<td>
The signature data of the proposal.
</td>
</tr>
</tbody>
</table>

### pactus.blockchain.get_account <span id="pactus.blockchain.get_account" class="rpc-badge"></span>
Expand Down
Loading

0 comments on commit 4e7052d

Please sign in to comment.