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: add coinbase extra info to grpc #6561

Merged
merged 4 commits into from
Sep 13, 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
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
Loading