public async Task <IActionResult> GetAsync(CancellationToken cancellationToken) { if (_logger.IsDebug()) { LogDebug.NodeGenesisTimeRequested(_logger, null); } ApiResponse <ulong> apiResponse = await _beaconNode.GetGenesisTimeAsync(cancellationToken).ConfigureAwait(false); if (apiResponse.StatusCode == Core2.Api.StatusCode.Success) { return(Ok(apiResponse.Content)); } return(Problem("Beacon node internal error.", statusCode: (int)apiResponse.StatusCode)); }
public async Task BasicGensisTime() { // Arrange IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(); IBeaconNodeOApiClient beaconNodeOApiClient = Substitute.For <IBeaconNodeOApiClient>(); beaconNodeOApiClient.TimeAsync(Arg.Any <CancellationToken>()).Returns(1_578_009_600uL); IBeaconNodeOApiClientFactory beaconNodeOApiClientFactory = Substitute.For <IBeaconNodeOApiClientFactory>(); beaconNodeOApiClientFactory.CreateClient(Arg.Any <string>()).Returns(beaconNodeOApiClient); testServiceCollection.AddSingleton <IBeaconNodeOApiClientFactory>(beaconNodeOApiClientFactory); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); // Act IBeaconNodeApi beaconNodeProxy = testServiceProvider.GetService <IBeaconNodeApi>(); beaconNodeProxy.ShouldBeOfType(typeof(BeaconNodeProxy)); ulong genesisTime = await beaconNodeProxy.GetGenesisTimeAsync(CancellationToken.None); // Assert genesisTime.ShouldBe(1578009600uL); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { if (_logger.IsInfo()) { Log.HonestValidatorWorkerExecuteStarted(_logger, _clientVersion.Description, _environment.EnvironmentName, Thread.CurrentThread.ManagedThreadId, null); } try { // Config // List of nodes // Validator private keys (or quickstart) // Seconds per slot string nodeVersion = string.Empty; while (nodeVersion == string.Empty) { try { nodeVersion = await _beaconNodeApi.GetNodeVersionAsync(stoppingToken).ConfigureAwait(false); } catch (Exception ex) { Log.WaitingForNodeVersion(_logger, ex); await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken).ConfigureAwait(false); } } ulong genesisTime = 0; while (genesisTime == 0) { try { genesisTime = await _beaconNodeApi.GetGenesisTimeAsync(stoppingToken).ConfigureAwait(false); } catch (Exception ex) { Log.WaitingForGenesisTime(_logger, ex); await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken).ConfigureAwait(false); } } Log.HonestValidatorWorkerConnected(_logger, nodeVersion, genesisTime, null); await _beaconChain.SetGenesisTimeAsync(genesisTime).ConfigureAwait(false); while (!stoppingToken.IsCancellationRequested && !_stopped) { try { DateTimeOffset clockTime = _clock.UtcNow(); ulong time = (ulong)clockTime.ToUnixTimeSeconds(); if (time > genesisTime) { await _validatorClient.OnTickAsync(_beaconChain, time, stoppingToken).ConfigureAwait(false); } // Wait for remaining time, if any // NOTE: To fast forward time during testing, have the second call to test _clock.Now() jump forward to avoid waiting. DateTimeOffset nextClockTime = DateTimeOffset.FromUnixTimeSeconds((long)time + 1); TimeSpan remaining = nextClockTime - _clock.UtcNow(); if (remaining > TimeSpan.Zero) { await Task.Delay(remaining, stoppingToken); } } catch (TaskCanceledException) { // This is expected when exiting } catch (Exception ex) { if (_logger.IsError()) { Log.HonestValidatorWorkerLoopError(_logger, ex); } } } } catch (Exception ex) { Log.HonestValidatorWorkerCriticalError(_logger, ex); throw; } if (_logger.IsDebug()) { LogDebug.HonestValidatorWorkerExecuteExiting(_logger, Thread.CurrentThread.ManagedThreadId, null); } }
/// <summary>Get the genesis_time parameter from beacon node configuration.</summary> /// <returns>Request successful</returns> public async Task <ulong> TimeAsync() { return(await _beaconNode.GetGenesisTimeAsync()); }
/// <summary>Get the genesis_time parameter from beacon node configuration.</summary> /// <returns>Request successful</returns> public async Task <ulong> TimeAsync() { return(await _beaconNode.GetGenesisTimeAsync(CancellationToken.None)); }