From 2ab84e2a61ff3e93f31a4201d3060f8221e25e0c Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 1 Apr 2024 13:56:07 +0200 Subject: [PATCH] Time handling for rewarder --- Tools/TestNetRewarder/Processor.cs | 15 ++++++++------- Tools/TestNetRewarder/TimeSegmenter.cs | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Tools/TestNetRewarder/Processor.cs b/Tools/TestNetRewarder/Processor.cs index 425c0e3..032b0ef 100644 --- a/Tools/TestNetRewarder/Processor.cs +++ b/Tools/TestNetRewarder/Processor.cs @@ -20,11 +20,11 @@ namespace TestNetRewarder public async Task ProcessTimeSegment(TimeRange timeRange) { + var connector = GethConnector.GethConnector.Initialize(log); + if (connector == null) throw new Exception("Invalid Geth information"); + try { - var connector = GethConnector.GethConnector.Initialize(log); - if (connector == null) return; - var blockRange = connector.GethNode.ConvertTimeRangeToBlockRange(timeRange); if (!IsNewBlockRange(blockRange)) { @@ -33,12 +33,12 @@ namespace TestNetRewarder } var chainState = new ChainState(historicState, connector.CodexContracts, blockRange); - await ProcessTimeSegment(chainState); - + await ProcessChainState(chainState); } catch (Exception ex) { log.Error("Exception processing time segment: " + ex); + throw; } } @@ -55,7 +55,7 @@ namespace TestNetRewarder return false; } - private async Task ProcessTimeSegment(ChainState chainState) + private async Task ProcessChainState(ChainState chainState) { var outgoingRewards = new List(); foreach (var reward in rewardRepo.Rewards) @@ -63,6 +63,7 @@ namespace TestNetRewarder ProcessReward(outgoingRewards, reward, chainState); } + log.Log($"Found {outgoingRewards.Count} rewards to send."); if (outgoingRewards.Any()) { if (!await SendRewardsCommand(outgoingRewards)) @@ -79,7 +80,7 @@ namespace TestNetRewarder Rewards = outgoingRewards.ToArray() }; - log.Log("Sending rewards: " + JsonConvert.SerializeObject(cmd)); + log.Debug("Sending rewards: " + JsonConvert.SerializeObject(cmd)); return await Program.BotClient.SendRewards(cmd); } diff --git a/Tools/TestNetRewarder/TimeSegmenter.cs b/Tools/TestNetRewarder/TimeSegmenter.cs index 5a555f7..4bdced2 100644 --- a/Tools/TestNetRewarder/TimeSegmenter.cs +++ b/Tools/TestNetRewarder/TimeSegmenter.cs @@ -31,11 +31,12 @@ namespace TestNetRewarder if (end > now) { // Wait for the entire time segment to be in the past. - var delay = (end - now).Add(TimeSpan.FromSeconds(3)); + var delay = end - now; waited = true; log.Log($"Waiting till time segment is in the past... {Time.FormatDuration(delay)}"); await Task.Delay(delay, Program.CancellationToken); } + await Task.Delay(TimeSpan.FromSeconds(3), Program.CancellationToken); if (Program.CancellationToken.IsCancellationRequested) return;