chain: set height properly
This commit is contained in:
parent
169be71d79
commit
7a2c8a933f
@ -94,8 +94,6 @@ Chain.prototype._getRange = function _getRange(hash, ts, futureOnly) {
|
|||||||
Chain.prototype._probeIndex = function _probeIndex(hash, ts) {
|
Chain.prototype._probeIndex = function _probeIndex(hash, ts) {
|
||||||
if (!this.index.bloom.test(hash, 'hex'))
|
if (!this.index.bloom.test(hash, 'hex'))
|
||||||
return false;
|
return false;
|
||||||
if (!this.strict)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
var start = 0;
|
var start = 0;
|
||||||
var end = this.index.ts.length;
|
var end = this.index.ts.length;
|
||||||
@ -107,7 +105,7 @@ Chain.prototype._probeIndex = function _probeIndex(hash, ts) {
|
|||||||
|
|
||||||
for (var i = start; i <= end; i++)
|
for (var i = start; i <= end; i++)
|
||||||
if (this.index.hashes[i] === hash)
|
if (this.index.hashes[i] === hash)
|
||||||
return true;
|
return { height: this.index.heights[i], ts: this.index.ts[i] };
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -127,11 +125,8 @@ Chain.prototype._addIndex = function _addIndex(hash, ts, height) {
|
|||||||
|
|
||||||
this.index.ts.splice(pos, 0, ts);
|
this.index.ts.splice(pos, 0, ts);
|
||||||
this.index.hashes.splice(pos, 0, hash);
|
this.index.hashes.splice(pos, 0, hash);
|
||||||
this.index.bloom.add(hash, 'hex');
|
|
||||||
assert(pos > 0);
|
|
||||||
if (!height)
|
|
||||||
height = this.index.heights[pos - 1] + 1;
|
|
||||||
this.index.heights.splice(pos, 0, height);
|
this.index.heights.splice(pos, 0, height);
|
||||||
|
this.index.bloom.add(hash, 'hex');
|
||||||
|
|
||||||
if (!this.storage)
|
if (!this.storage)
|
||||||
return;
|
return;
|
||||||
@ -166,9 +161,10 @@ Chain.prototype.add = function add(block) {
|
|||||||
if (this.orphan.map[prev])
|
if (this.orphan.map[prev])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
var prevProbe = this._probeIndex(prev, block.ts);
|
||||||
|
|
||||||
// If previous block wasn't ever seen - add current to orphans
|
// If previous block wasn't ever seen - add current to orphans
|
||||||
if (!this._probeIndex(hash, block.ts) &&
|
if (!this._probeIndex(hash, block.ts) && !prevProbe) {
|
||||||
!this._probeIndex(prev, block.ts)) {
|
|
||||||
this.orphan.count++;
|
this.orphan.count++;
|
||||||
this.orphan.map[prev] = block;
|
this.orphan.map[prev] = block;
|
||||||
|
|
||||||
@ -179,7 +175,8 @@ Chain.prototype.add = function add(block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validated known block at this point - add it to index
|
// Validated known block at this point - add it to index
|
||||||
this._addIndex(hash, block.ts);
|
if (prevProbe)
|
||||||
|
this._addIndex(hash, block.ts, prevProbe.height + 1);
|
||||||
|
|
||||||
// At least one block was added
|
// At least one block was added
|
||||||
res = true;
|
res = true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user