From 2b02f062ff1e5df24eae7ee1cfaca7c1dfec59f9 Mon Sep 17 00:00:00 2001 From: stringhandler Date: Fri, 30 Aug 2024 16:00:32 +0200 Subject: [PATCH 1/3] feat: add coinbase extra info to grpc --- .../minotari_app_grpc/proto/base_node.proto | 2 ++ .../src/grpc/base_node_grpc_server.rs | 26 +++++++++++++++++++ .../core/src/transactions/aggregated_body.rs | 10 +++++++ src/nodeenv | 1 + 4 files changed, 39 insertions(+) create mode 160000 src/nodeenv diff --git a/applications/minotari_app_grpc/proto/base_node.proto b/applications/minotari_app_grpc/proto/base_node.proto index dfc1c8e525..5728ccd8a7 100644 --- a/applications/minotari_app_grpc/proto/base_node.proto +++ b/applications/minotari_app_grpc/proto/base_node.proto @@ -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; + bytes first_coinbase_extra = 9; } // A generic single value response for a specific height diff --git a/applications/minotari_node/src/grpc/base_node_grpc_server.rs b/applications/minotari_node/src/grpc/base_node_grpc_server.rs index 6808594afc..cbf3bd4632 100644 --- a/applications/minotari_node/src/grpc/base_node_grpc_server.rs +++ b/applications/minotari_node/src/grpc/base_node_grpc_server.rs @@ -311,6 +311,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, @@ -319,6 +340,11 @@ 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, + first_coinbase_extra: coinbases + .first() + .map(|c| c.features.coinbase_extra.to_vec()) + .unwrap_or_default(), }; if let Err(err) = tx.send(Ok(difficulty)).await { diff --git a/base_layer/core/src/transactions/aggregated_body.rs b/base_layer/core/src/transactions/aggregated_body.rs index 9d4f798285..ecdafcde2c 100644 --- a/base_layer/core/src/transactions/aggregated_body.rs +++ b/base_layer/core/src/transactions/aggregated_body.rs @@ -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 diff --git a/src/nodeenv b/src/nodeenv new file mode 160000 index 0000000000..a6585e9a63 --- /dev/null +++ b/src/nodeenv @@ -0,0 +1 @@ +Subproject commit a6585e9a63e1601c4a37f3a1bb8fd0722dd6b51c From 1673b684bc6601f014c2a9f9237cbdd0411727e4 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Fri, 13 Sep 2024 11:48:37 +0200 Subject: [PATCH 2/3] remove submodule --- src/nodeenv | 1 - 1 file changed, 1 deletion(-) delete mode 160000 src/nodeenv diff --git a/src/nodeenv b/src/nodeenv deleted file mode 160000 index a6585e9a63..0000000000 --- a/src/nodeenv +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a6585e9a63e1601c4a37f3a1bb8fd0722dd6b51c From 6b12783e1822706ac87715b64cfdc4079df070e8 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Fri, 13 Sep 2024 11:55:50 +0200 Subject: [PATCH 3/3] change to retrun all extras --- applications/minotari_app_grpc/proto/base_node.proto | 2 +- applications/minotari_node/src/grpc/base_node_grpc_server.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/applications/minotari_app_grpc/proto/base_node.proto b/applications/minotari_app_grpc/proto/base_node.proto index 5728ccd8a7..a8ecf372ff 100644 --- a/applications/minotari_app_grpc/proto/base_node.proto +++ b/applications/minotari_app_grpc/proto/base_node.proto @@ -218,7 +218,7 @@ message NetworkDifficultyResponse { uint64 sha3x_estimated_hash_rate = 6; uint64 randomx_estimated_hash_rate = 7; uint64 num_coinbases = 8; - bytes first_coinbase_extra = 9; + repeated bytes coinbase_extras = 9; } // A generic single value response for a specific height diff --git a/applications/minotari_node/src/grpc/base_node_grpc_server.rs b/applications/minotari_node/src/grpc/base_node_grpc_server.rs index cbf3bd4632..fd8fb1ec1c 100644 --- a/applications/minotari_node/src/grpc/base_node_grpc_server.rs +++ b/applications/minotari_node/src/grpc/base_node_grpc_server.rs @@ -341,10 +341,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer { timestamp: current_timestamp.as_u64(), pow_algo: pow_algo.as_u64(), num_coinbases: coinbases.len() as u64, - first_coinbase_extra: coinbases - .first() - .map(|c| c.features.coinbase_extra.to_vec()) - .unwrap_or_default(), + coinbase_extras: coinbases.iter().map(|c| c.features.coinbase_extra.to_vec()).collect(), }; if let Err(err) = tx.send(Ok(difficulty)).await {