diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainState.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainState.cs index 16667098..8e64302c 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainState.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainState.cs @@ -2,7 +2,6 @@ using CodexContractsPlugin.Marketplace; using Logging; using Nethereum.Hex.HexConvertors.Extensions; -using Newtonsoft.Json; using System.Numerics; using Utils; @@ -15,7 +14,7 @@ namespace CodexContractsPlugin.ChainMonitor void OnRequestFulfilled(RequestEvent requestEvent); void OnRequestCancelled(RequestEvent requestEvent); void OnRequestFailed(RequestEvent requestEvent); - void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex); + void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair); void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex); void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex); void OnProofSubmitted(BlockTimeEntry block, string id); @@ -166,16 +165,18 @@ namespace CodexContractsPlugin.ChainMonitor { var r = FindRequest(@event); if (r == null) return; - r.Hosts.Add(@event.Host, (int)@event.SlotIndex); + var slotIndex = (int)@event.SlotIndex; + var isRepair = !r.Hosts.IsFilled(slotIndex) && r.Hosts.WasPreviouslyFilled(slotIndex); + r.Hosts.HostFillsSlot(@event.Host, slotIndex); r.Log($"[{@event.Block.BlockNumber}] SlotFilled (host:'{@event.Host}', slotIndex:{@event.SlotIndex})"); - handler.OnSlotFilled(new RequestEvent(@event.Block, r), @event.Host, @event.SlotIndex); + handler.OnSlotFilled(new RequestEvent(@event.Block, r), @event.Host, @event.SlotIndex, isRepair); } private void ApplyEvent(SlotFreedEventDTO @event) { var r = FindRequest(@event); if (r == null) return; - r.Hosts.RemoveHost((int)@event.SlotIndex); + r.Hosts.SlotFreed((int)@event.SlotIndex); r.Log($"[{@event.Block.BlockNumber}] SlotFreed (slotIndex:{@event.SlotIndex})"); handler.OnSlotFreed(new RequestEvent(@event.Block, r), @event.SlotIndex); } diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateChangeHandlerMux.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateChangeHandlerMux.cs index a9a46a25..b5b4ade4 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateChangeHandlerMux.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateChangeHandlerMux.cs @@ -38,9 +38,9 @@ namespace CodexContractsPlugin.ChainMonitor foreach (var handler in Handlers) handler.OnRequestFulfilled(requestEvent); } - public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) + public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair) { - foreach (var handler in Handlers) handler.OnSlotFilled(requestEvent, host, slotIndex); + foreach (var handler in Handlers) handler.OnSlotFilled(requestEvent, host, slotIndex, isRepair); } public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex) diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateRequest.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateRequest.cs index 408d2746..2fa50e78 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateRequest.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateRequest.cs @@ -55,13 +55,25 @@ namespace CodexContractsPlugin.ChainMonitor public class RequestHosts { private readonly Dictionary hosts = new Dictionary(); + private readonly List filled = new List(); - public void Add(EthAddress host, int index) + public void HostFillsSlot(EthAddress host, int index) { hosts.Add(index, host); + filled.Add(index); + } + + public bool IsFilled(int index) + { + return hosts.ContainsKey(index); + } + + public bool WasPreviouslyFilled(int index) + { + return filled.Contains(index); } - public void RemoveHost(int index) + public void SlotFreed(int index) { hosts.Remove(index); } diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/DoNothingChainEventHandler.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/DoNothingChainEventHandler.cs index 43407998..b7a7f7fa 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/DoNothingChainEventHandler.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/DoNothingChainEventHandler.cs @@ -26,7 +26,7 @@ namespace CodexContractsPlugin.ChainMonitor { } - public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) + public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair) { } diff --git a/Tools/MarketInsights/ContributionBuilder.cs b/Tools/MarketInsights/ContributionBuilder.cs index 50bf48ad..387fd62b 100644 --- a/Tools/MarketInsights/ContributionBuilder.cs +++ b/Tools/MarketInsights/ContributionBuilder.cs @@ -1,6 +1,5 @@ using BlockchainUtils; using CodexContractsPlugin.ChainMonitor; -using GethPlugin; using Logging; using System.Numerics; using Utils; @@ -47,7 +46,7 @@ namespace MarketInsights AddRequestToAverage(segment.Started, requestEvent); } - public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) + public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair) { } diff --git a/Tools/TestNetRewarder/EmojiMaps.cs b/Tools/TestNetRewarder/EmojiMaps.cs index 38684c55..dcde4f97 100644 --- a/Tools/TestNetRewarder/EmojiMaps.cs +++ b/Tools/TestNetRewarder/EmojiMaps.cs @@ -78,6 +78,7 @@ public string NewRequest => "🌱"; public string Started => "🌳"; public string SlotFilled => "🟢"; + public string SlotRepaired => "♻"; public string SlotFreed => "⭕"; public string SlotReservationsFull => "☑️"; public string Finished => "✅"; diff --git a/Tools/TestNetRewarder/EventsFormatter.cs b/Tools/TestNetRewarder/EventsFormatter.cs index e37943bb..e2968982 100644 --- a/Tools/TestNetRewarder/EventsFormatter.cs +++ b/Tools/TestNetRewarder/EventsFormatter.cs @@ -84,9 +84,9 @@ namespace TestNetRewarder AddRequestBlock(requestEvent, $"{emojiMaps.Started} Started"); } - public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) + public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair) { - AddRequestBlock(requestEvent, $"{emojiMaps.SlotFilled} Slot Filled", + AddRequestBlock(requestEvent, GetSlotFilledTitle(isRepair), $"Host: {host}", $"Slot Index: {slotIndex}" ); @@ -135,6 +135,12 @@ namespace TestNetRewarder AddBlock(0, $"{emojiMaps.ProofReport} **Proof system report**", lines.ToArray()); } + private string GetSlotFilledTitle(bool isRepair) + { + if (isRepair) return $"{emojiMaps.SlotRepaired} Slot Repaired"; + return $"{emojiMaps.SlotFilled} Slot Filled"; + } + private void AddMissedProofDetails(List lines, PeriodReport[] reports) { var reportsWithMissedProofs = reports.Where(r => r.MissedProofs.Length > 0).ToArray(); diff --git a/Tools/TraceContract/ChainRequestTracker.cs b/Tools/TraceContract/ChainRequestTracker.cs index 2e313ae8..9992f367 100644 --- a/Tools/TraceContract/ChainRequestTracker.cs +++ b/Tools/TraceContract/ChainRequestTracker.cs @@ -70,11 +70,11 @@ namespace TraceContract } } - public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) + public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair) { if (IsMyRequest(requestEvent)) { - output.LogSlotFilled(requestEvent, host, slotIndex); + output.LogSlotFilled(requestEvent, host, slotIndex, isRepair); } } diff --git a/Tools/TraceContract/Output.cs b/Tools/TraceContract/Output.cs index 162660f8..16de2dc7 100644 --- a/Tools/TraceContract/Output.cs +++ b/Tools/TraceContract/Output.cs @@ -72,9 +72,9 @@ namespace TraceContract Add(requestEvent.Block, "Started"); } - public void LogSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) + public void LogSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex, bool isRepair) { - Add(requestEvent.Block, $"Slot filled. Index: {slotIndex} Host: '{host}'"); + Add(requestEvent.Block, $"Slot filled. Index: {slotIndex} Host: '{host}' isRepair: {isRepair}"); } public void LogSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)