getumbrel / umbrel-bitcoin

The official Bitcoin Node app for Umbrel, powered by Bitcoin Core.
https://umbrel.com
Other
37 stars 19 forks source link

Synchronized Percent Displays Incorrect Value #8

Closed mandreko closed 11 months ago

mandreko commented 1 year ago

I'm setting up a new BitCoin node on Umbrel for the first time. I was watching it sync, and noticed the math seemed to be a bit off.

Here's an example from my Node:

image

Note that 71,993 / 790,002 should equal 0.091130149. Moving that to a percentage should make it 9.1130149%. It's about 1/10th the way complete.

I initially suspected that maybe the code was doing 71,993 / 790,002 and then rounding, but that would result in 0.09% displayed, not 0.01%. This appears to not be the case. Either way, the math appears to be incorrect, unless my assumption of what it's counting is incorrect.

nmfretz commented 11 months ago

Hey @mandreko, nice observation! The sync percent is not simply dividing synced-blocks by total blocks, since this would make it really inaccurate during initial-block-download because early blocks are tiny and download / validate a lot faster. So you might see 50% synced in only a handful of hours, and then the remaining 50% could take on the order of days. We actually did it this way in the past and users often thought something was wrong and the sync had broken at the end.

Instead, this sync percentage is based on verificationprogress from the getblockchaininfo RPC, which is an estimate that takes into account how many transactions have been seen versus known statistics about the transaction rate on the network: https://developer.bitcoin.org/reference/rpc/getblockchaininfo.html

If you're curious, the relevant code in the Bitcoin Node app is here: https://github.com/getumbrel/umbrel-bitcoin/blob/24aeac8e044be5f42f7d90b2b589c6c65440b8de/ui/src/store/modules/bitcoin.js#L57-L81