Skip to content

Commit

Permalink
feat: add coinbase extra info to grpc (#6561)
Browse files Browse the repository at this point in the history
Description
---
Add coinbase extra to grpc
Replaces PR: #6514

---------

Co-authored-by: stringhandler <stringhandler@protonmail.com>
  • Loading branch information
SWvheerden and stringhandler authored Sep 13, 2024
1 parent a22ae35 commit d48a15c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions applications/minotari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ message NetworkDifficultyResponse {
uint64 pow_algo = 5;
uint64 sha3x_estimated_hash_rate = 6;
uint64 randomx_estimated_hash_rate = 7;
uint64 num_coinbases = 8;
repeated bytes coinbase_extras = 9;
}

// A generic single value response for a specific height
Expand Down
23 changes: 23 additions & 0 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,27 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
let randomx_estimated_hash_rate = randomx_hash_rate_moving_average.average();
let estimated_hash_rate = sha3x_estimated_hash_rate.saturating_add(randomx_estimated_hash_rate);

let block = match handler.get_block(current_height, true).await {
Ok(block) => block,
Err(err) => {
warn!(target: LOG_TARGET, "Base node service error: {:?}", err,);
let _network_difficulty_response = tx.send(Err(obscure_error_if_true(
report_error_flag,
Status::internal(format!("Error fetching block at height {}", current_height)),
)));
return;
},
};
if block.is_none() {
let _network_difficulty_response = tx.send(Err(obscure_error_if_true(
report_error_flag,
Status::internal(format!("Block not found at height {}", current_height)),
)));
return;
}
let block = block.unwrap();
let coinbases = block.block().body.get_coinbase_outputs();

let difficulty = tari_rpc::NetworkDifficultyResponse {
difficulty: current_difficulty.as_u64(),
estimated_hash_rate,
Expand All @@ -321,6 +342,8 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
height: current_height,
timestamp: current_timestamp.as_u64(),
pow_algo: pow_algo.as_u64(),
num_coinbases: coinbases.len() as u64,
coinbase_extras: coinbases.iter().map(|c| c.features.coinbase_extra.to_vec()).collect(),
};

if let Err(err) = tx.send(Ok(difficulty)).await {
Expand Down
10 changes: 10 additions & 0 deletions base_layer/core/src/transactions/aggregated_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ impl AggregateBody {
Ok(fee)
}

pub fn get_coinbase_outputs(&self) -> Vec<&TransactionOutput> {
let mut outputs = vec![];
for utxo in self.outputs() {
if utxo.features.output_type == OutputType::Coinbase {
outputs.push(utxo);
}
}
outputs
}

/// Run through the outputs of the block and check that
/// 1. There is exactly ONE coinbase output
/// 1. The coinbase output's maturity is correctly set
Expand Down

0 comments on commit d48a15c

Please sign in to comment.