Skip to content

Commit

Permalink
blockmanager: only check if current once handling inv's
Browse files Browse the repository at this point in the history
This saves two additional calls to chain.IsCurrent().
  • Loading branch information
dajohi authored and davecgh committed Feb 17, 2019
1 parent 6dbd893 commit 4e7f080
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,24 +1290,27 @@ func (b *blockManager) handleInvMsg(imsg *invMsg) {
}
}

fromSyncPeer := imsg.peer == b.syncPeer
isCurrent := b.current()

// If this inv contains a block announcement, and this isn't coming from
// our current sync peer or we're current, then update the last
// announced block for this peer. We'll use this information later to
// update the heights of peers based on blocks we've accepted that they
// previously announced.
if lastBlock != -1 && (imsg.peer != b.syncPeer || b.current()) {
if lastBlock != -1 && (!fromSyncPeer || isCurrent) {
imsg.peer.UpdateLastAnnouncedBlock(&invVects[lastBlock].Hash)
}

// Ignore invs from peers that aren't the sync if we are not current.
// Helps prevent fetching a mass of orphans.
if imsg.peer != b.syncPeer && !b.current() {
if !fromSyncPeer && !isCurrent {
return
}

// If our chain is current and a peer announces a block we already
// know of, then update their current block height.
if lastBlock != -1 && b.current() {
if lastBlock != -1 && isCurrent {
blkHeight, err := b.chain.BlockHeightByHash(&invVects[lastBlock].Hash)
if err == nil {

Expand Down

0 comments on commit 4e7f080

Please sign in to comment.