Skip to content

Commit

Permalink
chore(release): v0.6.7
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Oct 28, 2024
1 parent 9c09672 commit 152cb45
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"}
Expand Down
19 changes: 13 additions & 6 deletions src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -537,15 +537,15 @@ 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
/// blocks and peers with different Tari networks and the given squad name.
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.
Expand Down Expand Up @@ -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:?}");
Expand All @@ -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:?}");
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down Expand Up @@ -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)
);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/sharechain/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 152cb45

Please sign in to comment.