mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-28 20:19:40 +00:00
Adds proofSubmitted event
This commit is contained in:
parent
d6cd7762c4
commit
07c3e5fc18
@ -14,7 +14,8 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
RequestFailedEventDTO[] failed,
|
||||
SlotFilledEventDTO[] slotFilled,
|
||||
SlotFreedEventDTO[] slotFreed,
|
||||
SlotReservationsFullEventDTO[] slotReservationsFull
|
||||
SlotReservationsFullEventDTO[] slotReservationsFull,
|
||||
ProofSubmittedEventDTO[] proofSubmitted
|
||||
)
|
||||
{
|
||||
BlockInterval = blockInterval;
|
||||
@ -25,8 +26,8 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
SlotFilled = slotFilled;
|
||||
SlotFreed = slotFreed;
|
||||
SlotReservationsFull = slotReservationsFull;
|
||||
|
||||
All = ConcatAll<IHasBlock>(requests, fulfilled, cancelled, failed, slotFilled, SlotFreed, SlotReservationsFull);
|
||||
ProofSubmitted = proofSubmitted;
|
||||
All = ConcatAll<IHasBlock>(requests, fulfilled, cancelled, failed, slotFilled, SlotFreed, SlotReservationsFull, ProofSubmitted);
|
||||
}
|
||||
|
||||
public BlockInterval BlockInterval { get; }
|
||||
@ -37,6 +38,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
public SlotFilledEventDTO[] SlotFilled { get; }
|
||||
public SlotFreedEventDTO[] SlotFreed { get; }
|
||||
public SlotReservationsFullEventDTO[] SlotReservationsFull { get; }
|
||||
public ProofSubmittedEventDTO[] ProofSubmitted { get; }
|
||||
public IHasBlock[] All { get; }
|
||||
|
||||
public static ChainEvents FromBlockInterval(ICodexContracts contracts, BlockInterval blockInterval)
|
||||
@ -59,7 +61,8 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
events.GetRequestFailedEvents(),
|
||||
events.GetSlotFilledEvents(),
|
||||
events.GetSlotFreedEvents(),
|
||||
events.GetSlotReservationsFull()
|
||||
events.GetSlotReservationsFullEvents(),
|
||||
events.GetProofSubmittedEvents()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex);
|
||||
void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex);
|
||||
void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex);
|
||||
|
||||
void OnProofSubmitted(BlockTimeEntry block, string id);
|
||||
void OnError(string msg);
|
||||
}
|
||||
|
||||
@ -39,12 +39,14 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
private readonly ILog log;
|
||||
private readonly ICodexContracts contracts;
|
||||
private readonly IChainStateChangeHandler handler;
|
||||
private readonly bool doProofPeriodMonitoring;
|
||||
|
||||
public ChainState(ILog log, ICodexContracts contracts, IChainStateChangeHandler changeHandler, DateTime startUtc)
|
||||
public ChainState(ILog log, ICodexContracts contracts, IChainStateChangeHandler changeHandler, DateTime startUtc, bool doProofPeriodMonitoring)
|
||||
{
|
||||
this.log = new LogPrefixer(log, "(ChainState) ");
|
||||
this.contracts = contracts;
|
||||
handler = changeHandler;
|
||||
this.doProofPeriodMonitoring = doProofPeriodMonitoring;
|
||||
TotalSpan = new TimeRange(startUtc, startUtc);
|
||||
PeriodMonitor = new PeriodMonitor(this.log, contracts);
|
||||
}
|
||||
@ -98,6 +100,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
|
||||
private void UpdatePeriodMonitor(ulong blockNumber, DateTime eventUtc)
|
||||
{
|
||||
if (!doProofPeriodMonitoring) return;
|
||||
PeriodMonitor.Update(blockNumber, eventUtc, Requests);
|
||||
}
|
||||
|
||||
@ -173,6 +176,13 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
handler.OnSlotReservationsFull(new RequestEvent(@event.Block, r), @event.SlotIndex);
|
||||
}
|
||||
|
||||
private void ApplyEvent(ProofSubmittedEventDTO @event)
|
||||
{
|
||||
var id = Base58.Encode(@event.Id);
|
||||
log.Log($"[{@event.Block.BlockNumber}] Proof submitted (id:{id})");
|
||||
handler.OnProofSubmitted(@event.Block, id);
|
||||
}
|
||||
|
||||
private void ApplyTimeImplicitEvents(ulong blockNumber, DateTime eventsUtc)
|
||||
{
|
||||
foreach (var r in requests)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Numerics;
|
||||
using BlockchainUtils;
|
||||
using System.Numerics;
|
||||
using Utils;
|
||||
|
||||
namespace CodexContractsPlugin.ChainMonitor
|
||||
@ -56,5 +57,10 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
{
|
||||
foreach (var handler in Handlers) handler.OnError(msg);
|
||||
}
|
||||
|
||||
public void OnProofSubmitted(BlockTimeEntry block, string id)
|
||||
{
|
||||
foreach (var handler in Handlers) handler.OnProofSubmitted(block, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Numerics;
|
||||
using BlockchainUtils;
|
||||
using System.Numerics;
|
||||
using Utils;
|
||||
|
||||
namespace CodexContractsPlugin.ChainMonitor
|
||||
@ -40,5 +41,9 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||
public void OnError(string msg)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnProofSubmitted(BlockTimeEntry block, string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ namespace CodexContractsPlugin
|
||||
RequestFailedEventDTO[] GetRequestFailedEvents();
|
||||
SlotFilledEventDTO[] GetSlotFilledEvents();
|
||||
SlotFreedEventDTO[] GetSlotFreedEvents();
|
||||
SlotReservationsFullEventDTO[] GetSlotReservationsFull();
|
||||
SlotReservationsFullEventDTO[] GetSlotReservationsFullEvents();
|
||||
ProofSubmittedEventDTO[] GetProofSubmittedEvents();
|
||||
}
|
||||
|
||||
public class CodexContractsEvents : ICodexContractsEvents
|
||||
@ -86,12 +87,18 @@ namespace CodexContractsPlugin
|
||||
return events.Select(SetBlockOnEvent).ToArray();
|
||||
}
|
||||
|
||||
public SlotReservationsFullEventDTO[] GetSlotReservationsFull()
|
||||
public SlotReservationsFullEventDTO[] GetSlotReservationsFullEvents()
|
||||
{
|
||||
var events = gethNode.GetEvents<SlotReservationsFullEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
||||
return events.Select(SetBlockOnEvent).ToArray();
|
||||
}
|
||||
|
||||
public ProofSubmittedEventDTO[] GetProofSubmittedEvents()
|
||||
{
|
||||
var events = gethNode.GetEvents<ProofSubmittedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
||||
return events.Select(SetBlockOnEvent).ToArray();
|
||||
}
|
||||
|
||||
private T SetBlockOnEvent<T>(EventLog<T> e) where T : IHasBlock
|
||||
{
|
||||
var result = e.Event;
|
||||
|
||||
@ -69,5 +69,11 @@ namespace CodexContractsPlugin.Marketplace
|
||||
[JsonIgnore]
|
||||
public BlockTimeEntry Block { get; set; }
|
||||
}
|
||||
|
||||
public partial class ProofSubmittedEventDTO : IHasBlock
|
||||
{
|
||||
[JsonIgnore]
|
||||
public BlockTimeEntry Block { get; set; }
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
@ -17,7 +17,8 @@ namespace MarketInsights
|
||||
{
|
||||
this.appState = appState;
|
||||
this.maxContributions = maxContributions;
|
||||
chainState = new ChainState(appState.Log, contracts, mux, appState.Config.HistoryStartUtc);
|
||||
chainState = new ChainState(appState.Log, contracts, mux, appState.Config.HistoryStartUtc,
|
||||
doProofPeriodMonitoring: false);
|
||||
}
|
||||
|
||||
public MarketTimeSegment[] Segments { get; private set; } = Array.Empty<MarketTimeSegment>();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using CodexContractsPlugin.ChainMonitor;
|
||||
using BlockchainUtils;
|
||||
using CodexContractsPlugin.ChainMonitor;
|
||||
using GethPlugin;
|
||||
using Logging;
|
||||
using System.Numerics;
|
||||
@ -58,6 +59,10 @@ namespace MarketInsights
|
||||
{
|
||||
}
|
||||
|
||||
public void OnProofSubmitted(BlockTimeEntry block, string id)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnError(string msg)
|
||||
{
|
||||
log.Error(msg);
|
||||
|
||||
@ -27,6 +27,12 @@ namespace TestNetRewarder
|
||||
[Uniform("events-overview", "eo", "EVENTSOVERVIEW", false, "When greater than zero, chain event summary will be generated.")]
|
||||
public int CreateChainEventsOverview { get; set; } = 1;
|
||||
|
||||
[Uniform("proof-period-reports", "ppr", "PROOFPERIODREPORTS", false, "When greater than zero, chain event summary will include period reports of the proving system.")]
|
||||
public int ShowProofPeriodReports { get; set; } = 1;
|
||||
|
||||
[Uniform("proof-submitted-events", "pse", "PROOFSUBMITTEDEVENTS", false, "When greater than zero, chain event summary will include proof-submitted events.")]
|
||||
public int ShowProofSubmittedEvents { get; set; } = 1;
|
||||
|
||||
public string LogPath
|
||||
{
|
||||
get
|
||||
|
||||
@ -83,6 +83,8 @@
|
||||
public string Finished => "✅";
|
||||
public string Cancelled => "🚫";
|
||||
public string Failed => "❌";
|
||||
public string ProofSubmitted => "🎵";
|
||||
public string ProofReport => "🔎";
|
||||
|
||||
public string StringToEmojis(string input, int outLength)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using CodexContractsPlugin;
|
||||
using BlockchainUtils;
|
||||
using CodexContractsPlugin;
|
||||
using CodexContractsPlugin.ChainMonitor;
|
||||
using DiscordRewards;
|
||||
using GethPlugin;
|
||||
@ -14,6 +15,12 @@ namespace TestNetRewarder
|
||||
private readonly List<ChainEventMessage> events = new List<ChainEventMessage>();
|
||||
private readonly List<string> errors = new List<string>();
|
||||
private readonly EmojiMaps emojiMaps = new EmojiMaps();
|
||||
private readonly Configuration config;
|
||||
|
||||
public EventsFormatter(Configuration config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public ChainEventMessage[] GetInitializationEvents(Configuration config)
|
||||
{
|
||||
@ -96,7 +103,16 @@ namespace TestNetRewarder
|
||||
$"Slot Index: {slotIndex}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void OnProofSubmitted(BlockTimeEntry block, string id)
|
||||
{
|
||||
if (config.ShowProofSubmittedEvents < 1) return;
|
||||
|
||||
AddBlock(block.BlockNumber, $"{emojiMaps.ProofSubmitted} **Proof submitted**",
|
||||
$"Id: {id}"
|
||||
);
|
||||
}
|
||||
|
||||
public void OnError(string msg)
|
||||
{
|
||||
errors.Add(msg);
|
||||
@ -106,7 +122,7 @@ namespace TestNetRewarder
|
||||
{
|
||||
var lines = periodReports.Select(FormatPeriodReport).ToList();
|
||||
lines.Insert(0, FormatPeriodReportLine("period", "totalSlots", "required", "missed"));
|
||||
AddBlock(0, "Proof system report", lines.ToArray());
|
||||
AddBlock(0, $"{emojiMaps.ProofReport} **Proof system report**", lines.ToArray());
|
||||
}
|
||||
|
||||
private string FormatPeriodReport(PeriodReport report)
|
||||
|
||||
@ -25,14 +25,15 @@ namespace TestNetRewarder
|
||||
|
||||
builder = new RequestBuilder();
|
||||
rewardChecker = new RewardChecker(builder);
|
||||
eventsFormatter = new EventsFormatter();
|
||||
eventsFormatter = new EventsFormatter(config);
|
||||
|
||||
var handler = new ChainStateChangeHandlerMux(
|
||||
rewardChecker.Handler,
|
||||
eventsFormatter
|
||||
);
|
||||
|
||||
chainState = new ChainState(log, contracts, handler, config.HistoryStartUtc);
|
||||
chainState = new ChainState(log, contracts, handler, config.HistoryStartUtc,
|
||||
doProofPeriodMonitoring: config.ShowProofPeriodReports > 0);
|
||||
}
|
||||
|
||||
public async Task Initialize()
|
||||
@ -85,6 +86,7 @@ namespace TestNetRewarder
|
||||
|
||||
private void ProcessPeriodUpdate()
|
||||
{
|
||||
if (config.ShowProofPeriodReports < 1) return;
|
||||
if (DateTime.UtcNow < (lastPeriodUpdateUtc + TimeSpan.FromHours(1.0))) return;
|
||||
lastPeriodUpdateUtc = DateTime.UtcNow;
|
||||
|
||||
|
||||
@ -80,6 +80,10 @@ namespace TestNetRewarder
|
||||
{
|
||||
}
|
||||
|
||||
public void OnProofSubmitted(BlockTimeEntry block, string id)
|
||||
{
|
||||
}
|
||||
|
||||
private void GiveReward(RewardConfig reward, EthAddress receiver)
|
||||
{
|
||||
giver.Give(reward, receiver);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user