node: fix event race conditions.

This commit is contained in:
Christopher Jeffrey 2016-12-14 12:03:47 -08:00
parent 4353decc5a
commit 4a8c4dee57
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 30 additions and 22 deletions

View File

@ -1735,7 +1735,7 @@ RPC.prototype._bindChain = function _bindChain() {
this._boundChain = true; this._boundChain = true;
this.chain.on('connect', function() { this.node.on('connect', function() {
if (!self.attempt) if (!self.attempt)
return; return;
@ -1745,7 +1745,7 @@ RPC.prototype._bindChain = function _bindChain() {
if (!this.mempool) if (!this.mempool)
return; return;
this.mempool.on('tx', function() { this.node.on('tx', function() {
if (!self.attempt) if (!self.attempt)
return; return;

View File

@ -196,33 +196,41 @@ FullNode.prototype._init = function _init() {
}); });
this.mempool.on('tx', function(tx) { this.mempool.on('tx', function(tx) {
self.emit('tx', tx);
self.miner.notifyEntry(); self.miner.notifyEntry();
self.emit('tx', tx);
}); });
this.chain.on('block', function(block) { 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);
}
}
self.emit('block', block); self.emit('block', block);
});
this.chain.on('connect', function(entry, block) {
self.emit('connect', entry, block); self.emit('connect', entry, block);
}));
if (self.chain.synced) this.chain.on('disconnect', co(function* (entry, block) {
self.mempool.addBlock(entry, block.txs).catch(onError); if (self.chain.synced) {
}); try {
yield self.mempool.removeBlock(entry, block.txs);
this.chain.on('disconnect', function(entry, block) { } catch (e) {
self._error(e);
}
}
self.emit('disconnect', entry, block); self.emit('disconnect', entry, block);
}));
if (self.chain.synced) this.chain.on('reset', co(function* (tip) {
self.mempool.removeBlock(entry, block.txs).catch(onError); try {
}); yield self.mempool.reset();
} catch (e) {
this.chain.on('reset', function(tip) { self._error(e);
}
self.emit('reset', tip); self.emit('reset', tip);
}));
self.mempool.reset().catch(onError);
});
this.miner.on('block', function(block) { this.miner.on('block', function(block) {
self.broadcast(block.toInv()).catch(onError); self.broadcast(block.toInv()).catch(onError);

View File

@ -664,7 +664,7 @@ regtest.seeds = [
regtest.magic = 0xdab5bffa; regtest.magic = 0xdab5bffa;
regtest.port = 18444; regtest.port = 48444;
regtest.alertPrivateKey = new Buffer( regtest.alertPrivateKey = new Buffer(
'b866c595a088e2d9ea87ff4df173dd5990b1331fa9acff6aa82cc04162a63f91', 'b866c595a088e2d9ea87ff4df173dd5990b1331fa9acff6aa82cc04162a63f91',
@ -791,7 +791,7 @@ regtest.addressPrefix = {
regtest.requireStandard = false; regtest.requireStandard = false;
regtest.rpcPort = 18332; regtest.rpcPort = 48332;
regtest.minRelay = 1000; regtest.minRelay = 1000;