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.chain.on('connect', function() {
this.node.on('connect', function() {
if (!self.attempt)
return;
@ -1745,7 +1745,7 @@ RPC.prototype._bindChain = function _bindChain() {
if (!this.mempool)
return;
this.mempool.on('tx', function() {
this.node.on('tx', function() {
if (!self.attempt)
return;

View File

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

View File

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