Skip to content

Commit

Permalink
chain: wrap saveNames() in a DB batch and use _saveNames() internally
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Dec 9, 2021
1 parent db9cb2f commit 52cf446
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/blockchain/chaindb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,25 @@ class ChainDB {
*/

async saveNames(view, entry, revert) {
this.start();
try {
await this._saveNames(view, entry, revert);
} catch (e) {
this.drop();
throw e;
}
await this.commit();
}

/**
* Commit names to tree, assuming batch is started.
* @private
* @param {CoinView} view
* @param {ChainEntry} entry
* @param {Boolean} revert
*/

async _saveNames(view, entry, revert) {
for (const ns of view.names.values()) {
const {nameHash} = ns;

Expand Down Expand Up @@ -1967,7 +1986,7 @@ class ChainDB {
else
this.put(layout.w.encode(entry.height), undo.encode());

return this.saveNames(view, entry, false);
return this._saveNames(view, entry, false);
}

/**
Expand All @@ -1992,7 +2011,7 @@ class ChainDB {
this.del(layout.w.encode(entry.height));
}

return this.saveNames(view, entry, true);
return this._saveNames(view, entry, true);
}

/**
Expand Down

0 comments on commit 52cf446

Please sign in to comment.