better existence check.
This commit is contained in:
parent
8ed054cbda
commit
509ed09603
@ -991,13 +991,17 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
(function next(block) {
|
(function next(block) {
|
||||||
var hash = block.hash('hex');
|
var hash = block.hash('hex');
|
||||||
var prevHash = block.prevBlock;
|
var prevHash = block.prevBlock;
|
||||||
var prevHeight, entry, checkpoint, prev, orphan;
|
var prevHeight, height, entry, checkpoint, prev, orphan;
|
||||||
|
|
||||||
|
// Find the previous block height/index.
|
||||||
|
prevHeight = self.db.getHeight(prevHash);
|
||||||
|
height = prevHeight === -1 ? -1 : prevHeight + 1;
|
||||||
|
|
||||||
// We already have this block.
|
// We already have this block.
|
||||||
if (self.db.has(hash)) {
|
if (self.db.has(hash) || self.hasPending(hash)) {
|
||||||
self.emit('exists', block, {
|
self.emit('exists', block, {
|
||||||
height: entry.height,
|
height: height,
|
||||||
hash: entry.hash
|
hash: hash
|
||||||
}, peer);
|
}, peer);
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
@ -1005,7 +1009,7 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
// Do not revalidate known invalid blocks.
|
// Do not revalidate known invalid blocks.
|
||||||
if (self.invalid[hash] || self.invalid[prevHash]) {
|
if (self.invalid[hash] || self.invalid[prevHash]) {
|
||||||
self.emit('invalid', block, {
|
self.emit('invalid', block, {
|
||||||
height: -1,
|
height: height,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
seen: !!self.invalid[hash],
|
seen: !!self.invalid[hash],
|
||||||
chain: !!self.invalid[prevHash]
|
chain: !!self.invalid[prevHash]
|
||||||
@ -1014,9 +1018,6 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the previous block height/index.
|
|
||||||
prevHeight = self.db.getHeight(prevHash);
|
|
||||||
|
|
||||||
// Validate the block we want to add.
|
// Validate the block we want to add.
|
||||||
// This is only necessary for new
|
// This is only necessary for new
|
||||||
// blocks coming in, not the resolving
|
// blocks coming in, not the resolving
|
||||||
@ -1024,7 +1025,7 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
if (block === initial && !block.verify()) {
|
if (block === initial && !block.verify()) {
|
||||||
self.invalid[hash] = true;
|
self.invalid[hash] = true;
|
||||||
self.emit('invalid', block, {
|
self.emit('invalid', block, {
|
||||||
height: prevHeight === -1 ? -1 : prevHeight + 1,
|
height: height,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
seen: false,
|
seen: false,
|
||||||
chain: false
|
chain: false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user