How to check geth syncing status? How long does it take?

Attach to your node:

geth attach http://127.0.0.1:8545

Paste this code in full:

(function() {
    var secPerSample = 10;
    var sampleWindow = 400;
    var networkBlocksPerSec = 1 / 11; // network block time
    var decimals = 3;
    var dataPoints = [];
    var topBlock = eth.syncing.highestBlock;
    var curBlock = eth.syncing.currentBlock;

    function checkETA() {
        if (!eth || !eth.syncing) return 'Your node isn\'t syncing.';
        var blocksSynced = eth.syncing.currentBlock - curBlock;
        dataPoints.push(blocksSynced);
        console.log('\nMade it from block ' + curBlock + ' to block ' + eth.syncing.currentBlock + ' in the last ' + secPerSample + ' seconds (' + blocksSynced + ' blocks)');
        if (dataPoints.length > sampleWindow) {
            dataPoints.splice(0, dataPoints.length - sampleWindow); // keep only 100 data points
        }
        var avgBlocksPerWindow = 0;
        for (var i = 0; i < dataPoints.length; i++) {
            avgBlocksPerWindow += dataPoints[i];
        }
        avgBlocksPerWindow /= dataPoints.length;
        var avgBlocksPerSecond = avgBlocksPerWindow / secPerSample;
        console.log('Catching up ' + avgBlocksPerSecond.toFixed(decimals) + ' blocks/sec on average (' + avgBlocksPerWindow.toFixed(decimals) + ' blocks every ' + secPerSample + ' seconds, over last ' + dataPoints.length + ' samples)');
        topBlock = eth.syncing.highestBlock;
        curBlock = eth.syncing.currentBlock;
        var blocksRemaining = topBlock - curBlock;
        var secondsToReachTopBlock = blocksRemaining / avgBlocksPerSecond;
        console.log('With ' + blocksRemaining + ' blocks left to catch up on, getting to highest block known thus far (' + topBlock + ') should take ' + fancyTimeFormat(secondsToReachTopBlock, false));
        var effectiveCatchupRate = avgBlocksPerSecond - networkBlocksPerSec;
        console.log('Network also creates ' + networkBlocksPerSec.toFixed(decimals) + ' blocks/second, making our effective catchup rate ' + effectiveCatchupRate.toFixed(decimals) + ' blocks/sec');
        if (effectiveCatchupRate > 0) {
            var catchupSeconds = blocksRemaining / effectiveCatchupRate;
            var expectedCaughtUpBlock = topBlock + catchupSeconds * networkBlocksPerSec;
            console.log('Factoring in the rate of future block creation, we will be synced in ' + fancyTimeFormat(catchupSeconds, false) + ', at block #' + Math.ceil(expectedCaughtUpBlock));
        } else {
            console.log('At this rate, network is producing faster, so we will never catch up');
        }
    }

    function fancyTimeFormat(duration, withSeconds) { // duration is in seconds
        var ret = ''; // Hours, minutes and seconds  
        var hrs = ~~(duration / 3600);
        if (hrs > 0) ret += hrs + ' hrs ';
        ret += ~~((duration % 3600) / 60) + ' mins';
        if (withSeconds) ret += ' ' + (~~duration % 60) + ' secs';
        return ret;
    }
    var handle = setInterval(checkETA, secPerSample * 1000);

    function stop() {
        clearInterval(handle)
    }
    this.stopChecking = stop;
})()

To get output like this:

Made it from block 498561 to block 535611 in the last 10 seconds (37050 blocks)
Catching up 3705.000 blocks/sec on average (37050.000 blocks every 10 seconds, over last 1 samples)
With 15213526 blocks left to catch up on, getting to highest block known thus far (15749137) should take 1 hrs 8 mins
Network also creates 0.091 blocks/second, making our effective catchup rate 3704.909 blocks/sec
Factoring in the rate of future block creation, we will be synced in 1 hrs 8 mins, at block #15749511

To stop monitoring:

  • Type exit to exit the attached console
  • To stay in the attached console, type stopChecking() in the console