update getheaders sync.
This commit is contained in:
parent
62caf5fd4a
commit
0af709388c
@ -415,17 +415,14 @@ Peer.prototype._onPacket = function onPacket(packet) {
|
|||||||
return this._handleReject(payload);
|
return this._handleReject(payload);
|
||||||
|
|
||||||
if (cmd === 'block') {
|
if (cmd === 'block') {
|
||||||
payload.network = true;
|
|
||||||
payload.relayedBy = this.host || '0.0.0.0';
|
payload.relayedBy = this.host || '0.0.0.0';
|
||||||
payload = bcoin.block(payload);
|
payload = bcoin.block(payload);
|
||||||
} else if (cmd === 'merkleblock') {
|
} else if (cmd === 'merkleblock') {
|
||||||
payload.network = true;
|
|
||||||
payload.relayedBy = this.host || '0.0.0.0';
|
payload.relayedBy = this.host || '0.0.0.0';
|
||||||
payload = bcoin.merkleblock(payload);
|
payload = bcoin.merkleblock(payload);
|
||||||
this.lastBlock = payload;
|
this.lastBlock = payload;
|
||||||
return;
|
return;
|
||||||
} else if (cmd === 'tx') {
|
} else if (cmd === 'tx') {
|
||||||
payload.network = true;
|
|
||||||
payload.relayedBy = this.host || '0.0.0.0';
|
payload.relayedBy = this.host || '0.0.0.0';
|
||||||
payload = bcoin.tx(payload, this.lastBlock);
|
payload = bcoin.tx(payload, this.lastBlock);
|
||||||
if (this.lastBlock) {
|
if (this.lastBlock) {
|
||||||
@ -602,11 +599,7 @@ Peer.prototype._handleInv = function handleInv(items) {
|
|||||||
|
|
||||||
Peer.prototype._handleHeaders = function handleHeaders(headers) {
|
Peer.prototype._handleHeaders = function handleHeaders(headers) {
|
||||||
headers = headers.map(function(header) {
|
headers = headers.map(function(header) {
|
||||||
header._hash = utils.dsha256(header._raw);
|
return new bcoin.headers(header);
|
||||||
header.hash = utils.toHex(header._hash);
|
|
||||||
header.prevBlock = utils.toHex(header.prevBlock);
|
|
||||||
header.merkleRoot = utils.toHex(header.merkleRoot);
|
|
||||||
return header;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.emit('headers', headers);
|
this.emit('headers', headers);
|
||||||
|
|||||||
@ -539,19 +539,18 @@ 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++) {
|
||||||
header = headers[i];
|
header = headers[i];
|
||||||
|
hash = header.hash('hex');
|
||||||
|
|
||||||
if (last && header.prevBlock !== last.hash)
|
if (last && header.prevBlock !== last)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!utils.testTarget(header.bits, header._hash)) {
|
if (!header.verify())
|
||||||
utils.debug('Header failed POW test.');
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (!self.chain.has(header.hash))
|
if (!self.chain.has(hash))
|
||||||
self.getData(peer, self.block.type, header.hash);
|
self.getData(peer, self.block.type, hash);
|
||||||
|
|
||||||
last = header;
|
last = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart the getheaders process
|
// Restart the getheaders process
|
||||||
@ -562,7 +561,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.hash, null);
|
self.getHeaders(peer, last, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset interval to avoid calling getheaders unnecessarily
|
// Reset interval to avoid calling getheaders unnecessarily
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user