2
0
mirror of synced 2025-01-11 17:14:25 +00:00

Adds SlotReservationsFull event to chain state tracker

This commit is contained in:
Ben 2024-10-10 11:15:07 +02:00
parent c239d555dc
commit 5313f8a7ac
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
9 changed files with 85 additions and 50 deletions

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin.Marketplace; using CodexContractsPlugin.Marketplace;
using System.Collections.Generic;
using Utils; using Utils;
namespace CodexContractsPlugin.ChainMonitor namespace CodexContractsPlugin.ChainMonitor
@ -12,7 +13,8 @@ namespace CodexContractsPlugin.ChainMonitor
RequestCancelledEventDTO[] cancelled, RequestCancelledEventDTO[] cancelled,
RequestFailedEventDTO[] failed, RequestFailedEventDTO[] failed,
SlotFilledEventDTO[] slotFilled, SlotFilledEventDTO[] slotFilled,
SlotFreedEventDTO[] slotFreed SlotFreedEventDTO[] slotFreed,
SlotReservationsFullEventDTO[] slotReservationsFull
) )
{ {
BlockInterval = blockInterval; BlockInterval = blockInterval;
@ -22,6 +24,9 @@ namespace CodexContractsPlugin.ChainMonitor
Failed = failed; Failed = failed;
SlotFilled = slotFilled; SlotFilled = slotFilled;
SlotFreed = slotFreed; SlotFreed = slotFreed;
SlotReservationsFull = slotReservationsFull;
All = ConcatAll<IHasBlock>(requests, fulfilled, cancelled, failed, slotFilled, SlotFreed, SlotReservationsFull);
} }
public BlockInterval BlockInterval { get; } public BlockInterval BlockInterval { get; }
@ -31,21 +36,8 @@ namespace CodexContractsPlugin.ChainMonitor
public RequestFailedEventDTO[] Failed { get; } public RequestFailedEventDTO[] Failed { get; }
public SlotFilledEventDTO[] SlotFilled { get; } public SlotFilledEventDTO[] SlotFilled { get; }
public SlotFreedEventDTO[] SlotFreed { get; } public SlotFreedEventDTO[] SlotFreed { get; }
public SlotReservationsFullEventDTO[] SlotReservationsFull { get; }
public IHasBlock[] All public IHasBlock[] All { get; }
{
get
{
var all = new List<IHasBlock>();
all.AddRange(Requests);
all.AddRange(Fulfilled);
all.AddRange(Cancelled);
all.AddRange(Failed);
all.AddRange(SlotFilled);
all.AddRange(SlotFreed);
return all.ToArray();
}
}
public static ChainEvents FromBlockInterval(ICodexContracts contracts, BlockInterval blockInterval) public static ChainEvents FromBlockInterval(ICodexContracts contracts, BlockInterval blockInterval)
{ {
@ -66,8 +58,19 @@ namespace CodexContractsPlugin.ChainMonitor
events.GetRequestCancelledEvents(), events.GetRequestCancelledEvents(),
events.GetRequestFailedEvents(), events.GetRequestFailedEvents(),
events.GetSlotFilledEvents(), events.GetSlotFilledEvents(),
events.GetSlotFreedEvents() events.GetSlotFreedEvents(),
events.GetSlotReservationsFull()
); );
} }
private T[] ConcatAll<T>(params T[][] arrays)
{
var result = Array.Empty<T>();
foreach (var array in arrays)
{
result = result.Concat(array).ToArray();
}
return result;
}
} }
} }

View File

@ -16,6 +16,7 @@ namespace CodexContractsPlugin.ChainMonitor
void OnRequestFailed(RequestEvent requestEvent); void OnRequestFailed(RequestEvent requestEvent);
void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex); void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex);
void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex); void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex);
void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex);
} }
public class RequestEvent public class RequestEvent
@ -149,6 +150,14 @@ namespace CodexContractsPlugin.ChainMonitor
handler.OnSlotFreed(new RequestEvent(@event.Block, r), @event.SlotIndex); handler.OnSlotFreed(new RequestEvent(@event.Block, r), @event.SlotIndex);
} }
private void ApplyEvent(SlotReservationsFullEventDTO @event)
{
var r = FindRequest(@event.RequestId);
if (r == null) return;
r.Log($"[{@event.Block.BlockNumber}] SlotReservationsFull (slotIndex:{@event.SlotIndex})");
handler.OnSlotReservationsFull(new RequestEvent(@event.Block, r), @event.SlotIndex);
}
private void ApplyTimeImplicitEvents(ulong blockNumber, DateTime eventsUtc) private void ApplyTimeImplicitEvents(ulong blockNumber, DateTime eventsUtc)
{ {
foreach (var r in requests) foreach (var r in requests)

View File

@ -51,5 +51,10 @@ namespace CodexContractsPlugin.ChainMonitor
{ {
foreach (var handler in Handlers) handler.OnSlotFreed(requestEvent, slotIndex); foreach (var handler in Handlers) handler.OnSlotFreed(requestEvent, slotIndex);
} }
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
{
foreach (var handler in Handlers) handler.OnSlotReservationsFull(requestEvent, slotIndex);
}
} }
} }

View File

@ -32,5 +32,9 @@ namespace CodexContractsPlugin.ChainMonitor
public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex) public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
{ {
} }
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
{
}
} }
} }

View File

@ -1,6 +1,7 @@
using CodexContractsPlugin.Marketplace; using CodexContractsPlugin.Marketplace;
using GethPlugin; using GethPlugin;
using Logging; using Logging;
using Nethereum.Contracts;
using Nethereum.Hex.HexTypes; using Nethereum.Hex.HexTypes;
using NethereumWorkflow.BlockUtils; using NethereumWorkflow.BlockUtils;
using Utils; using Utils;
@ -16,6 +17,7 @@ namespace CodexContractsPlugin
RequestFailedEventDTO[] GetRequestFailedEvents(); RequestFailedEventDTO[] GetRequestFailedEvents();
SlotFilledEventDTO[] GetSlotFilledEvents(); SlotFilledEventDTO[] GetSlotFilledEvents();
SlotFreedEventDTO[] GetSlotFreedEvents(); SlotFreedEventDTO[] GetSlotFreedEvents();
SlotReservationsFullEventDTO[] GetSlotReservationsFull();
} }
public class CodexContractsEvents : ICodexContractsEvents public class CodexContractsEvents : ICodexContractsEvents
@ -38,49 +40,32 @@ namespace CodexContractsPlugin
{ {
var events = gethNode.GetEvents<StorageRequestedEventDTO>(deployment.MarketplaceAddress, BlockInterval); var events = gethNode.GetEvents<StorageRequestedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
var i = new ContractInteractions(log, gethNode); var i = new ContractInteractions(log, gethNode);
return events return events.Select(e =>
.Select(e =>
{ {
var requestEvent = i.GetRequest(deployment.MarketplaceAddress, e.Event.RequestId); var requestEvent = i.GetRequest(deployment.MarketplaceAddress, e.Event.RequestId);
var result = requestEvent.ReturnValue1; var result = requestEvent.ReturnValue1;
result.Block = GetBlock(e.Log.BlockNumber.ToUlong()); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
result.RequestId = e.Event.RequestId; result.RequestId = e.Event.RequestId;
return result; return result;
}) }).ToArray();
.ToArray();
} }
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents() public RequestFulfilledEventDTO[] GetRequestFulfilledEvents()
{ {
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(deployment.MarketplaceAddress, BlockInterval); var events = gethNode.GetEvents<RequestFulfilledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
return events.Select(e => return events.Select(SetBlockOnEvent).ToArray();
{
var result = e.Event;
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result;
}).ToArray();
} }
public RequestCancelledEventDTO[] GetRequestCancelledEvents() public RequestCancelledEventDTO[] GetRequestCancelledEvents()
{ {
var events = gethNode.GetEvents<RequestCancelledEventDTO>(deployment.MarketplaceAddress, BlockInterval); var events = gethNode.GetEvents<RequestCancelledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
return events.Select(e => return events.Select(SetBlockOnEvent).ToArray();
{
var result = e.Event;
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result;
}).ToArray();
} }
public RequestFailedEventDTO[] GetRequestFailedEvents() public RequestFailedEventDTO[] GetRequestFailedEvents()
{ {
var events = gethNode.GetEvents<RequestFailedEventDTO>(deployment.MarketplaceAddress, BlockInterval); var events = gethNode.GetEvents<RequestFailedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
return events.Select(e => return events.Select(SetBlockOnEvent).ToArray();
{
var result = e.Event;
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result;
}).ToArray();
} }
public SlotFilledEventDTO[] GetSlotFilledEvents() public SlotFilledEventDTO[] GetSlotFilledEvents()
@ -98,12 +83,20 @@ namespace CodexContractsPlugin
public SlotFreedEventDTO[] GetSlotFreedEvents() public SlotFreedEventDTO[] GetSlotFreedEvents()
{ {
var events = gethNode.GetEvents<SlotFreedEventDTO>(deployment.MarketplaceAddress, BlockInterval); var events = gethNode.GetEvents<SlotFreedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
return events.Select(e => return events.Select(SetBlockOnEvent).ToArray();
}
public SlotReservationsFullEventDTO[] GetSlotReservationsFull()
{
var events = gethNode.GetEvents<SlotReservationsFullEventDTO>(deployment.MarketplaceAddress, BlockInterval);
return events.Select(SetBlockOnEvent).ToArray();
}
private T SetBlockOnEvent<T>(EventLog<T> e) where T : IHasBlock
{ {
var result = e.Event; var result = e.Event;
result.Block = GetBlock(e.Log.BlockNumber.ToUlong()); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result; return result;
}).ToArray();
} }
private BlockTimeEntry GetBlock(ulong number) private BlockTimeEntry GetBlock(ulong number)

View File

@ -58,5 +58,11 @@ namespace CodexContractsPlugin.Marketplace
[JsonIgnore] [JsonIgnore]
public BlockTimeEntry Block { get; set; } public BlockTimeEntry Block { get; set; }
} }
public partial class SlotReservationsFullEventDTO : 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. #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

View File

@ -51,6 +51,10 @@ namespace MarketInsights
{ {
} }
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
{
}
public MarketTimeSegment GetSegment() public MarketTimeSegment GetSegment()
{ {
return segment; return segment;

View File

@ -75,6 +75,13 @@ namespace TestNetRewarder
); );
} }
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
{
AddRequestBlock(requestEvent, "Slot Reservations Full",
$"Slot Index: {slotIndex}"
);
}
private void AddRequestBlock(RequestEvent requestEvent, string eventName, params string[] content) private void AddRequestBlock(RequestEvent requestEvent, string eventName, params string[] content)
{ {
var blockNumber = $"[{requestEvent.Block.BlockNumber} {FormatDateTime(requestEvent.Block.Utc)}]"; var blockNumber = $"[{requestEvent.Block.BlockNumber} {FormatDateTime(requestEvent.Block.Utc)}]";

View File

@ -72,6 +72,10 @@ namespace TestNetRewarder
{ {
} }
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
{
}
private void GiveReward(RewardConfig reward, EthAddress receiver) private void GiveReward(RewardConfig reward, EthAddress receiver)
{ {
giver.Give(reward, receiver); giver.Give(reward, receiver);