Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coin count and value statistics #960

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
39 changes: 29 additions & 10 deletions lib/blockchain/chaindb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,35 @@ class ChainDB {
return undefined;

// Update chain state value.
this.updateChainState(entry, block, view);

// Commit new coin state.
this.saveView(view);

// Write undo coins (if there are any).
if (!view.undo.isEmpty())
await this.blocks.writeUndo(hash, view.undo.commit());

// Prune height-288 if pruning is enabled.
return this.pruneBlock(entry);
}

/**
* Update chain state with coins.
* @param {ChainEntry} entry
* @param {Block} block
* @param {CoinView} view
*/

updateChainState(entry, block, view) {
const hash = this.network.bip30[entry.height];

// Blocks 91842 and 91880 created duplicate
// txids and should not increment or decrement
// the statistics.
if (hash && hash.equals(entry.hash))
return;

pinheadmz marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 0; i < block.txs.length; i++) {
const tx = block.txs[i];

Expand All @@ -1553,16 +1582,6 @@ class ChainDB {
this.pending.add(output);
}
}

// Commit new coin state.
this.saveView(view);

// Write undo coins (if there are any).
if (!view.undo.isEmpty())
await this.blocks.writeUndo(hash, view.undo.commit());

// Prune height-288 if pruning is enabled.
return this.pruneBlock(entry);
}

/**
Expand Down