From 152cb454347de1620b512d3d5e731b76f155551c Mon Sep 17 00:00:00 2001 From: stringhandler Date: Mon, 28 Oct 2024 20:49:19 +0200 Subject: [PATCH] chore(release): v0.6.7 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/server/p2p/network.rs | 19 +++++++++++++------ src/sharechain/in_memory.rs | 11 ++++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76ce7a33..f6855ccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4542,7 +4542,7 @@ dependencies = [ [[package]] name = "sha_p2pool" -version = "0.6.6" +version = "0.6.7" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index d5138671..06566781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "sha_p2pool" -version = "0.6.6" +version = "0.6.7" [dependencies] minotari_app_grpc = {git = "https://github.com/tari-project/tari.git", rev = "2d0ccb121bb13990cac422fe72945cced06c1f74"} diff --git a/src/server/p2p/network.rs b/src/server/p2p/network.rs index bd30a922..f270b000 100644 --- a/src/server/p2p/network.rs +++ b/src/server/p2p/network.rs @@ -417,7 +417,7 @@ where S: ShareChain StreamProtocol::new(CATCH_UP_SYNC_REQUEST_RESPONSE_PROTOCOL), request_response::ProtocolSupport::Full, )], - request_response::Config::default().with_request_timeout(Duration::from_secs(30)), // 10 is the default + request_response::Config::default().with_request_timeout(Duration::from_secs(90)), // 10 is the default ), kademlia: kad::Behaviour::new( key_pair.public().to_peer_id(), @@ -537,7 +537,7 @@ where S: ShareChain fn network_topic(topic: &str) -> String { let network = Network::get_current_or_user_setting_or_default().as_key_str(); let chain_id = CURRENT_CHAIN_ID.clone(); - format!("{network}_{chain_id}_{topic}") + format!("{network}_{chain_id}_{topic}_{PROTOCOL_VERSION}") } /// Generates a gossip sub topic name based on the current Tari network to avoid mixing up @@ -545,7 +545,7 @@ where S: ShareChain fn squad_topic(squad: &Squad, topic: &str) -> String { let network = Network::get_current_or_user_setting_or_default().as_key_str(); let chain_id = CURRENT_CHAIN_ID.clone(); - format!("{network}_{chain_id}_{squad}_{topic}") + format!("{network}_{chain_id}_{squad}_{topic}_{PROTOCOL_VERSION}") } /// Subscribing to a gossipsub topic. @@ -1158,6 +1158,7 @@ where S: ShareChain if blocks.is_empty() { return; } + let last_block_from_them = blocks.last().map(|b| (b.height, b.hash.clone())); match share_chain.add_synced_blocks(&blocks).await { Ok(result) => { info!(target: LOG_TARGET, squad = &self.config.squad; "Synced blocks added to share chain: {result:?}"); @@ -1169,7 +1170,7 @@ where S: ShareChain dbg!(their_tip_hash); dbg!(share_chain.get_tip().await); self.network_peer_store.add_catch_up_attempt(&peer); - match self.perform_catch_up_sync(algo, peer).await { + match self.perform_catch_up_sync(algo, peer, last_block_from_them).await { Ok(_) => {}, Err(error) => { error!(target: LOG_TARGET, squad = &self.config.squad; "Failed to perform catch up sync: {error:?}"); @@ -1247,7 +1248,7 @@ where S: ShareChain // self.swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); } - async fn perform_catch_up_sync(&mut self, algo: PowAlgorithm, peer: PeerId)-> Result<(), Error> { + async fn perform_catch_up_sync(&mut self, algo: PowAlgorithm, peer: PeerId, last_block_from_them: Option<(u64, FixedHash)>)-> Result<(), Error> { let share_chain = match algo { PowAlgorithm::RandomX => self.share_chain_random_x.clone(), PowAlgorithm::Sha3x => self.share_chain_sha3x.clone(), @@ -1273,6 +1274,10 @@ where S: ShareChain } } + if let Some(last_block_synced) = last_block_from_them { + i_have_blocks.push(last_block_synced); + } + info!(target: SYNC_REQUEST_LOG_TARGET, "Sending catch up sync to {} for blocks {}", peer, i_have_blocks.iter().map(|a| a.0.to_string()).join(", ")); self.swarm @@ -1555,7 +1560,9 @@ where S: ShareChain PowAlgorithm::Sha3x => record.peer_info.current_sha3x_height, }; if their_height > our_tip { - self.perform_catch_up_sync(*algo, record.peer_id).await; + let _ = self.perform_catch_up_sync(*algo, record.peer_id, None).await.inspect_err(|e| + warn!(target: LOG_TARGET, squad = &self.config.squad; "Failed to perform catch up sync: {}", e) + ); } } } diff --git a/src/sharechain/in_memory.rs b/src/sharechain/in_memory.rs index 0afa96d1..5380de73 100644 --- a/src/sharechain/in_memory.rs +++ b/src/sharechain/in_memory.rs @@ -62,10 +62,7 @@ impl InMemoryShareChain { } Ok(Self { - p2_chain: Arc::new(RwLock::new(P2Chain::new_empty( - MAX_BLOCKS_COUNT, - SHARE_WINDOW, - ))), + p2_chain: Arc::new(RwLock::new(P2Chain::new_empty(MAX_BLOCKS_COUNT, SHARE_WINDOW))), pow_algo, block_validation_params, consensus_manager, @@ -583,6 +580,10 @@ impl ShareChain for InMemoryShareChain { // Assume their blocks are in order highest first. let mut split_height = 0; + let mut their_blocks = their_blocks.to_vec(); + their_blocks.sort_by(|a, b| b.0.cmp(&a.0)); + their_blocks.reverse(); + // Go back and find the split in the chain for their_block in their_blocks { if let Some(level) = p2_chain_read.level_at_height(their_block.0) { @@ -697,7 +698,7 @@ impl ShareChain for InMemoryShareChain { let skip = page * page_size; let mut num_skipped = 0; // TODO: This is very inefficient, we should refactor this. - for level in &chain_read_lock.levels { + for level in chain_read_lock.levels.iter().rev() { if level.height < start_height.unwrap_or(0) { continue; }