Skip to content

Commit

Permalink
fix: unknown list insert should remove genesis hash
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Nov 14, 2022
1 parent 1ce2b34 commit 266de54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sync/src/synchronizer/get_headers_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'a> GetHeadersProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.synchronizer.shared.active_chain();

let block_locator_hashes = self
let mut block_locator_hashes = self
.message
.block_locator_hashes()
.iter()
Expand All @@ -59,6 +59,10 @@ impl<'a> GetHeadersProcess<'a> {
let state = self.synchronizer.shared.state();
if let Some(flag) = state.peers().get_flag(self.peer) {
if flag.is_outbound || flag.is_whitelist || flag.is_protect {
// Remove genesis hash on locators, because `try_update_best_known_with_unknown_header_list` can use
// genesis hash on headermap search, it will case some peers can not set best knonwn header and causes
// the ibd download source to be lost
block_locator_hashes.pop();
state.insert_peer_unknown_header_list(self.peer, block_locator_hashes);
}
};
Expand Down
9 changes: 9 additions & 0 deletions sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ impl Synchronizer {
}
}

// On ibd, node should only have one peer to sync headers, and it's state can control by
// headers_sync_controller.
//
// The header sync of other nodes does not matter in the ibd phase, and parallel synchronization
// can be enabled by unknown list, so there is no need to repeatedly download headers with
// multiple nodes at the same time.
if active_chain.is_initial_block_download() {
continue;
}
if state.peer_flags.is_outbound {
let best_known_header = state.best_known_header.as_ref();
let (tip_header, local_total_difficulty) = {
Expand Down
2 changes: 1 addition & 1 deletion sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ impl SyncState {
}

pub fn try_update_best_known_with_unknown_header_list(&self, pi: PeerIndex) {
// header list is an ordered list, sorted from highest to lowest,
// unknown list is an ordered list, sorted from lowest to highest,
// when header hash unknown, break loop is ok
while let Some(hash) = self.peers().take_unknown_last(pi) {
if let Some(header) = self.header_map.get(&hash) {
Expand Down

0 comments on commit 266de54

Please sign in to comment.