From e405dd59814941dfd2994d668eb472b6ea96e865 Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Tue, 18 Feb 2020 12:12:34 +0200 Subject: [PATCH] [NOD-694] Fix requesting blocks that will surely be orphaned during netsync. (#630) --- netsync/manager.go | 4 ++-- server/rpc/handle_get_block_template.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/netsync/manager.go b/netsync/manager.go index ba3de9a73..c428c7d52 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -414,12 +414,12 @@ func (sm *SyncManager) handleTxMsg(tmsg *txMsg) { // current returns true if we believe we are synced with our peers, false if we // still have blocks to check // -// We consider ourselves current iff at least one of the following is true: +// We consider ourselves current iff both of the following are true: // 1. there's no syncPeer, a.k.a. all connected peers are at the same tip // 2. the DAG considers itself current - to prevent attacks where a peer sends an // unknown tip but never lets us sync to it. func (sm *SyncManager) current() bool { - return sm.syncPeer == nil || sm.dag.IsCurrent() + return sm.syncPeer == nil && sm.dag.IsCurrent() } // restartSyncIfNeeded finds a new sync candidate if we're not expecting any diff --git a/server/rpc/handle_get_block_template.go b/server/rpc/handle_get_block_template.go index 9251da18f..c9e96a7fb 100644 --- a/server/rpc/handle_get_block_template.go +++ b/server/rpc/handle_get_block_template.go @@ -109,7 +109,7 @@ func handleGetBlockTemplate(s *Server, cmd interface{}, closeChan <-chan struct{ // we have nothing besides the genesis block (blueScore == 0), // because in that state IsCurrent may still return true. currentBlueScore := s.cfg.DAG.SelectedTipBlueScore() - if (currentBlueScore != 0 && !s.cfg.SyncMgr.IsCurrent()) || + if (currentBlueScore != 0 && !s.cfg.DAG.IsCurrent()) || (currentBlueScore == 0 && !s.cfg.shouldMineOnGenesis()) { return nil, &rpcmodel.RPCError{ Code: rpcmodel.ErrRPCClientInInitialDownload,