refactor orphan root.
This commit is contained in:
parent
0dc1b1cc5f
commit
c0bb66bf73
@ -1766,7 +1766,13 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
|||||||
hash = this.orphan.bmap[hash].prevBlock;
|
hash = this.orphan.bmap[hash].prevBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
if (!root)
|
||||||
|
return;
|
||||||
|
|
||||||
|
return {
|
||||||
|
root: root,
|
||||||
|
soil: this.orphan.bmap[root].prevBlock
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.getHeight = function getHeight(hash) {
|
Chain.prototype.getHeight = function getHeight(hash) {
|
||||||
|
|||||||
@ -262,35 +262,30 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan) {
|
|||||||
assert(orphan);
|
assert(orphan);
|
||||||
this.chain.onFlush(function() {
|
this.chain.onFlush(function() {
|
||||||
self.chain.getLocatorAsync(top, function(err, locator) {
|
self.chain.getLocatorAsync(top, function(err, locator) {
|
||||||
var root, soil;
|
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
throw err;
|
throw err;
|
||||||
|
|
||||||
root = self.chain.getOrphanRoot(orphan);
|
orphan = self.chain.getOrphanRoot(orphan);
|
||||||
|
|
||||||
// Was probably resolved.
|
// Was probably resolved.
|
||||||
if (!root) {
|
if (!orphan) {
|
||||||
utils.debug('Orphan root was already resolved.');
|
utils.debug('Orphan root was already resolved.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the block that would resolve the chain.
|
|
||||||
soil = self.chain.getOrphan(root).prevBlock;
|
|
||||||
|
|
||||||
// If we're already processing the block
|
// If we're already processing the block
|
||||||
// that would resolve this, ignore.
|
// that would resolve this, ignore.
|
||||||
if (self.request.map[soil] || self.chain.hasPending(soil)) {
|
if (self.request.map[orphan.soil] || self.chain.hasPending(orphan.soil)) {
|
||||||
utils.debug('Already processing orphan "soil".');
|
utils.debug('Already processing orphan "soil".');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.chain.has(soil)) {
|
if (self.chain.has(orphan.soil)) {
|
||||||
utils.debug('Already have orphan "soil". Race condition?');
|
utils.debug('Already have orphan "soil". Race condition?');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.getBlocks(locator, root);
|
peer.getBlocks(locator, orphan.root);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user