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) {
|
||||
if (!this.index.bloom.test(hash, 'hex'))
|
||||
return false;
|
||||
if (!this.strict)
|
||||
return true;
|
||||
|
||||
var start = 0;
|
||||
var end = this.index.ts.length;
|
||||
@ -107,7 +105,7 @@ Chain.prototype._probeIndex = function _probeIndex(hash, ts) {
|
||||
|
||||
for (var i = start; i <= end; i++)
|
||||
if (this.index.hashes[i] === hash)
|
||||
return true;
|
||||
return { height: this.index.heights[i], ts: this.index.ts[i] };
|
||||
|
||||
return false;
|
||||
};
|
||||
@ -127,11 +125,8 @@ Chain.prototype._addIndex = function _addIndex(hash, ts, height) {
|
||||
|
||||
this.index.ts.splice(pos, 0, ts);
|
||||
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.bloom.add(hash, 'hex');
|
||||
|
||||
if (!this.storage)
|
||||
return;
|
||||
@ -166,9 +161,10 @@ Chain.prototype.add = function add(block) {
|
||||
if (this.orphan.map[prev])
|
||||
break;
|
||||
|
||||
var prevProbe = this._probeIndex(prev, block.ts);
|
||||
|
||||
// If previous block wasn't ever seen - add current to orphans
|
||||
if (!this._probeIndex(hash, block.ts) &&
|
||||
!this._probeIndex(prev, block.ts)) {
|
||||
if (!this._probeIndex(hash, block.ts) && !prevProbe) {
|
||||
this.orphan.count++;
|
||||
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
|
||||
this._addIndex(hash, block.ts);
|
||||
if (prevProbe)
|
||||
this._addIndex(hash, block.ts, prevProbe.height + 1);
|
||||
|
||||
// At least one block was added
|
||||
res = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user