-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: updated the sync progress function #1110
Conversation
d351dd2
to
6759da5
Compare
Codecov ReportBase: 69.36% // Head: 69.34% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #1110 +/- ##
==========================================
- Coverage 69.36% 69.34% -0.02%
==========================================
Files 158 158
Lines 26590 26601 +11
==========================================
+ Hits 18443 18446 +3
- Misses 8147 8155 +8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
This patch doesn't actually solve the issue as described in #886. What we need to do is base progress estimation not on blocks or time (which are consistent throughout the life of the Bitcoin blockchain) but on TRANSACTIONS (which are not). For example, you could process 50% of the blockchain (2009-2015 or so) very quickly because during that era TX activity was relatively low. Once your node gets to ~2016 and on, the blocks get processed much slower because they have so many more transactions. That's the cool trick that Bitcoin Core does - it actually gives you a % progress not on the number of blocks but more accurately on how much actual UTXO/hashing/ECDSA work is left for your specific machine. So the goal would be an initial block download where the progress advances at the same rate the whole time from 0-100% |
6d9f82d
to
0af2164
Compare
e4ae2ad
to
ae3c61f
Compare
ae3c61f
to
ef0fdd8
Compare
ef0fdd8
to
b4e4934
Compare
LGTM! |
merged in 57f5956 |
@masterchief164 @pinheadmz |
@bolaum great catch, yeah we did not consider SPV mode! I think diff --git a/test/chain-progress-test.js b/test/chain-progress-test.js
index 456267105..b03b38618 100644
--- a/test/chain-progress-test.js
+++ b/test/chain-progress-test.js
@@ -154,7 +154,8 @@ describe('Chain Sync Progress', function () {
const newChain = new Chain({
memory: true,
blocks,
- network
+ network,
+ spv: true
});
before(async () => {
|
I did this in my branch: diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js
index 1c252b81..9cd0a312 100644
--- a/lib/blockchain/chain.js
+++ b/lib/blockchain/chain.js
@@ -2035,6 +2035,13 @@ class Chain extends AsyncEmitter {
*/
getProgress() {
+ if (this.options.spv) {
+ const start = this.network.genesis.time;
+ const current = this.tip.time - start;
+ const end = util.now() - start - 40 * 60;
+ return Math.min(1, current / end);
+ }
+
const time = util.now();
const currentCount = this.db.state.tx; Is this an acceptable PR? 😬 |
Yes but try to add a test, or include SPV in the existing diff --git a/test/chain-progress-test.js b/test/chain-progress-test.js
index 456267105..43a353d46 100644
--- a/test/chain-progress-test.js
+++ b/test/chain-progress-test.js
@@ -140,7 +140,8 @@ describe('Chain Sync Progress', function () {
assert.strictEqual(chain.db.state.tx, (1 + 100 + 200 + 300));
});
- describe('New chain', function () {
+for (const spv of [true, false]) {
+ describe(`New chain: ${spv ? 'SPV' : 'Full'}`, function () {
// time never changes
util.now = () => {
return chain.tip.time;
@@ -154,7 +155,8 @@ describe('Chain Sync Progress', function () {
const newChain = new Chain({
memory: true,
blocks,
- network
+ network,
+ spv
});
before(async () => {
@@ -222,4 +224,5 @@ describe('Chain Sync Progress', function () {
assert.strictEqual(percent, 100);
});
});
+}
});
|
@pinheadmz PR: #1137 |
Closes #886
We now calculate the progress according to the number of blocks mined until 17:36:38 UTC on 3rd December 2022 and then extrapolate the number of blocks assuming the 144 blocks are mined every day. This PR fixes issue #886.