From b6a6e577c4a23ea43be6e35c0f236a8fbac10044 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Tue, 9 Jun 2020 12:12:18 +0300 Subject: [PATCH] [NOD-1013] Don't block handleBlockDAGNotification when calling peerNotifier (#749) * [NOD-1013] Don't block handleBlockDAGNotification when calling peerNotifier * [NOD-1013] Add comment --- netsync/manager.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/netsync/manager.go b/netsync/manager.go index 0ab7c4e50..2a3227c98 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -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) + } + }) } }