From b0ee614432f772b2ba6a758d8f94c92c2b8c4a27 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 31 Jan 2016 00:50:13 -0800 Subject: [PATCH] misc sync fixes. --- README.md | 1 + lib/bcoin/peer.js | 2 -- lib/bcoin/pool.js | 22 +++++++++------------- lib/bcoin/tx.js | 2 +- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 50bf00ef..3b79842e 100644 --- a/README.md +++ b/README.md @@ -1572,6 +1572,7 @@ Usage: `bcoin.tx([options], [block])` - __fill(wallet/txpool/object)__ - Fills all the transaction's inputs with the appropriate previous outputs using the available transactions in a wallet, txpool, or an object with txids as its keys and txs as its values. +- __isFull()__ - Returns true if the TX has all previous output references. - __isFinal(height, ts)__ - Mimics the bitcoind `IsFinalTx()` function. Checks the locktime and input sequences. Returns true or false. - __getSigops([scripthash], [accurate])__ - Count sigops in transaction. Set diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 1598c258..dc8fda6b 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -123,7 +123,6 @@ Peer.prototype._init = function init() { self._error(err); // Something is wrong here. // Ignore this peer. - self.destroy(); self.pool.misbehaving(self, 100); }); @@ -146,7 +145,6 @@ Peer.prototype._init = function init() { if (err) { self._error(err); self.destroy(); - self.pool.misbehaving(self, 100); return; } self.ack = true; diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index b178e108..b3ab0d8c 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -242,6 +242,7 @@ Pool.prototype._startTimer = function _startTimer() { // Chain is full and up-to-date if (self.chain.isFull()) { self._stopTimer(); + self._stopInterval(); self.synced = true; self.emit('full'); utils.debug('Chain is fully synced (height=%d).', self.chain.height()); @@ -346,11 +347,10 @@ Pool.prototype._addLoader = function _addLoader() { }); peer.once('ack', function() { + peer.updateWatch(); if (!self.syncing) return; - peer.updateWatch(); - if (!self._load()) - self._stopTimer(); + self._load(); }); peer.on('merkleblock', function(block) { @@ -410,10 +410,8 @@ Pool.prototype.startSync = function startSync() { return; } - if (this.peers.load.ack) { - if (!this._load()) - this._stopTimer(); - } + if (this.peers.load.ack) + this._load(); }; Pool.prototype.stopSync = function stopSync() { @@ -693,19 +691,17 @@ Pool.prototype._load = function _load() { var next; if (!this.syncing) - return true; + return; if (!this.peers.load) { this._addLoader(); - return true; + return; } if (this.options.headers) this.peers.load.loadHeaders(this.chain.locatorHashes(), null); else this.peers.load.loadBlocks(this.chain.locatorHashes(), null); - - return true; }; Pool.prototype.loadMempool = function loadMempool() { @@ -1447,7 +1443,7 @@ Pool.prototype.sendTX = function sendTX(tx) { // bitcoind nodes. Possibly check // sigops. Call isStandard and/or // isStandardInputs as well. - if (tx.full()) { + if (tx.isFull()) { if (!tx.verify(null, true)) { utils.debug( 'Could not relay TX (%s). It does not verify.', @@ -1606,7 +1602,7 @@ Pool.prototype.getSeed = function getSeed(priority, connecting) { utils.debug( 'We had to connect to a random peer. Something is not right.'); - return seeds[Math.random() * (seeds.length - 1) | 0]; + return original[Math.random() * (original.length - 1) | 0]; } }; diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 43d23275..a9eab006 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1130,7 +1130,7 @@ TX.prototype.increaseFee = function increaseFee(fee) { } }; -TX.prototype.full = function full() { +TX.prototype.isFull = function isFull() { if (this.inputs.length === 0) return false; return this.inputs.every(function(input) {