Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add back check for missing block #174

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use std::{
collections::HashMap,
collections::{HashMap, HashSet},
fmt::Display,
fs,
hash::Hash,
Expand Down Expand Up @@ -1452,6 +1452,7 @@ where S: ShareChain

tokio::spawn(async move {
let last_block_from_them = blocks.last().map(|b| (b.height, b.hash));
let mut missing_blocks = HashSet::new();
for b in &blocks {
match share_chain.add_synced_blocks(&[b.clone()]).await {
Ok(result) => {
Expand All @@ -1461,6 +1462,9 @@ where S: ShareChain
crate::sharechain::error::ShareChainError::BlockParentDoesNotExist { missing_parents } => {
// This should not happen though, catchup should return all blocks
warn!(target: SYNC_REQUEST_LOG_TARGET, squad; "Catchup sync Reporting missing blocks {}", missing_parents.len());
for (height, hash) in missing_parents {
missing_blocks.insert((height, hash));
}
// let sync_share_chain = SyncShareChain {
// algo,
// peer,
Expand All @@ -1480,10 +1484,20 @@ where S: ShareChain
},
};
}
if missing_blocks.len() > 0 {
let sync_share_chain = SyncShareChain {
algo,
peer,
missing_parents: missing_blocks.into_iter().collect(),
is_from_new_block_notify: false,
};
let _ = tx.send(InnerRequest::DoSyncChain(sync_share_chain));
return;
}

info!(target: SYNC_REQUEST_LOG_TARGET, squad = &squad; "Synced blocks added to share chain");
let our_pow = share_chain.get_total_chain_pow().await;
let mut must_continue_sync = their_pow > our_pow.as_u128();
let mut must_continue_sync = missing_blocks.is_empty && their_pow > our_pow.as_u128();
info!(target: SYNC_REQUEST_LOG_TARGET, "[{:?}] must continue: {}", algo, must_continue_sync);
// Check if we have recieved their tip
if blocks.iter().any(|b| b.hash == their_tip_hash) {
Expand Down
Loading