diff --git a/lib/chain/chaindb.js b/lib/chain/chaindb.js index bf53ca0f..827934cb 100644 --- a/lib/chain/chaindb.js +++ b/lib/chain/chaindb.js @@ -1520,7 +1520,7 @@ ChainDB.prototype.hasCoins = function hasCoins(hash) { */ ChainDB.prototype.pruneBlock = co(function* pruneBlock(block) { - var futureHeight, key, hash, data; + var futureHeight, key, hash; if (this.options.spv) return; diff --git a/lib/net/bip152.js b/lib/net/bip152.js index f6853b58..20d16d64 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -8,6 +8,7 @@ var bcoin = require('../env'); var utils = require('../utils/utils'); +var spawn = require('../utils/spawn'); var crypto = require('../crypto/crypto'); var assert = utils.assert; var constants = bcoin.constants; @@ -363,7 +364,7 @@ CompactBlock.fromBlock = function fromBlock(block, nonce) { return new CompactBlock().fromBlock(block, nonce); }; -CompactBlock.prototype.wait = function wait(callback) { +CompactBlock.prototype.wait = function wait(time) { var self = this; return new Promise(function(resolve, reject) { self._wait(time, spawn.wrap(resolve, reject)); diff --git a/lib/net/peer.js b/lib/net/peer.js index d3b0c7c5..1196be2b 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -466,6 +466,8 @@ Peer.prototype._finalize = co(function* _finalize() { // Start syncing the chain. this.sync(); + + yield spawn.wait(); }); /** @@ -1347,8 +1349,6 @@ Peer.prototype.__handleGetBlocks = co(function* _handleGetBlocks(packet) { */ Peer.prototype._handleVersion = co(function* _handleVersion(version) { - var self = this; - if (!this.network.selfConnect) { if (version.nonce.cmp(this.pool.localNonce) === 0) { this.error('We connected to ourself. Oops.'); @@ -2128,13 +2128,13 @@ Peer.prototype._handleGetBlockTxn = co(function* _handleGetBlockTxn(packet) { var res, item, block; if (this.chain.db.options.spv) - return done(); + return; if (this.chain.db.options.prune) - return done(); + return; if (this.options.selfish) - return done(); + return; item = new InvItem(constants.inv.BLOCK, req.hash); diff --git a/lib/net/pool.js b/lib/net/pool.js index 42675a69..c6fd26a5 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -721,6 +721,15 @@ Pool.prototype._handleHeaders = co(function* _handleHeaders(headers, peer) { } }); +/** + * Handle `headers` packet from + * a given peer without a lock. + * @private + * @param {Headers[]} headers + * @param {Peer} peer + * @param {Function} callback + */ + Pool.prototype.__handleHeaders = co(function* _handleHeaders(headers, peer) { var i, ret, header, hash, last; @@ -773,7 +782,7 @@ Pool.prototype.__handleHeaders = co(function* _handleHeaders(headers, peer) { // simply tries to find the latest block in // the peer's chain. if (last && headers.length === 2000) - yield peer.getHeaders(last, null); + yield peer.getHeaders(last); }); /** @@ -861,6 +870,14 @@ Pool.prototype._handleInv = co(function* _handleInv(hashes, peer) { } }); +/** + * Handle `inv` packet from peer without a lock. + * @private + * @param {Hash[]} hashes + * @param {Peer} peer + * @param {Function} callback + */ + Pool.prototype.__handleInv = co(function* _handleInv(hashes, peer) { var i, hash; @@ -1060,7 +1077,7 @@ Pool.prototype.createPeer = function createPeer(addr, socket) { try { yield self._handleBlock(block, peer); } catch (e) { - self.emit('error', err); + self.emit('error', e); return; } diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index ba54de54..e4e593f3 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -1311,7 +1311,7 @@ WalletDB.prototype._addBlock = co(function* addBlock(entry, txs) { WalletDB.prototype.removeBlock = co(function* removeBlock(entry) { var unlock = yield this.txLock.lock(); try { - return yield this._removeBlock(entry, txs); + return yield this._removeBlock(entry); } finally { unlock(); } diff --git a/test/chain-test.js b/test/chain-test.js index 3d8e72bd..3688720a 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -217,7 +217,7 @@ describe('Chain', function() { assert.ifError(err); // assert.equal(balance.unconfirmed, 23000000000); // assert.equal(balance.confirmed, 97000000000); - // assert.equal(balance.total, 120000000000); + assert.equal(balance.total, 120000000000); // assert.equal(wallet.account.receiveDepth, 8); // assert.equal(wallet.account.changeDepth, 7); assert.equal(walletdb.height, chain.height);