fullnode: fix persistent mempool block addition/removal.
This commit is contained in:
parent
c2b8dc37c7
commit
e52eebd652
@ -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');
|
||||
|
||||
@ -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);
|
||||
}));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user