1

I've asked around, and it seems that to figure out that bitcoind is still downloading blocks is to run ./bitcoind getinfo and see if the "block count" is increasing.

Is there an easier way to do this, or is there a better way? How do those clients figure out that there's "30 blocks left" to download etc?

1

If you have linux's shell, you may try my bash script:

$ cat coin_get_diff.sh
#!/bin/bash
[ -z "$1" ] && echo "Usage: input=coinname" && exit 1
coin="$1"

while sleep 1;do
blk="$(eval "$coin getblockcount")"
h="$(eval "$coin getblockhash $blk")"    
coin_t="$(eval "$coin getblock $h" | grep '"time"' | awk '{print $3}' | sed -e 's/,//g')"

d="$[$(date +%s) - $coin_t]"; dm="$[$d / 60]"; dh="$[$dm / 60 ]"; dd="$[$dh / 24 ]"
echo "Difference with main chain $d s. or $dm m.  or $dh h.  or $dd d."

if [ -z "$first_t" ];then
        first_t="$d"
        start_watch_time="$(date +%s)"
else
        difference=$[$first_t - $d]
        speed="$(echo "$difference / $[$(date +%s) - $start_watch_time ]" | bc -l)" 
        remain_seconds="$(echo "$d / $speed" | bc -l)" 
        remain_minutes="$(echo "$remain_seconds / 60" | bc -l)"
        remain_hours="$(echo "$remain_minutes / 60" | bc -l)"
        remain_days="$(echo "$remain_hours / 24" | bc -l)"
        # eval "$coin getinfo"
        echo -n "Approximate remain: $remain_seconds seconds to complete  sync."
        echo "[m: $remain_minutes; h: $remain_hours; d: $remain_days ]"
fi    
[ "$LAST_BLK" == "$blk" ] && echo "Alarm! Stuck on block # $blk!"
LAST_BLK="$blk"
done

Start it in next manner:

$ bash coin_get_diff.sh bitcoind

Example output:

...
....
Difference with main chain 2528577 s. or 42142 m.  or 702 h.  or 29 d.
Approximate remain: 2186.83957899106610047826 seconds to complete  sync.[m: 36.44732631651776834130; h: .60745543860862947235; d: .02531064327535956134 ]
Difference with main chain 2526232 s. or 42103 m.  or 701 h.  or 29 d.
Approximate remain: 2184.21035499949140474011 seconds to complete  sync.[m: 36.40350591665819007900; h: .60672509861096983465; d: .02528021244212374311 ]
Difference with main chain 2524021 s. or 42067 m.  or 701 h.  or 29 d.
Approximate remain: 2205.15551284291455530316 seconds to complete  sync.[m: 36.75259188071524258838; h: .61254319801192070980; d: .02552263325049669624 ]
...
..

Read this my answer: How long does it take to download blockchain

  • Woah, that is literally exactly what I needed! Thanks! – kamziro Nov 1 '13 at 3:13
1

There are several ways to estimate the number of blocks left to download. The easiest is likely that the client takes a look around at what its peers are saying their longest chain currently looks like. So if you connect to 8 peers in the network it is very unlikely that all of them are still catching up with the rest of the network and therefore it will tell you what the current state, or something close to it is.

Another way of estimating the number of blocks is by looking at the timestamp included in the block that you just downloaded. In expectation a block should arrive every 10 minutes. The timestamp in the block is not allowed to deviate from the actual time it was mined by more than a fixed number of minutes (otherwise it would be rejected when it is first seen). So if you subtract the time of the last block you downloaded from the current time and then divide by 10 minute intervals you get an estimate of the total number of blocks in the network.

Notice that the second method may not be incredibly precise, especially in times the commputational power in the network grows quickly, like it is currently doing, or is reduced quickly.

As for you checking how many blocks are left, it's a simple matter of going to a trusted block explorer and comparing your blockchain height with the height they display.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.