From c99a742aae515564a575fc65279dca18cb92d5fe Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 31 Mar 2019 10:15:42 +1100 Subject: [PATCH] Fix bug in SimpleSync queue. It was not completing partials with bodies. --- beacon_node/network/src/sync/import_queue.rs | 16 +++++++++------- beacon_node/network/src/sync/simple_sync.rs | 4 +++- beacon_node/network/tests/tests.rs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/beacon_node/network/src/sync/import_queue.rs b/beacon_node/network/src/sync/import_queue.rs index 8680993aa4..b9280440bf 100644 --- a/beacon_node/network/src/sync/import_queue.rs +++ b/beacon_node/network/src/sync/import_queue.rs @@ -113,13 +113,6 @@ impl ImportQueue { }) } - /// Returns the index of the first new root in the list of block roots. - pub fn first_new_root(&mut self, roots: &[BlockRootSlot]) -> Option { - roots - .iter() - .position(|brs| self.is_new_block(&brs.block_root)) - } - /// Adds the `block_roots` to the partials queue. /// /// If a `block_root` is not in the queue and has not been processed by the chain it is added @@ -203,8 +196,17 @@ impl ImportQueue { .iter() .position(|p| p.block_root == block_root) { + // Case 1: there already exists a partial with a matching block root. + // + // The `inserted` time is set to now and the header is replaced, regardless of whether + // it existed or not. + self.partials[i].header = Some(header); self.partials[i].inserted = Instant::now(); } else { + // Case 2: there was no partial with a matching block root. + // + // A new partial is added. This case permits adding a header without already known the + // root -- this is not possible in the wire protocol however we support it anyway. self.partials.push(PartialBeaconBlock { slot: header.slot, block_root, diff --git a/beacon_node/network/src/sync/simple_sync.rs b/beacon_node/network/src/sync/simple_sync.rs index 21b2612689..39fe772b45 100644 --- a/beacon_node/network/src/sync/simple_sync.rs +++ b/beacon_node/network/src/sync/simple_sync.rs @@ -374,7 +374,9 @@ impl SimpleSync { return; } - let new_roots = self.import_queue.enqueue_block_roots(&res.roots, peer_id.clone()); + let new_roots = self + .import_queue + .enqueue_block_roots(&res.roots, peer_id.clone()); // No new roots means nothing to do. // diff --git a/beacon_node/network/tests/tests.rs b/beacon_node/network/tests/tests.rs index 9cead1b557..47d5482d3e 100644 --- a/beacon_node/network/tests/tests.rs +++ b/beacon_node/network/tests/tests.rs @@ -543,7 +543,7 @@ fn sync_two_nodes() { // A provides block bodies to B. node_a.tee_block_body_response(&node_b); - std::thread::sleep(Duration::from_secs(10)); + std::thread::sleep(Duration::from_secs(20)); node_b.harness.run_fork_choice();