From ef51f4f84254d817e99ba29b859f73a406b02438 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 21 Jan 2016 03:24:29 -0800 Subject: [PATCH] chaindb: recovery. --- lib/bcoin/chain.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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+'); };