rpc: implement invalidateblock correctly.
This commit is contained in:
parent
c174bed58d
commit
290f6ab563
@ -1078,7 +1078,7 @@ Chain.prototype._reset = co(function* reset(block, silent) {
|
|||||||
Chain.prototype.replay = co(function* replay(block) {
|
Chain.prototype.replay = co(function* replay(block) {
|
||||||
var unlock = yield this.locker.lock();
|
var unlock = yield this.locker.lock();
|
||||||
try {
|
try {
|
||||||
return yield this._replay(block);
|
return yield this._replay(block, true);
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
@ -1089,10 +1089,11 @@ Chain.prototype.replay = co(function* replay(block) {
|
|||||||
* @method
|
* @method
|
||||||
* @private
|
* @private
|
||||||
* @param {Hash|Number} block - hash/height
|
* @param {Hash|Number} block - hash/height
|
||||||
|
* @param {Boolean?} silent
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Chain.prototype._replay = co(function* replay(block) {
|
Chain.prototype._replay = co(function* replay(block, silent) {
|
||||||
var entry = yield this.db.getEntry(block);
|
var entry = yield this.db.getEntry(block);
|
||||||
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
@ -1102,9 +1103,37 @@ Chain.prototype._replay = co(function* replay(block) {
|
|||||||
throw new Error('Cannot reset on alternate chain.');
|
throw new Error('Cannot reset on alternate chain.');
|
||||||
|
|
||||||
if (entry.isGenesis())
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -2020,7 +2020,7 @@ RPC.prototype.invalidateBlock = co(function* invalidateBlock(args, help) {
|
|||||||
if (!hash)
|
if (!hash)
|
||||||
throw new RPCError('Block not found.');
|
throw new RPCError('Block not found.');
|
||||||
|
|
||||||
this.chain.setInvalid(hash);
|
yield this.chain.invalidate(hash);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user