Ignore non-sync invs and don't relay invs if we are not yet caught up.

We originally wanted to also not fetch orphan parents in this commit, however,
I have discovered that if you are doing a main sync from a peer, if it
sends you an orphan you must fetch it, else you ahven't fetched
everything it told you about and thus it will nto send you end more invs
from the main sync.

So we always fetch orphan parents, but we still don't fetch from
non-sync peers (all invs from them will be unsolicited). Seems to fix some hangs
with multiple peers.
This commit is contained in:
Owain G. Ainsworth 2013-10-03 16:25:13 +01:00
parent 6dbc61e960
commit 6bb0b80bbb

View file

@ -272,6 +272,11 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
// NOTE: This will need to have tx handling added as well when they are
// supported.
func (b *blockManager) handleInvMsg(imsg *invMsg) {
// 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.blockChain.IsCurrent() {
return
}
// Attempt to find the final block in the inventory list. There may
// not be one.
lastBlock := -1
@ -439,6 +444,13 @@ func (b *blockManager) handleNotifyMsg(notification *btcchain.Notification) {
// A block has been accepted into the block chain. Relay it to other
// peers.
case btcchain.NTBlockAccepted:
// Don't relay if we are not current. Other peers that are
// current should already know about it.
if !b.blockChain.IsCurrent() {
return
}
block, ok := notification.Data.(*btcutil.Block)
if !ok {
log.Warnf("[BMGR] Chain notification type not a block.")