From fefb89277acb82c8e35adfde85530dc1f0d6471d Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 10 Sep 2018 04:46:43 -0500 Subject: [PATCH] blockmanager: Fast relay checked tip blocks. This makes use of the newly exposed notification from blockchain when a block that intends to extend the main chain has passed all sanity and contextual checks to relay the block the rest of the network at that point rather than needing to wait for the more expensive connection code to complete. --- blockmanager.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/blockmanager.go b/blockmanager.go index 3e2235cf..d80a7fa4 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -1852,8 +1852,26 @@ func (b *blockManager) notifiedWinningTickets(hash *chainhash.Hash) bool { // as request orphan block parents and relay accepted blocks to connected peers. func (b *blockManager) handleNotifyMsg(notification *blockchain.Notification) { switch notification.Type { + // A block that intends to extend the main chain has passed all sanity and + // contextual checks and the chain is believed to be current. Relay it to + // other peers. + case blockchain.NTNewTipBlockChecked: + // WARNING: The chain lock is not released before sending this + // notification, so care must be taken to avoid calling chain functions + // which could result in a deadlock. + block, ok := notification.Data.(*dcrutil.Block) + if !ok { + bmgrLog.Warnf("New tip block checkedd notification is not a block.") + break + } + + // Generate the inventory vector and relay it immediately. + iv := wire.NewInvVect(wire.InvTypeBlock, block.Hash()) + b.server.RelayInventory(iv, block.MsgBlock().Header, true) + // A block has been accepted into the block chain. Relay it to other peers - // and possibly notify RPC clients with the winning tickets. + // (will be ignored if already relayed via NTNewTipBlockChecked) and + // possibly notify RPC clients with the winning tickets. case blockchain.NTBlockAccepted: // Don't relay or notify RPC clients with winning tickets if we // are not current. Other peers that are current should already