Skip to content

Commit a31e28a

Browse files
authored
fix: small fixes (#179)
Description --- Fixes catchup sync sending duplicate blocks Removes not required rwlock
1 parent d72eb49 commit a31e28a

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/server/p2p/network.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ where S: ShareChain
620620
return Ok(MessageAcceptance::Reject);
621621
}
622622

623-
info!(target: LOG_TARGET, squad = &self.config.squad; "🆕 New block from broadcast: {:?}", &payload.new_blocks.iter().map(|b| b.height.to_string()).collect::<Vec<String>>());
623+
info!(target: LOG_TARGET, squad = &self.config.squad; "[{:?}]🆕 New block from broadcast: {:?}", &payload.new_blocks.first().unwrap().original_header.pow.pow_algo ,&payload.new_blocks.iter().map(|b| b.height.to_string()).collect::<Vec<String>>());
624624
// info!(target: LOG_TARGET, squad = &self.config.squad; "🆕 New blocks from broadcast:
625625
// {:?}", &payload.new_blocks.iter().map(|b| b.hash.to_hex()).collect::<Vec<String>>());
626626
let algo = payload.algo();
@@ -1006,17 +1006,6 @@ where S: ShareChain
10061006
missing_parents,
10071007
is_from_new_block_notify,
10081008
} = sync_share_chain;
1009-
let peer_store_read_lock = self.network_peer_store.read().await;
1010-
if peer_store_read_lock.is_blacklisted(&peer) {
1011-
warn!(target: LOG_TARGET, squad = &self.config.squad; "Peer is blacklisted, skipping sync");
1012-
return;
1013-
}
1014-
1015-
if !peer_store_read_lock.is_whitelisted(&peer) {
1016-
info!(target: LOG_TARGET, squad = &self.config.squad; "Peer is not whitelisted, will still try to sync");
1017-
// return;
1018-
}
1019-
drop(peer_store_read_lock);
10201009

10211010
if is_from_new_block_notify {
10221011
info!(target: SYNC_REQUEST_LOG_TARGET, "[{}] Sending sync to connected peers for blocks {:?} from notify", algo, missing_parents.iter().map(|(height, hash)|format!("{}({:x}{:x}{:x}{:x})",height.to_string(), hash[0], hash[1], hash[2], hash[3])).collect::<Vec<String>>());
@@ -1041,13 +1030,24 @@ where S: ShareChain
10411030
// };
10421031

10431032
// ask our connected peers rather than everyone swarming the original peer
1033+
let mut sent_to_original_peer = false;
10441034
let connected_peers: Vec<_> = self.swarm.connected_peers().cloned().collect();
10451035
for connected_peer in connected_peers {
1036+
if connected_peer == peer {
1037+
sent_to_original_peer = true;
1038+
}
10461039
let _outbound_id = self.swarm.behaviour_mut().share_chain_sync.send_request(
10471040
&connected_peer,
10481041
ShareChainSyncRequest::new(algo, missing_parents.clone()),
10491042
);
10501043
}
1044+
if !sent_to_original_peer && !is_from_new_block_notify {
1045+
let _outbound_id = self
1046+
.swarm
1047+
.behaviour_mut()
1048+
.share_chain_sync
1049+
.send_request(&peer, ShareChainSyncRequest::new(algo, missing_parents.clone()));
1050+
}
10511051
}
10521052

10531053
/// Main method to handle libp2p events.
@@ -1463,7 +1463,6 @@ where S: ShareChain
14631463
Err(error) => match error {
14641464
crate::sharechain::error::ShareChainError::BlockParentDoesNotExist { missing_parents } => {
14651465
// This should not happen though, catchup should return all blocks
1466-
warn!(target: SYNC_REQUEST_LOG_TARGET, squad; "Catchup sync Reporting missing blocks {}", missing_parents.len());
14671466
for (height, hash) in missing_parents {
14681467
missing_blocks.insert((height, hash));
14691468
}
@@ -1487,14 +1486,14 @@ where S: ShareChain
14871486
};
14881487
}
14891488
if missing_blocks.len() > 0 {
1489+
warn!(target: SYNC_REQUEST_LOG_TARGET, squad; "Catchup sync Reporting missing blocks {}", missing_blocks.len());
14901490
let sync_share_chain = SyncShareChain {
14911491
algo,
14921492
peer,
14931493
missing_parents: missing_blocks.into_iter().collect(),
14941494
is_from_new_block_notify: false,
14951495
};
14961496
let _ = tx.send(InnerRequest::DoSyncChain(sync_share_chain));
1497-
// return;
14981497
}
14991498

15001499
info!(target: SYNC_REQUEST_LOG_TARGET, squad = &squad; "Synced blocks added to share chain");

src/server/p2p/peer_store.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
io::{BufReader, Write},
88
path::Path,
99
str::FromStr,
10-
sync::Arc,
1110
time::{Duration, Instant},
1211
};
1312

@@ -17,7 +16,6 @@ use log::warn;
1716
use tari_core::proof_of_work::PowAlgorithm;
1817
use tari_utilities::epoch_time::EpochTime;
1918

20-
use super::messages::NotifyNewTipBlock;
2119
use crate::server::{http::stats_collector::StatsBroadcastClient, p2p::messages::PeerInfo, PROTOCOL_VERSION};
2220

2321
const LOG_TARGET: &str = "tari::p2pool::peer_store";

src/sharechain/in_memory.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use super::{
3030
UNCLE_REWARD_SHARE,
3131
};
3232
use crate::{
33-
main,
3433
server::{http::stats_collector::StatsBroadcastClient, PROTOCOL_VERSION},
3534
sharechain::{
3635
error::{ShareChainError, ValidationError},
@@ -329,7 +328,6 @@ impl InMemoryShareChain {
329328
}
330329
};
331330

332-
333331
loop {
334332
for block in level.blocks.values() {
335333
if main_chain_only {
@@ -698,7 +696,7 @@ impl ShareChain for InMemoryShareChain {
698696
if let Some(last_block_received) = last_block_received {
699697
if let Some(level) = p2_chain_read.level_at_height(last_block_received.0) {
700698
if let Some(block) = level.blocks.get(&last_block_received.1) {
701-
split_height = block.height;
699+
split_height = block.height.saturating_add(1);
702700
}
703701
}
704702
}
@@ -715,7 +713,7 @@ impl ShareChain for InMemoryShareChain {
715713
if let Some(block) = level.blocks.get(&their_block.1) {
716714
// Only split if the block is in the main chain
717715
if level.chain_block == block.hash {
718-
split_height2 = block.height;
716+
split_height2 = block.height.saturating_add(1);
719717
break;
720718
}
721719
}

0 commit comments

Comments
 (0)