From bdc546edbc45eb95ff3ef08cc945a5e34dbf5df6 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 2 Jan 2016 05:09:37 -0800 Subject: [PATCH] fix chain.index.lastTs. --- lib/bcoin/chain.js | 3 +-- lib/bcoin/fullchain.js | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index ce69eb84..61dc77f7 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -56,7 +56,7 @@ function Chain(options) { this.fromJSON(preload); // Last TS after preload, needed for fill percent - this.index.lastTs = this.index.ts[this.index.ts.length - 1]; + this.index.lastTs = this.index.ts[0]; bcoin.chain.global = this; @@ -212,7 +212,6 @@ Chain.prototype.resetHeight = function resetHeight(height) { this.index.hashes.forEach(function(hash) { self.index.bloom.add(hash, 'hex'); }); - this.index.lastTs = this.index.ts[this.index.ts.length - 1]; }; Chain.prototype._heightByTime = function _heightByTime(ts) { diff --git a/lib/bcoin/fullchain.js b/lib/bcoin/fullchain.js index 7d66bf1e..d7d43df9 100644 --- a/lib/bcoin/fullchain.js +++ b/lib/bcoin/fullchain.js @@ -64,7 +64,7 @@ function Chain(options) { }); // Last TS after preload, needed for fill percent - this.index.lastTs = this.index.entries[this.index.entries.length - 1].ts; + this.index.lastTs = this.index.entries[0].ts; bcoin.chain.global = this; @@ -157,7 +157,7 @@ Chain.prototype.resetHeight = function resetHeight(height) { }, {}); this.index.hashes.length = height + 1; - this.index.lastTs = this.index.entries[this.index.entries.length - 1].ts; + this.index.lastTs = this.index.entries[0].ts; forked.forEach(function(entry) { self._delete(entry); @@ -348,7 +348,7 @@ Chain.prototype.isFull = function isFull() { Chain.prototype.fillPercent = function fillPercent() { var total = (+new Date() / 1000 - 40 * 60) - this.index.lastTs; - var current = this.index.entries[this.index.entries.length - 1].ts - this.index.lastTs; + var current = this.getTip().ts - this.index.lastTs; return Math.max(0, Math.min(current / total, 1)); };