From 3fb98b9d1f6fda7dc087d9853a2dfeea7fc00632 Mon Sep 17 00:00:00 2001 From: richardb Date: Tue, 2 Jul 2024 13:37:23 +0200 Subject: [PATCH] small updates --- src/server/grpc/p2pool.rs | 4 ++-- src/server/p2p/p2p.rs | 14 +++++++------- src/sharechain/in_memory.rs | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/server/grpc/p2pool.rs b/src/server/grpc/p2pool.rs index bddf1ddd..4fc1cc78 100644 --- a/src/server/grpc/p2pool.rs +++ b/src/server/grpc/p2pool.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use log::{debug, error, info}; +use log::{debug, error, info, warn}; use minotari_app_grpc::tari_rpc::{ GetNewBlockRequest, GetNewBlockResponse, GetNewBlockTemplateWithCoinbasesRequest, HeightRequest, NewBlockTemplateRequest, PowAlgo, SubmitBlockRequest, SubmitBlockResponse, @@ -55,7 +55,7 @@ impl ShaP2PoolGrpc /// Submits a new block to share chain and broadcasts to the p2p network. pub async fn submit_share_chain_block(&self, block: &Block) -> Result<(), Status> { if let Err(error) = self.share_chain.submit_block(block).await { - error!(target: LOG_TARGET, "Failed to add new block: {error:?}"); + warn!(target: LOG_TARGET, "Failed to add new block: {error:?}"); } debug!(target: LOG_TARGET, "Broadcast new block with height: {:?}", block.height()); self.p2p_client diff --git a/src/server/p2p/p2p.rs b/src/server/p2p/p2p.rs index 5c38d3d8..cda588a8 100644 --- a/src/server/p2p/p2p.rs +++ b/src/server/p2p/p2p.rs @@ -385,13 +385,13 @@ impl Service Ok(payload) => { debug!(target: LOG_TARGET, "New peer info: {peer:?} -> {payload:?}"); self.peer_store.add(peer, payload).await; - if let Some(tip) = self.peer_store.tip_of_block_height().await { - if let Ok(curr_height) = self.share_chain.tip_height().await { - if curr_height < tip.height { - self.sync_share_chain().await; - } - } - } + // if let Some(tip) = self.peer_store.tip_of_block_height().await { + // if let Ok(curr_height) = self.share_chain.tip_height().await { + // if curr_height < tip.height { + self.sync_share_chain().await; + // } + // } + // } } Err(error) => { error!(target: LOG_TARGET, "Can't deserialize peer info payload: {:?}", error); diff --git a/src/sharechain/in_memory.rs b/src/sharechain/in_memory.rs index a76424ae..4205caf2 100644 --- a/src/sharechain/in_memory.rs +++ b/src/sharechain/in_memory.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::sync::Arc; use async_trait::async_trait; -use log::{debug, info, warn}; +use log::{debug, error, info, warn}; use minotari_app_grpc::tari_rpc::{NewBlockCoinbase, SubmitBlockRequest}; use tari_common_types::tari_address::TariAddress; use tari_core::blocks::BlockHeader; @@ -95,6 +95,7 @@ impl InMemoryShareChain { if in_sync && last_block.is_some() { // validate if !self.validate_block(last_block.unwrap(), &block).await? { + error!(target: LOG_TARGET, "Invalid block!"); return Err(Error::InvalidBlock(block)); } } else if !in_sync && last_block.is_none() { @@ -102,6 +103,7 @@ impl InMemoryShareChain { } else if !in_sync && last_block.is_some() { // validate if !self.validate_block(last_block.unwrap(), &block).await? { + error!(target: LOG_TARGET, "Invalid block!"); return Err(Error::InvalidBlock(block)); } } @@ -136,7 +138,7 @@ impl ShareChain for InMemoryShareChain { let last_block = blocks_write_lock.last(); if (sync && last_block.is_none()) || - (sync && last_block.is_some() && last_block.unwrap().height() < blocks[0].height()) { + (sync && last_block.is_some() && !blocks.is_empty() && last_block.unwrap().height() < blocks[0].height()) { blocks_write_lock.clear(); }