fix chain.index.lastTs.

This commit is contained in:
Christopher Jeffrey 2016-01-02 05:09:37 -08:00
parent a7a8eb11bb
commit bdc546edbc
2 changed files with 4 additions and 5 deletions

View File

@ -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) {

View File

@ -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));
};