Adds isRepair to onSlotFilled event from chainState.

This commit is contained in:
ThatBen 2025-06-20 14:22:34 +02:00
parent fb07ec8024
commit 561f277e76
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB
9 changed files with 37 additions and 18 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -55,13 +55,25 @@ namespace CodexContractsPlugin.ChainMonitor
public class RequestHosts
{
private readonly Dictionary<int, EthAddress> hosts = new Dictionary<int, EthAddress>();
private readonly List<int> filled = new List<int>();
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);
}

View File

@ -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)
{
}

View File

@ -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)
{
}

View File

@ -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 => "✅";

View File

@ -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<string> lines, PeriodReport[] reports)
{
var reportsWithMissedProofs = reports.Where(r => r.MissedProofs.Length > 0).ToArray();

View File

@ -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);
}
}

View File

@ -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)