add chain.hasOrphan method.

This commit is contained in:
Christopher Jeffrey 2015-12-18 16:57:37 -08:00
parent e735249d0d
commit d1f8e9b5ff
2 changed files with 15 additions and 3 deletions

View File

@ -381,13 +381,26 @@ Chain.prototype.has = function has(hash, noProbe, cb) {
return cb(!!this.orphan.map[hash]); return cb(!!this.orphan.map[hash]);
}; };
Chain.prototype.hasBlock = function hasBlock(hash, noProbe, strict) { Chain.prototype.hasBlock = function hasBlock(hash) {
if (this.loading) if (this.loading)
return false; return false;
if (Array.isArray(hash))
hash = utils.toHex(hash);
return this.index.bloom.test(hash, 'hex'); return this.index.bloom.test(hash, 'hex');
}; };
Chain.prototype.hasOrphan = function hasOrphan(hash) {
if (this.loading)
return false;
if (Array.isArray(hash))
hash = utils.toHex(hash);
return !!this.orphan.bmap[hash];
};
Chain.prototype.get = function get(hash, force, cb) { Chain.prototype.get = function get(hash, force, cb) {
if (typeof force === 'function') { if (typeof force === 'function') {
cb = force; cb = force;

View File

@ -460,12 +460,11 @@ Peer.prototype._handleInv = function handleInv(items) {
for (var i = 0; i < blocks.length; i++) { for (var i = 0; i < blocks.length; i++) {
var block = blocks[i]; var block = blocks[i];
var hash = utils.toHex(block); var hash = utils.toHex(block);
if (this.chain.orphan.bmap[hash]) { if (this.chain.hasOrphan(hash)) {
this.loadBlocks(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash)); this.loadBlocks(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash));
continue; continue;
} }
if (!this.chain.hasBlock(hash)) { if (!this.chain.hasBlock(hash)) {
// this.getData({ type: 'block', hash: hash });
req.push({ type: 'block', hash: block }); req.push({ type: 'block', hash: block });
continue; continue;
} }