fullnode: fix persistent mempool block addition/removal.

This commit is contained in:
Christopher Jeffrey 2017-03-05 13:01:30 -08:00
parent c2b8dc37c7
commit e52eebd652
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 18 additions and 12 deletions

View File

@ -199,6 +199,11 @@ Mempool.prototype._addBlock = co(function* addBlock(block, txs) {
var entries = [];
var i, entry, tx, hash;
if (this.totalTX === 0) {
this.tip = block.hash;
return;
}
for (i = txs.length - 1; i >= 1; i--) {
tx = txs[i];
hash = tx.hash('hex');
@ -273,6 +278,11 @@ Mempool.prototype._removeBlock = co(function* removeBlock(block, txs) {
var total = 0;
var i, tx, hash;
if (this.totalTX === 0) {
this.tip = block.prevBlock;
return;
}
for (i = 1; i < txs.length; i++) {
tx = txs[i];
hash = tx.hash('hex');

View File

@ -188,24 +188,20 @@ FullNode.prototype._init = function _init() {
});
this.chain.on('connect', co(function* (entry, block) {
if (self.chain.synced) {
try {
yield self.mempool.addBlock(entry, block.txs);
} catch (e) {
self.error(e);
}
try {
yield self.mempool.addBlock(entry, block.txs);
} catch (e) {
self.error(e);
}
self.emit('block', block);
self.emit('connect', entry, block);
}));
this.chain.on('disconnect', co(function* (entry, block) {
if (self.chain.synced) {
try {
yield self.mempool.removeBlock(entry, block.txs);
} catch (e) {
self.error(e);
}
try {
yield self.mempool.removeBlock(entry, block.txs);
} catch (e) {
self.error(e);
}
self.emit('disconnect', entry, block);
}));