From 09d699109e2ba3cecaa0d644d5f20861cd2e2eb2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 26 Aug 2016 01:13:46 -0700 Subject: [PATCH] pool: even more refactoring. --- lib/net/peer.js | 12 ++++++------ lib/net/pool.js | 14 ++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/net/peer.js b/lib/net/peer.js index 1ef9b43e..c8bc3d64 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -416,7 +416,7 @@ Peer.prototype._onAck = function _onAck(err) { // Ask for the mempool if we're synced. if (this.network.requestMempool) { - if (this.isLoader() && this.pool.synced) + if (this.isLoader() && this.chain.synced) this.sendMempool(); } @@ -1103,7 +1103,7 @@ Peer.prototype._handleGetUTXOs = function _handleGetUTXOs(payload) { unlock(); } - if (!this.pool.synced) + if (!this.chain.synced) return done(); if (this.options.selfish) @@ -1187,7 +1187,7 @@ Peer.prototype._handleGetHeaders = function _handleGetHeaders(payload) { unlock(); } - if (!this.pool.synced) + if (!this.chain.synced) return done(); if (this.options.selfish) @@ -1270,7 +1270,7 @@ Peer.prototype._handleGetBlocks = function _handleGetBlocks(payload) { unlock(); } - if (!this.pool.synced) + if (!this.chain.synced) return done(); if (this.options.selfish) @@ -1414,7 +1414,7 @@ Peer.prototype._handleMempool = function _handleMempool() { if (!this.mempool) return done(); - if (!this.pool.synced) + if (!this.chain.synced) return done(); if (this.options.selfish) @@ -2390,7 +2390,7 @@ Peer.prototype.sync = function sync(callback) { return; if (!this.isLoader()) { - if (!this.chain.isFull()) + if (!this.chain.synced) return; } diff --git a/lib/net/pool.js b/lib/net/pool.js index c2d610a1..5e3918e9 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -106,7 +106,6 @@ function Pool(options) { this.identityKey = null; this.syncing = false; - this.synced = false; this.loadTimeout = 120000; @@ -277,7 +276,7 @@ Pool.prototype._init = function _init() { self.stopTimeout(); self.stopInterval(); - if (!self.synced) { + if (!self.chain.synced) { // Ask loader for a mempool snapshot. if (self.network.requestMempool) { if (self.peers.load) @@ -288,7 +287,6 @@ Pool.prototype._init = function _init() { self.sync(); } - self.synced = true; self.emit('full'); self.logger.info('Chain is fully synced (height=%d).', self.chain.height); @@ -412,7 +410,7 @@ Pool.prototype.connect = function connect() { // chain that we can't connect and // verify yet. this.chain.on('block', function(block) { - if (!self.synced) + if (!self.chain.synced) return; self.announce(block); }); @@ -537,7 +535,7 @@ Pool.prototype.startTimeout = function startTimeout() { if (!self.syncing) return; - if (self.chain.isFull()) + if (self.chain.synced) return; if (self.peers.load) { @@ -581,7 +579,7 @@ Pool.prototype.startInterval = function startInterval() { if (!self.syncing) return; - if (self.chain.isFull()) + if (self.chain.synced) return self.stopInterval(); if (self.chain.isBusy()) @@ -883,7 +881,7 @@ Pool.prototype._handleInv = function _handleInv(hashes, peer, callback) { return; // Ignore for now if we're still syncing - if (!this.synced && !peer.isLoader()) + if (!this.chain.synced && !peer.isLoader()) return callback(); if (!this.options.headers) @@ -1182,7 +1180,7 @@ Pool.prototype.createPeer = function createPeer(addr, socket) { self.emit('txs', txs, peer); - if (self.syncing && !self.synced) + if (self.syncing && !self.chain.synced) return; for (i = 0; i < txs.length; i++) {