Skip to content

Commit

Permalink
chore: add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Sep 19, 2024
1 parent a2ab7c0 commit 0498887
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/server/grpc/p2pool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use log::{error, info, warn};
use log::{debug, error, info, warn};
use minotari_app_grpc::tari_rpc::pow_algo::PowAlgos;
use minotari_app_grpc::tari_rpc::{
base_node_client::BaseNodeClient, sha_p2_pool_server::ShaP2Pool, GetNewBlockRequest, GetNewBlockResponse,
Expand Down Expand Up @@ -196,6 +196,7 @@ where
.clone()
.miner_data
.ok_or_else(|| Status::internal("missing miner data"))?;
debug!("Inserting height cached difficulty: {}", miner_data.target_difficulty);
if let Some(header) = &response.block {
let height = header.header.as_ref().map(|h| h.height).unwrap_or(0);
self.block_height_difficulty_cache
Expand Down Expand Up @@ -312,13 +313,15 @@ where
if *max_difficulty < request_block_difficulty.as_u64() {
*max_difficulty = request_block_difficulty.as_u64();
}
info!("Max difficulty: {}", max_difficulty);

if !network_difficulty_matches {
block.set_sent_to_main_chain(false);
// Don't error if we can't submit it.
match self.submit_share_chain_block(&block).await {
Ok(_) => {
info!("πŸ”— Block submitted to share chain!");
let pow_type = origin_block_header.pow.pow_algo.to_string();
info!("πŸ”— Block submitted to {} share chain!", pow_type);
},
Err(error) => {
warn!("Failed to submit block to share chain: {error:?}");
Expand All @@ -331,20 +334,27 @@ where

// submit block to base node
let (metadata, extensions, _inner) = request.into_parts();
info!("πŸ”— Submitting block to base node...");
info!("πŸ”— Submitting block {} to base node...", origin_block_header.hash());

let grpc_request = Request::from_parts(metadata, extensions, grpc_request_payload);
match self.client.lock().await.submit_block(grpc_request).await {
Ok(resp) => {
self.stats_store
.inc(&algo_stat_key(pow_algo, P2POOL_STAT_ACCEPTED_BLOCKS_COUNT), 1)
.await;
info!("πŸ’° New matching block found and sent to network!");
info!(
"πŸ’° New matching block found and sent to network! Block hash: {}",
origin_block_header.hash()
);
block.set_sent_to_main_chain(true);
self.submit_share_chain_block(&block).await?;
Ok(resp)
},
Err(error) => {
warn!("Failed to submit block to Tari network: {error:?}");
warn!(
"Failed to submit block {} to Tari network: {error:?}",
origin_block_header.hash()
);
self.stats_store
.inc(&algo_stat_key(pow_algo, P2POOL_STAT_REJECTED_BLOCKS_COUNT), 1)
.await;
Expand Down

0 comments on commit 0498887

Please sign in to comment.