getheaders. better pow test.
This commit is contained in:
parent
a3b2149c1f
commit
95a5d2c47b
@ -601,12 +601,11 @@ Peer.prototype._handleInv = function handleInv(items) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype._handleHeaders = function handleHeaders(headers) {
|
Peer.prototype._handleHeaders = function handleHeaders(headers) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
headers = headers.map(function(header) {
|
headers = headers.map(function(header) {
|
||||||
|
header._hash = utils.dsha256(header._raw);
|
||||||
|
header.hash = utils.toHex(header._hash);
|
||||||
header.prevBlock = utils.toHex(header.prevBlock);
|
header.prevBlock = utils.toHex(header.prevBlock);
|
||||||
header.merkleRoot = utils.toHex(header.merkleRoot);
|
header.merkleRoot = utils.toHex(header.merkleRoot);
|
||||||
header.hash = utils.toHex(utils.dsha256(header._raw));
|
|
||||||
return header;
|
return header;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@ function Pool(options) {
|
|||||||
options.headers = true;
|
options.headers = true;
|
||||||
} else {
|
} else {
|
||||||
if (options.headers == null)
|
if (options.headers == null)
|
||||||
options.headers = false;
|
options.headers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
@ -534,18 +534,20 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
|
|||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.onFlush(function() {
|
||||||
for (i = 0; i < headers.length; i++) {
|
for (i = 0; i < headers.length; i++) {
|
||||||
block = bcoin.block(headers[i], 'header');
|
header = headers[i];
|
||||||
|
|
||||||
if (last && block.prevBlock !== last.hash('hex'))
|
if (last && header.prevBlock !== last.hash)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!block.verify())
|
if (!utils.testTarget(header.bits, header._hash)) {
|
||||||
|
utils.debug('Header failed POW test.');
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!self.chain.has(block))
|
if (!self.chain.has(header.hash))
|
||||||
self.getData(peer, self.block.type, block.hash('hex'));
|
self.getData(peer, self.block.type, header.hash);
|
||||||
|
|
||||||
last = block;
|
last = header;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart the getheaders process
|
// Restart the getheaders process
|
||||||
@ -556,7 +558,7 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
|
|||||||
// simply tries to find the latest block in
|
// simply tries to find the latest block in
|
||||||
// the peer's chain.
|
// the peer's chain.
|
||||||
if (last && headers.length === 2000)
|
if (last && headers.length === 2000)
|
||||||
self.getHeaders(peer, last, null);
|
self.getHeaders(peer, last.hash, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset interval to avoid calling getheaders unnecessarily
|
// Reset interval to avoid calling getheaders unnecessarily
|
||||||
|
|||||||
@ -876,9 +876,7 @@ utils.testTarget = function testTarget(target, hash) {
|
|||||||
if (typeof hash === 'string')
|
if (typeof hash === 'string')
|
||||||
hash = new Buffer(hash, 'hex');
|
hash = new Buffer(hash, 'hex');
|
||||||
|
|
||||||
hash = Array.prototype.slice.call(hash);
|
return new bn(hash, 'le').cmp(target) < 0;
|
||||||
|
|
||||||
return new bn(hash.slice().reverse()).cmp(target) < 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.now = function now() {
|
utils.now = function now() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user