diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 6a8b107f..8bc94475 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -1078,7 +1078,7 @@ Chain.prototype._reset = co(function* reset(block, silent) { Chain.prototype.replay = co(function* replay(block) { var unlock = yield this.locker.lock(); try { - return yield this._replay(block); + return yield this._replay(block, true); } finally { unlock(); } @@ -1089,10 +1089,11 @@ Chain.prototype.replay = co(function* replay(block) { * @method * @private * @param {Hash|Number} block - hash/height + * @param {Boolean?} silent * @returns {Promise} */ -Chain.prototype._replay = co(function* replay(block) { +Chain.prototype._replay = co(function* replay(block, silent) { var entry = yield this.db.getEntry(block); if (!entry) @@ -1102,9 +1103,37 @@ Chain.prototype._replay = co(function* replay(block) { throw new Error('Cannot reset on alternate chain.'); if (entry.isGenesis()) - return yield this._reset(entry.hash, true); + return yield this._reset(entry.hash, silent); - yield this._reset(entry.prevBlock, true); + yield this._reset(entry.prevBlock, silent); +}); + +/** + * Invalidate block. + * @method + * @param {Hash} hash + * @returns {Promise} + */ + +Chain.prototype.invalidate = co(function* invalidate(hash) { + var unlock = yield this.locker.lock(); + try { + return yield this._invalidate(hash); + } finally { + unlock(); + } +}); + +/** + * Invalidate block (no lock). + * @method + * @param {Hash} hash + * @returns {Promise} + */ + +Chain.prototype._invalidate = co(function* _invalidate(hash) { + yield this._replay(hash, false); + this.chain.setInvalid(hash); }); /** diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 7ef69368..73cab0ff 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -2020,7 +2020,7 @@ RPC.prototype.invalidateBlock = co(function* invalidateBlock(args, help) { if (!hash) throw new RPCError('Block not found.'); - this.chain.setInvalid(hash); + yield this.chain.invalidate(hash); return null; });