¿Cómo puedo estimar el tiempo restante para completar una sincronización?

Me gustaría saber aproximadamente cuánto tiempo le tomará a mi gethnodo completar la sincronización. Había una pregunta anterior que era similar a la mía, pero menos específica, y se cerró a favor de una pregunta sobre cómo obtener el número de bloque más alto . Como no fue posible agregar una respuesta a la pregunta cerrada, y la otra pregunta no responde a mi pregunta, estoy haciendo esta versión de la pregunta.

Respuestas (2)

Puede ingresar el siguiente código para estimar el tiempo restante en minutos. Muestrea el bloque actual en dos momentos diferentes para estimar el tiempo restante. Tenga en cuenta que si su bloque actual no cambia durante este tiempo, entonces no puede estimarlo.

en geth console:

function printSyncForecast() {
    if (!eth.syncing) return "Your node isn't syncing."
    var sampleSeconds = 10
    var currentBlock = eth.syncing.currentBlock;
    admin.sleep(sampleSeconds);
    if (!eth.syncing) return "Your node stopped syncing."
    var blocksSynced = eth.syncing.currentBlock - currentBlock
    var blocksPerMinute = blocksSynced * 60 / sampleSeconds;
    if (blocksPerMinute === 0) return "Current block didn't change; try increasing the sample time";
    var blocksRemaining = eth.syncing.highestBlock - eth.syncing.currentBlock;
    var minutesRemaining = blocksRemaining / blocksPerMinute;
    return "node synced " + blocksSynced + " blocks in " + sampleSeconds + " seconds (" + blocksPerMinute + 
      " blocks/minute.)  If these 📈 continue, node will sync the remaining " + blocksRemaining + " blocks in " + 
      minutesRemaining + " minutes."
}
printSyncForecast()

Aquí hay una sola línea de la línea de comando usando una versión minimizada de ese código:

geth attach --exec '(function(){if(!eth.syncing)return"Your node isnt syncing.";var n=eth.syncing.currentBlock;if(admin.sleep(10),!eth.syncing)return"Your node stopped syncing.";var e=eth.syncing.currentBlock-n,t=60*e/10;if(0===t)return"Current block didnt change; try increasing the sample time";var c=eth.syncing.highestBlock-eth.syncing.currentBlock;return"node synced "+e+" blocks in 10 seconds ("+t+" blocks/minute.)  If these 📈 continue, node will sync the remaining "+c+" blocks in "+c/t+" minutes."})()'
Me doy cuenta de que es una estimación, pero tampoco estoy seguro de que sea una estimación particularmente útil, al menos hasta que casi termines de sincronizar. La razón de esto es que diferentes períodos de tiempo en la historia de la cadena de bloques de Ethereum producen tasas de procesamiento de bloques muy diferentes. Los primeros bloques se procesan muy rápido porque la cadena puede vivir en caché y hubo pocas transacciones. Avance rápido hasta el otoño de 2016. El ataque de expansión de la cadena estatal ralentiza el procesamiento de bloques a pesar de que los bloques no están llenos. Finales de 2017 resulta en un procesamiento lento debido a transacciones pesadas (léase: CryptoKitties). Te funciona, genial :)
Actualicé el código para resaltar que el pronóstico es especulativo.

Puede intentar pegar esto en la consola geth ( geth attach http://localhost:8545para abrir la consola u otra URL según su configuración), observando ajustar la tasa de producción de bloques para su cadena de interés. Por ejemplo, en ethereum se convierte en var networkBlocksPerSec = 1 / 13.2;. Tenga en cuenta que otros fragmentos que flotan en línea no tienen en cuenta los bloques que producirá la red mientras se sincroniza, por lo que no están dando una estimación precisa. Este lo hace :)

(function () {

    var secPerSample = 10;
    var sampleWindow = 200;
    var networkBlocksPerSec = 1 / 2.3; // network block time (polygon makes a block every ~2 seconds)
    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;
})()

Para detener la ejecución de la función en un intervalo, ejecute stopChecking()en la consola geth