Skip to content

Commit

Permalink
fix get_locator which loop the whole headers (#2159)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyyu authored Dec 16, 2018
1 parent c188b60 commit ea1c3a9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions servers/src/grin/sync/header_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl HeaderSync {
// Rebuild the sync MMR to match our updated sync_head.
self.chain.rebuild_sync_mmr(&header_head).unwrap();

self.history_locator.clear();
self.history_locator.retain(|&x| x.0 == 0);
true
}
_ => false,
Expand Down Expand Up @@ -154,7 +154,7 @@ impl HeaderSync {
// for security, clear history_locator[] in any case of header chain rollback,
// the easiest way is to check whether the sync head and the header head are identical.
if self.history_locator.len() > 0 && tip.hash() != self.chain.header_head()?.hash() {
self.history_locator.clear();
self.history_locator.retain(|&x| x.0 == 0);
}

// for each height we need, we either check if something is close enough from
Expand All @@ -168,8 +168,10 @@ impl HeaderSync {
let last_loc = locator.last().unwrap().clone();
let mut header_cursor = self.chain.get_block_header(&last_loc.1);
while let Ok(header) = header_cursor {
if header.height == h && header.height != last_loc.0 {
locator.push((header.height, header.hash()));
if header.height == h {
if header.height != last_loc.0 {
locator.push((header.height, header.hash()));
}
break;
}
header_cursor = self.chain.get_previous_header(&header);
Expand Down

0 comments on commit ea1c3a9

Please sign in to comment.