diff options
Diffstat (limited to 'block_pool.go')
-rw-r--r-- | block_pool.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/block_pool.go b/block_pool.go index 595400c79..02eb65d47 100644 --- a/block_pool.go +++ b/block_pool.go @@ -99,11 +99,7 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool { self.td = peer.td if !self.HasLatestHash() { - peer.doneFetchingHashes = false - - const amount = 256 - peerlogger.Debugf("Fetching hashes (%d) %x...\n", amount, peer.lastReceivedHash[0:4]) - peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)})) + self.fetchHashes() } return true @@ -112,6 +108,16 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool { return false } +func (self *BlockPool) fetchHashes() { + peer := self.peer + + peer.doneFetchingHashes = false + + const amount = 256 + peerlogger.Debugf("Fetching hashes (%d) %x...\n", amount, peer.lastReceivedHash[0:4]) + peer.QueueMessage(wire.NewMessage(wire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)})) +} + func (self *BlockPool) AddHash(hash []byte, peer *Peer) { self.mut.Lock() defer self.mut.Unlock() @@ -259,6 +265,13 @@ out: self.ChainLength = len(self.hashes) } + if self.peer != nil && + !self.peer.doneFetchingHashes && + time.Since(self.peer.lastHashAt) > 10*time.Second && + time.Since(self.peer.lastHashRequestedAt) > 5*time.Second { + self.fetchHashes() + } + /* if !self.fetchingHashes { blocks := self.Blocks() |