コード例 #1
0
        private void TryUpdateSyncTimes(eth_syncing syncing)
        {
            lock (_locker)
            {
                var currentSyncBlockNr = syncing.TryGetCurrentBlock();

                if (lastSyncBlock >= currentSyncBlockNr ||
                    currentSyncBlockNr <= 0)
                {
                    return;
                }

                if (syncTimes.Count == 0 && lastSyncBlock <= 0)
                {
                    syncTimesStopWatch.Restart();
                    lastSyncBlock = currentSyncBlockNr;
                    return;
                }

                syncTimes.Add(((float)(currentSyncBlockNr - lastSyncBlock) / syncTimesStopWatch.ElapsedMilliseconds) * 1000);
                syncTimesStopWatch.Restart();

                if (syncTimes.Count > _cfg.syncTimesAverageCount)
                {
                    syncTimes.RemoveAt(0);
                }

                averageSyncSpeed = (long)syncTimes.Average();
                lastSyncBlock    = currentSyncBlockNr;
            }
        }
コード例 #2
0
        public async Task <bool> TryUpdatePrivateSyncing()
        {
            eth_syncing response;

            try
            {
                var connectionString = _cfg.GetPrivateGethConnectionString();
                response = await FetchGethSyncResponse(connectionString);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to fetch private geth block height.");
                Console.WriteLine(ex.JsonSerializeAsPrettyException());
                return(false);
            }

            if (response == null || response.result is bool)
            {
                return(false);
            }

            var nr = response.TryGetCurrentBlock();

            if (nr > (privateSyncing?.TryGetCurrentBlock() ?? 0))
            {
                response.name  = "private";
                privateSyncing = response;
                TryUpdateBlockTimes(
                    currentBlock: null,
                    currentBlockOverride: response.TryGetHighestBlock());
                TryUpdateSyncTimes(response);
                return(true);
            }

            return(false);
        }