[NOD-1013] Don't block handleBlockDAGNotification when calling peerNotifier (#749)

* [NOD-1013] Don't block handleBlockDAGNotification when calling peerNotifier

* [NOD-1013] Add comment
This commit is contained in:
Ori Newman 2020-06-09 12:12:18 +03:00 committed by GitHub
parent 84888221ae
commit b6a6e577c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1029,17 +1029,22 @@ func (sm *SyncManager) handleBlockDAGNotification(notification *blockdag.Notific
}
})
// Relay if we are current and the block was not just now unorphaned.
// Otherwise peers that are current should already know about it
if sm.isSynced() && !data.WasUnorphaned {
iv := wire.NewInvVect(wire.InvTypeBlock, block.Hash())
sm.peerNotifier.RelayInventory(iv, block.MsgBlock().Header)
}
// sm.peerNotifier sends messages to the rebroadcastHandler, so we call
// it in its own goroutine so it won't block dag.ProcessBlock in case
// rebroadcastHandler channel is full.
spawn(func() {
// Relay if we are current and the block was not just now unorphaned.
// Otherwise peers that are current should already know about it
if sm.isSynced() && !data.WasUnorphaned {
iv := wire.NewInvVect(wire.InvTypeBlock, block.Hash())
sm.peerNotifier.RelayInventory(iv, block.MsgBlock().Header)
}
for msg := range ch {
sm.peerNotifier.TransactionConfirmed(msg.Tx)
sm.peerNotifier.AnnounceNewTransactions(msg.AcceptedTxs)
}
for msg := range ch {
sm.peerNotifier.TransactionConfirmed(msg.Tx)
sm.peerNotifier.AnnounceNewTransactions(msg.AcceptedTxs)
}
})
}
}