fix some blockdb stuff.

This commit is contained in:
Christopher Jeffrey 2016-02-19 09:19:34 -08:00
parent a558cbfb57
commit fc5187bb26
2 changed files with 11 additions and 9 deletions

View File

@ -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.'));

View File

@ -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);