mempool: extra sanity checking for mining.

This commit is contained in:
Christopher Jeffrey 2017-03-01 15:12:35 -08:00
parent 027470e8cb
commit 8977e99906
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 12 additions and 0 deletions

View File

@ -88,6 +88,7 @@ function Mempool(options) {
this.freeCount = 0;
this.lastTime = 0;
this.lastFlush = 0;
this.tip = this.network.genesis.hash;
this.waiting = {};
this.orphans = {};
@ -150,6 +151,8 @@ Mempool.prototype._open = co(function* open() {
}
}
this.tip = this.chain.tip.hash;
this.logger.info('Mempool loaded (maxsize=%dkb).', size);
});
@ -227,6 +230,8 @@ Mempool.prototype._addBlock = co(function* addBlock(block, txs) {
yield this.cache.flush();
this.tip = block.hash;
if (entries.length === 0)
return;
@ -291,6 +296,8 @@ Mempool.prototype._removeBlock = co(function* removeBlock(block, txs) {
yield this.cache.flush();
this.tip = block.prevBlock;
if (total === 0)
return;
@ -345,6 +352,8 @@ Mempool.prototype._reset = co(function* reset() {
yield this.cache.wipe();
this.cache.clear();
}
this.tip = this.chain.tip.hash;
});
/**

View File

@ -389,6 +389,9 @@ Miner.prototype.build = function build(attempt) {
if (!this.mempool)
return [];
assert(this.mempool.tip === this.chain.tip.hash,
'Mempool/chain tip mismatch! Unsafe to create block.');
hashes = this.mempool.getSnapshot();
for (i = 0; i < hashes.length; i++) {