예제 #1
0
		private async Task StartLoop(CancellationToken token, Signaler tick)
		{
			try
			{
				int errors = 0;
				while (!token.IsCancellationRequested)
				{
					errors = Math.Min(11, errors);
					try
					{
						while (await StepAsync(token))
						{
						}
						await tick.Wait(PollingInterval, token);
						errors = 0;
					}
					catch (ConfigException) when (!token.IsCancellationRequested)
					{
						// Probably RPC errors, don't spam
						await Wait(errors, tick, token);
						errors++;
					}
					catch (Exception ex) when (!token.IsCancellationRequested)
					{
						Logs.Configuration.LogError(ex, $"{_Network.CryptoCode}: Unhandled in Waiter loop");
						await Wait(errors, tick, token);
						errors++;
					}
				}
			}
			catch when (token.IsCancellationRequested)
			{
			}
		}
예제 #2
0
        private async Task Wait(int errors, Signaler tick, CancellationToken token)
        {
            var timeToWait = TimeSpan.FromSeconds(5.0) * (errors + 1);

            Logs.Configuration.LogInformation($"{_Network.CryptoCode}: Testing again in {(int)timeToWait.TotalSeconds} seconds");
            await tick.Wait(timeToWait, token);
        }
        private async Task IndexBlockLoop(Node node, CancellationToken cancellationToken)
        {
            try
            {
                CurrentLocation = await Repository.GetIndexProgress() ?? GetDefaultCurrentLocation();

                var fork = Chain.FindFork(CurrentLocation);
                if (fork == null)
                {
                    CurrentLocation = GetDefaultCurrentLocation();
                    fork            = Chain.FindFork(CurrentLocation);
                }
                Logs.Explorer.LogInformation($"{Network.CryptoCode}: Starting scan at block " + fork.Height);

                var downloader = new BlockDownloader(Chain, node);

                while (true)
                {
                    int   downloaded = 0;
                    Block lastBlock  = null;
                    await foreach (var block in downloader.DownloadBlocks(CurrentLocation, cancellationToken))
                    {
                        await SaveMatches(block);

                        downloaded++;
                        if (downloaded % 5 == 0)
                        {
                            CurrentLocation = Chain.GetLocator(block.Header.GetHash()) ?? CurrentLocation;
                            await Repository.SetIndexProgress(CurrentLocation);
                        }
                        lastBlock = block;
                    }
                    if (lastBlock != null)
                    {
                        CurrentLocation = Chain.GetLocator(lastBlock.Header.GetHash()) ?? CurrentLocation;
                        await Repository.SetIndexProgress(CurrentLocation);
                    }
                    if (CurrentLocation.Blocks.Count > 0 && CurrentLocation.Blocks[0] == Chain.TipBlock.Hash)
                    {
                        _EventAggregator.Publish(new FullySynchedEvent(Network), true);
                    }
                    await _NewBlock.Wait(cancellationToken);
                }
            }
            catch when(cancellationToken.IsCancellationRequested)
            {
            }