From 009baa1b91138db5dfff2548f441473047b155de Mon Sep 17 00:00:00 2001 From: Gary Yu Date: Wed, 10 Oct 2018 16:48:41 +0800 Subject: [PATCH] fix: panic at get_locator (#1711) --- servers/src/grin/sync/header_sync.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/servers/src/grin/sync/header_sync.rs b/servers/src/grin/sync/header_sync.rs index fbe542f5..8200dbf4 100644 --- a/servers/src/grin/sync/header_sync.rs +++ b/servers/src/grin/sync/header_sync.rs @@ -240,15 +240,16 @@ impl HeaderSync { let shrink_index = self .history_locators .iter() - .position(|&r| r.0 > shrink_height) - .unwrap(); - if shrink_index > 100 { - // shrink but avoid trivial shrinking - let mut shrunk = self.history_locators[shrink_index..].to_vec(); - shrunk_size = shrink_index; - self.history_locators.clear(); - self.history_locators.push((0, locator[locator.len() - 1])); - self.history_locators.append(&mut shrunk); + .position(|&r| r.0 > shrink_height); + if let Some(shrink_index) = shrink_index { + if shrink_index > 100 { + // shrink but avoid trivial shrinking + let mut shrunk = self.history_locators[shrink_index..].to_vec(); + shrunk_size = shrink_index; + self.history_locators.clear(); + self.history_locators.push((0, locator[locator.len() - 1])); + self.history_locators.append(&mut shrunk); + } } debug!( LOGGER,