From 4e7f080b7b2cb11a8680d54dc5fb9ce735119d15 Mon Sep 17 00:00:00 2001 From: David Hill Date: Sat, 16 Feb 2019 14:31:23 -0500 Subject: [PATCH] blockmanager: only check if current once handling inv's This saves two additional calls to chain.IsCurrent(). --- blockmanager.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/blockmanager.go b/blockmanager.go index 8245d1f6..2440dd5c 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -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 {