chaindb: recovery.

This commit is contained in:
Christopher Jeffrey 2016-01-21 03:24:29 -08:00
parent c950a30330
commit ef51f4f842

View File

@ -742,7 +742,12 @@ ChainDB.prototype._init = function _init() {
this.size = this.getSize();
assert(this.size % BLOCK_SIZE === 0);
if (this.size % BLOCK_SIZE !== 0) {
utils.debug('Blockchain is at an odd length. Truncating.');
fs.truncateSync(this.file, this.size - (this.size % BLOCK_SIZE));
this.size = this.getSize();
assert(this.size % BLOCK_SIZE === 0);
}
this.fd = fs.openSync(this.file, 'r+');
};