Skip to content

Commit 5a26674

Browse files
authored
fix: add sort to incoming blocks (#180)
Description --- sort the incoming blocks
1 parent a31e28a commit 5a26674

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/server/p2p/network.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ where S: ShareChain
14421442
let their_tip_hash = *response.tip_hash();
14431443
let their_height = response.tip_height();
14441444
let their_pow = response.achieved_pow();
1445-
let blocks: Vec<_> = response.into_blocks().into_iter().map(Arc::new).collect();
1445+
let mut blocks: Vec<_> = response.into_blocks().into_iter().map(Arc::new).collect();
14461446
info!(target: SYNC_REQUEST_LOG_TARGET, "Received catch up sync response for chain {} from {} with blocks {}. Their tip: {}:{}", algo, peer, blocks.iter().map(|a| a.height.to_string()).join(", "), their_height, &their_tip_hash.to_hex()[0..8]);
14471447
if blocks.is_empty() {
14481448
return;
@@ -1453,6 +1453,7 @@ where S: ShareChain
14531453
let synced_bool = self.are_we_synced_with_p2pool.clone();
14541454

14551455
tokio::spawn(async move {
1456+
blocks.sort_by(|a, b| a.height.cmp(&b.height));
14561457
let last_block_from_them = blocks.last().map(|b| (b.height, b.hash));
14571458
let mut missing_blocks = HashSet::new();
14581459
for b in &blocks {

0 commit comments

Comments
 (0)