Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small updates
Browse files Browse the repository at this point in the history
ksrichard committed Jul 2, 2024
1 parent ebd88ab commit 3fb98b9
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/server/grpc/p2pool.rs
Original file line number Diff line number Diff line change
@@ -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<S> ShaP2PoolGrpc<S>
/// 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
14 changes: 7 additions & 7 deletions src/server/p2p/p2p.rs
Original file line number Diff line number Diff line change
@@ -385,13 +385,13 @@ impl<S> Service<S>
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);
6 changes: 4 additions & 2 deletions src/sharechain/in_memory.rs
Original file line number Diff line number Diff line change
@@ -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,13 +95,15 @@ 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() {
return Err(Error::Empty);
} 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();
}

0 comments on commit 3fb98b9

Please sign in to comment.