fixes for perf.
This commit is contained in:
parent
e2817436de
commit
1ef834ca3e
@ -365,6 +365,12 @@ Peer.prototype.sendInv = function sendInv(items) {
|
|||||||
inv.push(item);
|
inv.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inv.length === 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bcoin.debug('Serving %d inv items to %s.',
|
||||||
|
inv.length, this.hostname);
|
||||||
|
|
||||||
for (i = 0; i < inv.length; i += 50000) {
|
for (i = 0; i < inv.length; i += 50000) {
|
||||||
chunk = inv.slice(i, i + 50000);
|
chunk = inv.slice(i, i + 50000);
|
||||||
this.write(this.framer.inv(chunk));
|
this.write(this.framer.inv(chunk));
|
||||||
@ -392,6 +398,12 @@ Peer.prototype.sendHeaders = function sendHeaders(items) {
|
|||||||
headers.push(item);
|
headers.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headers.length === 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bcoin.debug('Serving %d headers to %s.',
|
||||||
|
headers.length, this.hostname);
|
||||||
|
|
||||||
for (i = 0; i < headers.length; i += 2000) {
|
for (i = 0; i < headers.length; i += 2000) {
|
||||||
chunk = headers.slice(i, i + 2000);
|
chunk = headers.slice(i, i + 2000);
|
||||||
this.write(this.framer.headers(chunk));
|
this.write(this.framer.headers(chunk));
|
||||||
@ -850,6 +862,9 @@ Peer.prototype._handleGetUTXOs = function _handleGetUTXOs(payload) {
|
|||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.pool.synced)
|
||||||
|
return done();
|
||||||
|
|
||||||
if (this.pool.options.selfish)
|
if (this.pool.options.selfish)
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
@ -950,6 +965,9 @@ Peer.prototype._handleGetHeaders = function _handleGetHeaders(payload) {
|
|||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.pool.synced)
|
||||||
|
return done();
|
||||||
|
|
||||||
if (this.pool.options.selfish)
|
if (this.pool.options.selfish)
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
@ -1024,6 +1042,9 @@ Peer.prototype._handleGetBlocks = function _handleGetBlocks(payload) {
|
|||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.pool.synced)
|
||||||
|
return done();
|
||||||
|
|
||||||
if (this.pool.options.selfish)
|
if (this.pool.options.selfish)
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
@ -1150,6 +1171,9 @@ Peer.prototype._handleMempool = function _handleMempool() {
|
|||||||
if (!this.mempool)
|
if (!this.mempool)
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
|
if (!this.pool.synced)
|
||||||
|
return done();
|
||||||
|
|
||||||
if (this.pool.options.selfish)
|
if (this.pool.options.selfish)
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
@ -1368,8 +1392,7 @@ Peer.prototype._handleGetData = function _handleGetData(items) {
|
|||||||
|
|
||||||
Peer.prototype._handleAddr = function _handleAddr(addrs) {
|
Peer.prototype._handleAddr = function _handleAddr(addrs) {
|
||||||
var hosts = [];
|
var hosts = [];
|
||||||
var now = utils.now();
|
var i, addr;
|
||||||
var i, addr, ts;
|
|
||||||
|
|
||||||
for (i = 0; i < addrs.length; i++) {
|
for (i = 0; i < addrs.length; i++) {
|
||||||
addr = new NetworkAddress(addrs[i]);
|
addr = new NetworkAddress(addrs[i]);
|
||||||
@ -1454,7 +1477,7 @@ Peer.prototype._handleGetAddr = function _handleGetAddr() {
|
|||||||
items.length,
|
items.length,
|
||||||
this.hostname);
|
this.hostname);
|
||||||
|
|
||||||
return this.write(this.framer.addr(items));
|
this.write(this.framer.addr(items));
|
||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype._handleInv = function _handleInv(items) {
|
Peer.prototype._handleInv = function _handleInv(items) {
|
||||||
@ -1462,8 +1485,6 @@ Peer.prototype._handleInv = function _handleInv(items) {
|
|||||||
var txs = [];
|
var txs = [];
|
||||||
var i, item, unknown;
|
var i, item, unknown;
|
||||||
|
|
||||||
this.fire('inv', items);
|
|
||||||
|
|
||||||
for (i = 0; i < items.length; i++) {
|
for (i = 0; i < items.length; i++) {
|
||||||
item = items[i];
|
item = items[i];
|
||||||
if (item.type === constants.inv.TX) {
|
if (item.type === constants.inv.TX) {
|
||||||
@ -1477,6 +1498,8 @@ Peer.prototype._handleInv = function _handleInv(items) {
|
|||||||
this.invFilter.add(item.hash, 'hex');
|
this.invFilter.add(item.hash, 'hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.fire('inv', items);
|
||||||
|
|
||||||
if (blocks.length > 0)
|
if (blocks.length > 0)
|
||||||
this.emit('blocks', blocks);
|
this.emit('blocks', blocks);
|
||||||
|
|
||||||
@ -1539,7 +1562,7 @@ Peer.prototype.getHeaders = function getHeaders(locator, stop) {
|
|||||||
'Requesting headers packet from peer with getheaders (%s).',
|
'Requesting headers packet from peer with getheaders (%s).',
|
||||||
this.hostname);
|
this.hostname);
|
||||||
|
|
||||||
bcoin.debug('Height: %s, Hash: %s, Stop: %s',
|
bcoin.debug('Height: %d, Hash: %s, Stop: %s',
|
||||||
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : -1,
|
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : -1,
|
||||||
locator && locator.length ? utils.revHex(locator[0]) : 0,
|
locator && locator.length ? utils.revHex(locator[0]) : 0,
|
||||||
stop ? utils.revHex(stop) : 0);
|
stop ? utils.revHex(stop) : 0);
|
||||||
@ -1558,8 +1581,8 @@ Peer.prototype.getBlocks = function getBlocks(locator, stop) {
|
|||||||
'Requesting inv packet from peer with getblocks (%s).',
|
'Requesting inv packet from peer with getblocks (%s).',
|
||||||
this.hostname);
|
this.hostname);
|
||||||
|
|
||||||
bcoin.debug('Height: %s, Hash: %s, Stop: %s',
|
bcoin.debug('Height: %d, Hash: %s, Stop: %s',
|
||||||
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : null,
|
locator && locator.length ? this.chain._getCachedHeight(locator[0]) : -1,
|
||||||
locator && locator.length ? utils.revHex(locator[0]) : 0,
|
locator && locator.length ? utils.revHex(locator[0]) : 0,
|
||||||
stop ? utils.revHex(stop) : 0);
|
stop ? utils.revHex(stop) : 0);
|
||||||
|
|
||||||
|
|||||||
@ -52,9 +52,7 @@ Profile.prototype.stopProfiling = function stopProfiling() {
|
|||||||
if (!v8profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.profile);
|
this.profile = v8profiler.stopProfiling(this.name);
|
||||||
|
|
||||||
return this.profile.stopProfiling();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,9 +63,7 @@ Profile.prototype.del = function del() {
|
|||||||
if (!v8profiler)
|
if (!v8profiler)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.profile);
|
this.profile['delete']();
|
||||||
|
|
||||||
return this.profile['delete']();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +79,8 @@ Profile.prototype.save = function save(callback) {
|
|||||||
if (!v8profiler)
|
if (!v8profiler)
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
assert(this.profile);
|
if (!this.profile)
|
||||||
|
this.stopProfiling();
|
||||||
|
|
||||||
bcoin.debug('Saving CPU profile: %s', this.name);
|
bcoin.debug('Saving CPU profile: %s', this.name);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user