21

I installed the bitcoind and started it as daemon. After 10hours I've tried "du -h"

ubuntu@ip-172-31-37-93:~/.bitcoin$ du -h
16K     ./database
59M     ./blocks/index
29G     ./blocks
646M    ./chainstate
30G     . 

How to know if it synced or not?

UPD found an interesting script to monitor node sync status How to check Bitcoind block chain download progress level

7 Answers 7

17

You can compare the block count from Blockexplorer with your local block count. Something like this:


$ wget -q -O- https://blockchain.info/q/getblockcount; echo
359721
$ bitcoin-cli -conf=/u0/bitcoin/bitcoin.conf getblockcount
359721

As you can see above my node is synched since the counter is equal.

0
12

bitcoind logs the current sync status to its debug.log file:

$ tailf ~/.bitcoin/debug.log
2017-05-26 03:49:16 UpdateTip: new best=0000000000000001e0b7c8cffb8e7fa23909b8728913663decfaebffe24ca689 height=280022 version=0x00000002 log2_work=75.644236 tx=30854900 date='2014-01-12 03:50:07' **progress=0.137838** cache=312.7MiB(396972tx)
…

The field progress=0.137838 means that I'm currently ~13.7838% synced.

3

test my masterpiece:

#!/bin/bash
coin="$1";
if [ -z $coin ]; then
        /bin/echo "No coin given... using btc as default";
        coin="bitcoin";
fi
count=$(/usr/local/bin/${coin}-cli getblockcount);
/bin/echo "block count: $count";

hash=$(/usr/local/bin/${coin}-cli getblockhash $count);
/bin/echo "block hash: $hash";

t=$(/usr/local/bin/${coin}-cli getblock "$hash" | grep '"time"' | awk '{print $2}' | sed -e 's/,$//g');
/bin/echo "block timestamp is: $t";

cur_t=$(date +%s);
diff_t=$[$cur_t - $t];
/bin/echo -n "Difference is: ";
/bin/echo $diff_t | /usr/bin/awk '{printf "%d days, %d:%d:%d\n",$1/(60*60*24),$1/(60*60)%24,$1%(60*60)/60,$1%60}';

Usage:

$ bash masterpiece.sh bitcoin
block count: 525432
block hash: 000000000000000000373849d360010906852493fc3f8e51c3b6063de1ac70e8
block timestamp is: 1527848948
Difference is: 0 days, 0:10:11
1
  • this is reasonably nice
    – tofutim
    Aug 28, 2018 at 22:49
2

29G doesn't look after fully synced up.

But you should use bitcoin-cli (RPC command line app).

Do bitcoin-cli getinfo (check the "blocks" value and compare against blockchain or another full node) or bitcoin-cli getchaintips (more complicated to read)

Example:

:~/node/bitcoin$ ./src/bitcoin-cli getblockchaininfo
{
    "version" : 109900,
    "protocolversion" : 70002,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 359646,  // <--------------
    "timeoffset" : 0,
    "connections" : 63,
    "proxy" : "",
    "difficulty" : 47589591153.62500763,
    "testnet" : false,
    "keypoololdest" : 1425569670,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00001000,
    "errors" : "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
}
1

Extending the work done by hiding_ninja, I have crafter a script that gives you a readable answer if the node is reasonably in sync. (Last block less than 30 minutes old)

It does some extra error checking that help debug wrong parameters or common mistakes as trying to use CLI with the node not running.

#!/bin/bash

# Default Parameters
clis_path=/opt/bin/
configs_path=$HOME
max_allowed_last_block_age=1800 # 30 Minutes expressed in seconds


coin="$1";

if [ -z $coin ]; then
        /bin/echo "ERR: No coin selected. Usage example 'syncstate bitcoin'";
        exit 1;
fi
coin_cli="${clis_path}${coin}-cli"

if [ ! -f ${coin_cli} ]; then
    echo "ERR: The selected coin is not available or you should modify the clis_path variable"
    exit 2
fi

coin_cli="${coin_cli} -conf=${configs_path}/.${coin}/${coin}.conf"

count=$(${coin_cli} getblockcount);

RESULT=$?
if [ $RESULT != 0 ]; then
  echo "ERR: The cli does not seem to be available. Maybe the node is not running or rpc is not enabled?"
  exit 3
fi


hash=$(${coin_cli} getblockhash $count);

t=$(${coin_cli} getblock "$hash" | grep '"time"' | awk '{print $2}' | sed -e 's/,$//g');



cur_t=$(date +%s);
diff_t=$[$cur_t - $t];
if (( $diff_t <= max_allowed_last_block_age )); then
        echo ""
        echo "${coin} is in synch. Last block is ${diff_t} seconds old."
        echo ""
else
        echo "WARNING:"
        echo "${coin} node could be NOT in synch. Details:"
        echo "Last block hash: $hash";
        echo "Last block timestamp is: $t";
        echo "Last block count: $count";
        echo -n "Last synched ${coin} block is: ";
        echo $diff_t | /usr/bin/awk '{printf "%ddays %dhours %dminutes %dseconds old\n",$1/(60*60*24),$1/(60*60)%24,$1%(60*60)/60,$1%60}';
        echo ""
fi
0

I found the easiest way to do this:

tail -n 1  ~/.bitcoin/debug.log | grep -Po 'progress=\K.*?(.*)\s'
0

Run:

bitcoin-cli getblockchaininfo

.. and check response. For example, this node is not synchronized yet:

{
  "chain": "main",
  "blocks": 624371,
  "headers": 726916,
  ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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