fix some blockdb stuff.
This commit is contained in:
parent
a558cbfb57
commit
fc5187bb26
@ -290,7 +290,7 @@ BlockDB.prototype.removeBlock = function removeBlock(hash, callback) {
|
|||||||
// TODO: Add check to make sure we
|
// TODO: Add check to make sure we
|
||||||
// can ONLY remove the last block.
|
// can ONLY remove the last block.
|
||||||
assert(block._fileOffset >= 0);
|
assert(block._fileOffset >= 0);
|
||||||
assert(block._fileOffset < self.index.size);
|
assert(block._fileOffset < self.data.size);
|
||||||
self.data.truncateAsync(block._fileOffset, function(err) {
|
self.data.truncateAsync(block._fileOffset, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -738,14 +738,15 @@ BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback)
|
|||||||
try {
|
try {
|
||||||
tx = bcoin.tx.fromRaw(data);
|
tx = bcoin.tx.fromRaw(data);
|
||||||
entry = bcoin.chain.global.db.getSync(record.height);
|
entry = bcoin.chain.global.db.getSync(record.height);
|
||||||
assert(entry);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return callback(e);
|
return callback(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.height = record.height;
|
tx.height = record.height;
|
||||||
tx.ts = entry.ts;
|
if (entry) {
|
||||||
tx.block = entry.hash;
|
tx.ts = entry.ts;
|
||||||
|
tx.block = entry.hash;
|
||||||
|
}
|
||||||
txs.push(tx);
|
txs.push(tx);
|
||||||
|
|
||||||
if (self.options.cache)
|
if (self.options.cache)
|
||||||
@ -798,13 +799,14 @@ BlockDB.prototype.getTX = function getTX(hash, callback) {
|
|||||||
try {
|
try {
|
||||||
tx = bcoin.tx.fromRaw(data);
|
tx = bcoin.tx.fromRaw(data);
|
||||||
entry = bcoin.chain.global.db.getSync(record.height);
|
entry = bcoin.chain.global.db.getSync(record.height);
|
||||||
assert(entry);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return callback(e);
|
return callback(e);
|
||||||
}
|
}
|
||||||
tx.height = record.height;
|
tx.height = record.height;
|
||||||
tx.ts = entry.ts;
|
if (entry) {
|
||||||
tx.block = entry.hash;
|
tx.ts = entry.ts;
|
||||||
|
tx.block = entry.hash;
|
||||||
|
}
|
||||||
tx._fileOffset = record.offset;
|
tx._fileOffset = record.offset;
|
||||||
if (self.options.paranoid && tx.hash('hex') !== hash)
|
if (self.options.paranoid && tx.hash('hex') !== hash)
|
||||||
return callback(new Error('BlockDB is corrupt. All is lost.'));
|
return callback(new Error('BlockDB is corrupt. All is lost.'));
|
||||||
|
|||||||
@ -922,12 +922,12 @@ Chain.prototype.syncHeight = function syncHeight(callback, force) {
|
|||||||
utils.debug('ChainDB and BlockDB are out of sync.');
|
utils.debug('ChainDB and BlockDB are out of sync.');
|
||||||
|
|
||||||
if (blockHeight < chainHeight) {
|
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);
|
return self.resetHeightAsync(blockHeight, done, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockHeight > chainHeight) {
|
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) {
|
self.blockdb.resetHeight(chainHeight, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return done(err);
|
return done(err);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user