From 1cc479dbf8cd3ad356cf0d4a6076cdcf4269a099 Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Wed, 1 May 2019 18:01:58 +0300 Subject: [PATCH] [NOD-152] Netsync correctly syncs only 500 first blocks (#276) * [NOD-152] Stopped pushBlockMsg from sending tip inv to syncing nodes. * [NOD-152] Fixed restartSyncIfNeeded not restarting if sync is needed. * [NOD-152] Removed continueHash, as it is no longer required. --- netsync/manager.go | 2 ++ server/p2p/p2p.go | 33 +-------------------------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/netsync/manager.go b/netsync/manager.go index 0e0319c65..adce4c2eb 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -496,6 +496,8 @@ func (sm *SyncManager) restartSyncIfNeeded() { } } } + + sm.syncPeer = nil sm.startSync() } diff --git a/server/p2p/p2p.go b/server/p2p/p2p.go index 2c7555dbd..cdc814d2d 100644 --- a/server/p2p/p2p.go +++ b/server/p2p/p2p.go @@ -160,7 +160,6 @@ type Peer struct { connReq *connmgr.ConnReq server *Server persistent bool - continueHash *daghash.Hash relayMtx sync.Mutex DisableRelayTx bool sentAddrs bool @@ -713,15 +712,6 @@ func (sp *Peer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks) { // Send the inventory message if there is anything to send. if len(invMsg.InvList) > 0 { - invListLen := len(invMsg.InvList) - if invListLen == wire.MaxBlocksPerMsg { - // Intentionally use a copy of the final hash so there - // is not a reference into the inventory slice which - // would prevent the entire slice from being eligible - // for GC as soon as it's sent. - continueHash := invMsg.InvList[invListLen-1].Hash - sp.continueHash = continueHash - } sp.QueueMessage(invMsg, nil) } } @@ -1318,29 +1308,8 @@ func (s *Server) pushBlockMsg(sp *Peer, hash *daghash.Hash, doneChan chan<- stru <-waitChan } - // We only send the channel for this message if we aren't sending - // an inv straight after. - var dc chan<- struct{} - continueHash := sp.continueHash - sendInv := continueHash != nil && continueHash.IsEqual(hash) - if !sendInv { - dc = doneChan - } - sp.QueueMessage(&msgBlock, dc) + sp.QueueMessage(&msgBlock, doneChan) - // When the peer requests the final block that was advertised in - // response to a getblocks message which requested more blocks than - // would fit into a single message, send it a new inventory message - // to trigger it to issue another getblocks message for the next - // batch of inventory. - if sendInv { - highestTipHash := sp.server.DAG.HighestTipHash() - invMsg := wire.NewMsgInvSizeHint(1) - iv := wire.NewInvVect(wire.InvTypeBlock, highestTipHash) - invMsg.AddInvVect(iv) - sp.QueueMessage(invMsg, doneChan) - sp.continueHash = nil - } return nil }