diff --git a/lib/bcoin/blockdb.js b/lib/bcoin/blockdb.js index 2ace28fc..f7115379 100644 --- a/lib/bcoin/blockdb.js +++ b/lib/bcoin/blockdb.js @@ -290,7 +290,7 @@ BlockDB.prototype.removeBlock = function removeBlock(hash, callback) { // TODO: Add check to make sure we // can ONLY remove the last block. assert(block._fileOffset >= 0); - assert(block._fileOffset < self.index.size); + assert(block._fileOffset < self.data.size); self.data.truncateAsync(block._fileOffset, function(err) { if (err) return callback(err); @@ -738,14 +738,15 @@ BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback) try { tx = bcoin.tx.fromRaw(data); entry = bcoin.chain.global.db.getSync(record.height); - assert(entry); } catch (e) { return callback(e); } tx.height = record.height; - tx.ts = entry.ts; - tx.block = entry.hash; + if (entry) { + tx.ts = entry.ts; + tx.block = entry.hash; + } txs.push(tx); if (self.options.cache) @@ -798,13 +799,14 @@ BlockDB.prototype.getTX = function getTX(hash, callback) { try { tx = bcoin.tx.fromRaw(data); entry = bcoin.chain.global.db.getSync(record.height); - assert(entry); } catch (e) { return callback(e); } tx.height = record.height; - tx.ts = entry.ts; - tx.block = entry.hash; + if (entry) { + tx.ts = entry.ts; + tx.block = entry.hash; + } tx._fileOffset = record.offset; if (self.options.paranoid && tx.hash('hex') !== hash) return callback(new Error('BlockDB is corrupt. All is lost.')); diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 5c25cec0..c9bcb751 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -922,12 +922,12 @@ Chain.prototype.syncHeight = function syncHeight(callback, force) { utils.debug('ChainDB and BlockDB are out of sync.'); if (blockHeight < chainHeight) { - utils.debug('BlockDB is higher than ChainDB. Syncing...'); + utils.debug('ChainDB is higher than BlockDB. Syncing...'); return self.resetHeightAsync(blockHeight, done, true); } if (blockHeight > chainHeight) { - utils.debug('ChainDB is higher than BlockDB. Syncing...'); + utils.debug('BlockDB is higher than ChainDB. Syncing...'); self.blockdb.resetHeight(chainHeight, function(err) { if (err) return done(err);