chaindb: refactor reset and removeChain.
This commit is contained in:
parent
e68a64d1f9
commit
51e3228d83
@ -1346,7 +1346,7 @@ ChainDB.prototype.reset = co(function* reset(block) {
|
|||||||
|
|
||||||
this.logger.debug('Resetting main chain to: %s', entry.rhash);
|
this.logger.debug('Resetting main chain to: %s', entry.rhash);
|
||||||
|
|
||||||
while (!tip.isGenesis()) {
|
for (;;) {
|
||||||
this.start();
|
this.start();
|
||||||
|
|
||||||
if (tip.hash === entry.hash) {
|
if (tip.hash === entry.hash) {
|
||||||
@ -1355,6 +1355,8 @@ ChainDB.prototype.reset = co(function* reset(block) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(!tip.isGenesis());
|
||||||
|
|
||||||
this.del(layout.H(tip.height));
|
this.del(layout.H(tip.height));
|
||||||
this.del(layout.h(tip.hash));
|
this.del(layout.h(tip.hash));
|
||||||
this.del(layout.e(tip.hash));
|
this.del(layout.e(tip.hash));
|
||||||
@ -1391,24 +1393,29 @@ ChainDB.prototype.reset = co(function* reset(block) {
|
|||||||
ChainDB.prototype.removeChain = co(function* removeChain(tip, entry) {
|
ChainDB.prototype.removeChain = co(function* removeChain(tip, entry) {
|
||||||
this.logger.debug('Removing alternate chain: %s->%s', tip.rhash, entry.rhash);
|
this.logger.debug('Removing alternate chain: %s->%s', tip.rhash, entry.rhash);
|
||||||
|
|
||||||
while (!tip.isGenesis()) {
|
this.start();
|
||||||
|
|
||||||
|
for (;;) }
|
||||||
if (tip.hash === entry.hash)
|
if (tip.hash === entry.hash)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
this.start();
|
if (tip.isGenesis()) {
|
||||||
|
this.drop();
|
||||||
|
throw new Error('Target entry not in chain.');
|
||||||
|
}
|
||||||
|
|
||||||
this.del(layout.h(tip.hash));
|
this.del(layout.h(tip.hash));
|
||||||
this.del(layout.e(tip.hash));
|
this.del(layout.e(tip.hash));
|
||||||
this.del(layout.b(tip.hash));
|
this.del(layout.b(tip.hash));
|
||||||
|
|
||||||
yield this.commit();
|
this.cacheHash.unpush(tip.hash);
|
||||||
|
|
||||||
this.cacheHash.remove(tip.hash);
|
|
||||||
|
|
||||||
tip = yield this.get(tip.prevBlock);
|
tip = yield this.get(tip.prevBlock);
|
||||||
assert(tip);
|
assert(tip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yield this.commit();
|
||||||
|
|
||||||
return tip;
|
return tip;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user