<p>If you have linux's shell, you may try my bash script:</p>

<pre><code>$ cat coin_get_diff.sh
#!/bin/bash
[ -z "$1" ] &amp;&amp; echo "Usage: input=coinname" &amp;&amp; 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" ] &amp;&amp; echo "Alarm! Stuck on block # $blk!"
LAST_BLK="$blk"
done
</code></pre>

<p>Start it in next manner:</p>

<pre><code>$ bash coin_get_diff.sh bitcoind
</code></pre>

<p>Example output:</p>

<pre><code>...
....
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 ]
...
..
</code></pre>

<p>Read this my answer: <a href="https://bitcoin.stackexchange.com/questions/14104/how-long-does-it-take-to-download-blockchain/14114#14114">How long does it take to download blockchain</a></p>

CC BY-SA 3.0
2013-11-01T03:13:42.237Z
Woah, that is literally exactly what I needed! Thanks!
kamziro
CC BY-SA 3.0
2013-10-31T23:59:23.920Z
2013-10-31T23:59:23.920Z
2017-04-13T12:47:33.283Z
bellicose
<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2013-10-31T08:31:50.373Z
2013-10-31T08:31:50.373Z
cdecker
<p>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.</p>

<p>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?</p>

<bitcoind>
bitcoind and figuring out if it's still downloading blocks
kamziro
# bitcoind and figuring out if it's still downloading blocks

(Asked by: username_0 on 2013-10-31)

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?

**Tags:** bitcoind


---

## 2 answers

### Answer by username_1 on 2013-10-31. Score: 1 | Accepted answer

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](https://bitcoin.stackexchange.com/questions/14104/how-long-does-it-take-to-download-blockchain/14114#14114)

> **Comments:**
> **username_0**: Woah, that is literally exactly what I needed! Thanks!  

---

### Answer by username_2 on 2013-10-31. Score: 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.


---

