Skip to content

Commit

Permalink
feat: add block height to input request to get network consensus cons…
Browse files Browse the repository at this point in the history
…tants (#4856)

Description
---
In this PR, we refactor the method `get_constants` of `BaseNodeClient` to request a block height input.

Motivation and Context
---
In order to get `ConsensusConstants` values at the DAN layer, it is useful to be able to request the former using a block height, for synchronization purposes. This PR addresses this scenario.

How Has This Been Tested?
---
  • Loading branch information
jorgeantonio21 authored Oct 26, 2022
1 parent df5d78e commit 23b4313
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion applications/tari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ service BaseNode {
// Returns the block timing for the chain heights
rpc GetBlockTiming(HeightRequest) returns (BlockTimingResponse);
// Returns the network Constants
rpc GetConstants(Empty) returns (ConsensusConstants);
rpc GetConstants(BlockHeight) returns (ConsensusConstants);
// Returns Block Sizes
rpc GetBlockSize (BlockGroupRequest) returns (BlockGroupResponse);
// Returns Block Fees
Expand Down
5 changes: 5 additions & 0 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ message Range {
/// An Empty placeholder for endpoints without request parameters
message Empty {}

/// Define an interface for block height
message BlockHeight {
uint64 block_height = 1;
}

// Define the explicit Signature implementation for the Tari base layer. A different signature scheme can be
// employed by redefining this type.
message Signature {
Expand Down
15 changes: 10 additions & 5 deletions applications/tari_base_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,19 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {

async fn get_constants(
&self,
_request: Request<tari_rpc::Empty>,
request: Request<tari_rpc::BlockHeight>,
) -> Result<Response<tari_rpc::ConsensusConstants>, Status> {
debug!(target: LOG_TARGET, "Incoming GRPC request for GetConstants",);
debug!(target: LOG_TARGET, "Sending GetConstants response to client");
// TODO: Switch to request height
Ok(Response::new(
self.network.create_consensus_constants().pop().unwrap().into(),
))

let block_height = request.into_inner().block_height;

let consensus_manager = ConsensusManager::builder(self.network.as_network()).build();
let consensus_constants = consensus_manager.consensus_constants(block_height);

Ok(Response::new(tari_rpc::ConsensusConstants::from(
consensus_constants.clone(),
)))
}

async fn get_block_size(
Expand Down

0 comments on commit 23b4313

Please sign in to comment.