From 496349d4b5065ee4fdcb50962a47042a91e4a31c Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 22 Oct 2015 14:08:44 -0400 Subject: [PATCH] fix sync percentage --- lib/status.js | 6 +++++- test/status.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/status.js b/lib/status.js index 2275adf03..eac1f2352 100644 --- a/lib/status.js +++ b/lib/status.js @@ -59,10 +59,14 @@ StatusController.prototype.sync = function(req, res) { status = 'finished'; } + // Not exactly the total blockchain height, + // but we will reach 100% when our db and bitcoind are both fully synced + var totalHeight = this.node.services.bitcoind.height / (this.node.services.bitcoind.syncPercentage() / 100); + var info = { status: status, blockChainHeight: this.node.services.bitcoind.height, - syncPercentage: this.node.services.db.tip.__height / this.node.services.bitcoind.height * 100, + syncPercentage: Math.round(this.node.services.db.tip.__height / totalHeight * 100), height: this.node.services.db.tip.__height, error: null, type: 'bitcore node' diff --git a/test/status.js b/test/status.js index 1fff1f9b9..2bf3975e7 100644 --- a/test/status.js +++ b/test/status.js @@ -125,7 +125,8 @@ describe('Status', function() { }, bitcoind: { height: 500000, - isSynced: sinon.stub().returns(true) + isSynced: sinon.stub().returns(true), + syncPercentage: sinon.stub().returns(99.99) } } };