Skip to content

Commit

Permalink
chaindb: add trigger to force rollback the tree for reorgs
Browse files Browse the repository at this point in the history
  • Loading branch information
kilpatty committed Sep 10, 2019
1 parent cc35dc2 commit cccd8e5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/blockchain/chaindb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1825,9 +1825,10 @@ class ChainDB {
* @private
* @param {CoinView} view
* @param {Number} height
* @param {Boolean} force - force a commitment threw (used for reorgs)
*/

async saveNames(view, height) {
async saveNames(view, height, force=false) {
for (const ns of view.names.values()) {
const {nameHash} = ns;

Expand All @@ -1839,7 +1840,7 @@ class ChainDB {
await this.txn.insert(nameHash, ns.encode());
}

if ((height % this.network.names.treeInterval) === 0)
if ((height % this.network.names.treeInterval) === 0 || force)
this.put(layout.s.encode(), await this.txn.commit());
}

Expand Down Expand Up @@ -1883,7 +1884,7 @@ class ChainDB {
this.del(layout.w.encode(height));
}

return this.saveNames(view, height - 1);
return this.saveNames(view, height - 1, true);
}

/**
Expand Down

0 comments on commit cccd8e5

Please sign in to comment.