diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index ee042169..adcf3c68 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -508,7 +508,7 @@ Chain.prototype._verify = function _verify(block, prev, callback) { // Segregrated witness is now usable (the-bip-that-really-needs-to-be-rewritten) if (network.segwitHeight !== -1 && height >= network.segwitHeight) { - if (block.version >= 5 && prev.isUpgraded(5) ) { + if (block.version >= 5 && prev.isUpgraded(5)) { flags |= constants.flags.VERIFY_WITNESS; segwit = true; } diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index 3494565e..fefdf503 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -853,13 +853,8 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, opti }); } - if (key === undefined) { - return iter.end(function(err) { - if (err) - return done(err); - done(); - }); - } + if (key === undefined) + return iter.end(done); parts = key.split('/'); hash = parts[3]; @@ -954,13 +949,8 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, c }); } - if (key === undefined) { - return iter.end(function(err) { - if (err) - return done(err); - done(); - }); - } + if (key === undefined) + return iter.end(done); hash = key.split('/')[3]; @@ -1262,7 +1252,6 @@ ChainDB.prototype._getTX = function _getTX(hash, callback) { // For BIP30 // https://bitcointalk.org/index.php?topic=67738.0 ChainDB.prototype.isUnspentTX = function isUnspentTX(hash, callback) { - return callback(null, false); if (this.options.spv) return callback(null, false); return this.isSpentTX(hash, function(err, spent) { @@ -1276,8 +1265,6 @@ ChainDB.prototype.isUnspentTX = function isUnspentTX(hash, callback) { ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) { var spent = true; - return callback(null, false); - // Important! if (hash.hash) hash = hash.hash('hex'); @@ -1303,7 +1290,6 @@ ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) { spent = false; - // IMPORTANT! iter.end(done); }); })(); @@ -1396,7 +1382,9 @@ ChainDB.prototype._pruneTX = function _pruneTX(tx, batch, callback) { // they should be safe to delete anyway at the // future height. It's unlikely there will be // _another_ reorg to take over 288 blocks. - batch.put('t/q/' + futureHeight + '/' + input.prevout.hash, DUMMY); + batch.put( + 't/q/' + pad32(futureHeight) + '/' + input.prevout.hash, + DUMMY); return next(); } @@ -1456,8 +1444,8 @@ ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) { var self = this; var hashes = []; var iter = self.db.db.iterator({ - gte: 't/q/' + block.height, - lte: 't/q/' + block.height + '~', + gte: 't/q/' + pad32(block.height), + lte: 't/q/' + pad32(block.height) + '~', keys: true, values: false, fillCache: false, @@ -1466,7 +1454,7 @@ ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) { (function next() { iter.next(function(err, key, value) { - var parts, hash, index; + var parts, hash; if (err) { return iter.end(function() { @@ -1491,7 +1479,7 @@ ChainDB.prototype._pruneQueue = function _pruneQueue(block, batch, callback) { return callback(err); if (hashes.length) - utils.debug('Retroactively pruning txs at height %d', block.height); + utils.debug('Retroactively pruning txs at height %d.', block.height); utils.forEachSerial(hashes, function(hash, next) { batch.del('t/q/' + block.height + '/' + hash); diff --git a/lib/bcoin/fullnode.js b/lib/bcoin/fullnode.js index 11cfea7d..8382f95d 100644 --- a/lib/bcoin/fullnode.js +++ b/lib/bcoin/fullnode.js @@ -44,7 +44,8 @@ Fullnode.prototype._init = function _init() { this.chain = new bcoin.chain(this, { preload: false, fsync: false, - prune: false + prune: false, + useCheckpoints: false }); // Mempool needs access to blockdb. diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index 8b7e806a..fde36c50 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -1728,6 +1728,7 @@ utils.indexOf = function indexOf(arr, buf) { }; utils.pad32 = function pad32(num) { + assert(num >= 0); num = num + ''; while (num.length < 10) num = '0' + num;