move all block sync logic to pool.
This commit is contained in:
parent
22427fe78f
commit
350ca9c875
@ -141,15 +141,6 @@ Peer.prototype._init = function init() {
|
||||
});
|
||||
};
|
||||
|
||||
Peer.prototype.startSync = function startSync() {
|
||||
if (!this.pool.options.fullNode)
|
||||
return;
|
||||
|
||||
this.pool.emit('debug', 'version (%s): sending locator hashes', this.address);
|
||||
|
||||
this.loadBlocks(this.chain.locatorHashes(), 0);
|
||||
};
|
||||
|
||||
Peer.prototype.broadcast = function broadcast(items) {
|
||||
var self = this;
|
||||
var result;
|
||||
@ -515,28 +506,6 @@ Peer.prototype._handleInv = function handleInv(items) {
|
||||
|
||||
this.emit('blocks', blocks);
|
||||
|
||||
if (this.pool.options.fullNode) {
|
||||
req = [];
|
||||
for (i = 0; i < blocks.length; i++) {
|
||||
block = blocks[i];
|
||||
hash = utils.toHex(block);
|
||||
if (this.chain.hasOrphan(hash)) {
|
||||
this.loadBlocks(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash));
|
||||
continue;
|
||||
}
|
||||
if (!this.chain.hasBlock(hash)) {
|
||||
req.push({ type: 'block', hash: block });
|
||||
continue;
|
||||
}
|
||||
if (i === blocks.length - 1) {
|
||||
this.loadBlocks(this.chain.locatorHashes(), 0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (req.length)
|
||||
this.getData(req);
|
||||
}
|
||||
|
||||
if (txs.length === 0)
|
||||
return;
|
||||
|
||||
|
||||
@ -517,7 +517,33 @@ Pool.prototype.startSync = function startSync(peer) {
|
||||
|
||||
this.syncPeer = peer;
|
||||
|
||||
peer.startSync();
|
||||
peer.on('blocks', function(hashes) {
|
||||
var req = [];
|
||||
var i, hash;
|
||||
|
||||
for (i = 0; i < hashes.length; i++) {
|
||||
hash = hashes[i];
|
||||
if (peer.chain.hasOrphan(hash)) {
|
||||
peer.loadBlocks(peer.chain.locatorHashes(), peer.chain.getOrphanRoot(hash));
|
||||
continue;
|
||||
}
|
||||
if (!peer.chain.hasBlock(hash)) {
|
||||
req.push({ type: 'block', hash: hash });
|
||||
continue;
|
||||
}
|
||||
if (i === hashes.length - 1) {
|
||||
peer.loadBlocks(peer.chain.locatorHashes(), 0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.length)
|
||||
peer.getData(req);
|
||||
});
|
||||
|
||||
this.emit('debug', 'version (%s): sending locator hashes', peer.address);
|
||||
|
||||
peer.loadBlocks(this.chain.locatorHashes(), 0);
|
||||
};
|
||||
|
||||
Pool.prototype._removePeer = function _removePeer(peer) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user