Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool event proxying - pass in peer and emit blocks and txs event from INV #10

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bcoin/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Chain.prototype.has = function has(hash, noProbe, cb) {
}
if (this.loading) {
this.once('load', function() {
this.has(hash, cb);
this.has(hash, noProbe, cb);
});
return;
}
Expand All @@ -297,7 +297,7 @@ Chain.prototype.has = function has(hash, noProbe, cb) {

if (!noProbe && this.index.bloom.test(hash, 'hex')) {
// XXX find hash
return true;
return cb(true);
}

return cb(!!this.orphan.map[hash]);
Expand Down
3 changes: 3 additions & 0 deletions lib/bcoin/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ Peer.prototype._handleInv = function handleInv(items) {
if (txs.length === 0)
return;

this.emit('txs', txs.map(function(tx) {
return tx.hash;
}));
this.getData(txs);
};

Expand Down
18 changes: 13 additions & 5 deletions lib/bcoin/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ Pool.prototype._addPeer = function _addPeer(backoff) {

self._response(block);
self.chain.add(block);
self.emit('chain-progress', self.chain.fillPercent());
self.emit('block', block);
self.emit('chain-progress', self.chain.fillPercent(), peer);
self.emit('block', block, peer);
});

// Just FYI
peer.on('reject', function(payload) {
self.emit('reject', payload);
self.emit('reject', payload, peer);
});

peer.on('notfound', function(items) {
Expand All @@ -308,11 +308,19 @@ Pool.prototype._addPeer = function _addPeer(backoff) {

peer.on('tx', function(tx) {
self._response(tx);
self.emit('tx', tx);
self.emit('tx', tx, peer);
});

peer.on('addr', function(addr) {
self.emit('addr', addr);
self.emit('addr', addr, peer);
});

peer.on('blocks', function(blocks) {
self.emit('blocks', blocks, peer);
});

peer.on('txs', function(txs) {
self.emit('txs', txs, peer);
});
};

Expand Down