diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index ed3bbd36..ca2c82a4 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -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+'); };