Skip to content

Commit 5313f8a

Browse files
committed
Adds SlotReservationsFull event to chain state tracker
1 parent c239d55 commit 5313f8a

File tree

9 files changed

+85
-50
lines changed

9 files changed

+85
-50
lines changed

ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainEvents.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CodexContractsPlugin.Marketplace;
2+
using System.Collections.Generic;
23
using Utils;
34

45
namespace CodexContractsPlugin.ChainMonitor
@@ -12,7 +13,8 @@ private ChainEvents(
1213
RequestCancelledEventDTO[] cancelled,
1314
RequestFailedEventDTO[] failed,
1415
SlotFilledEventDTO[] slotFilled,
15-
SlotFreedEventDTO[] slotFreed
16+
SlotFreedEventDTO[] slotFreed,
17+
SlotReservationsFullEventDTO[] slotReservationsFull
1618
)
1719
{
1820
BlockInterval = blockInterval;
@@ -22,6 +24,9 @@ SlotFreedEventDTO[] slotFreed
2224
Failed = failed;
2325
SlotFilled = slotFilled;
2426
SlotFreed = slotFreed;
27+
SlotReservationsFull = slotReservationsFull;
28+
29+
All = ConcatAll<IHasBlock>(requests, fulfilled, cancelled, failed, slotFilled, SlotFreed, SlotReservationsFull);
2530
}
2631

2732
public BlockInterval BlockInterval { get; }
@@ -31,21 +36,8 @@ SlotFreedEventDTO[] slotFreed
3136
public RequestFailedEventDTO[] Failed { get; }
3237
public SlotFilledEventDTO[] SlotFilled { get; }
3338
public SlotFreedEventDTO[] SlotFreed { get; }
34-
35-
public IHasBlock[] All
36-
{
37-
get
38-
{
39-
var all = new List<IHasBlock>();
40-
all.AddRange(Requests);
41-
all.AddRange(Fulfilled);
42-
all.AddRange(Cancelled);
43-
all.AddRange(Failed);
44-
all.AddRange(SlotFilled);
45-
all.AddRange(SlotFreed);
46-
return all.ToArray();
47-
}
48-
}
39+
public SlotReservationsFullEventDTO[] SlotReservationsFull { get; }
40+
public IHasBlock[] All { get; }
4941

5042
public static ChainEvents FromBlockInterval(ICodexContracts contracts, BlockInterval blockInterval)
5143
{
@@ -66,8 +58,19 @@ public static ChainEvents FromContractEvents(ICodexContractsEvents events)
6658
events.GetRequestCancelledEvents(),
6759
events.GetRequestFailedEvents(),
6860
events.GetSlotFilledEvents(),
69-
events.GetSlotFreedEvents()
61+
events.GetSlotFreedEvents(),
62+
events.GetSlotReservationsFull()
7063
);
7164
}
65+
66+
private T[] ConcatAll<T>(params T[][] arrays)
67+
{
68+
var result = Array.Empty<T>();
69+
foreach (var array in arrays)
70+
{
71+
result = result.Concat(array).ToArray();
72+
}
73+
return result;
74+
}
7275
}
7376
}

ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainState.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IChainStateChangeHandler
1616
void OnRequestFailed(RequestEvent requestEvent);
1717
void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex);
1818
void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex);
19+
void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex);
1920
}
2021

2122
public class RequestEvent
@@ -149,6 +150,14 @@ private void ApplyEvent(SlotFreedEventDTO @event)
149150
handler.OnSlotFreed(new RequestEvent(@event.Block, r), @event.SlotIndex);
150151
}
151152

153+
private void ApplyEvent(SlotReservationsFullEventDTO @event)
154+
{
155+
var r = FindRequest(@event.RequestId);
156+
if (r == null) return;
157+
r.Log($"[{@event.Block.BlockNumber}] SlotReservationsFull (slotIndex:{@event.SlotIndex})");
158+
handler.OnSlotReservationsFull(new RequestEvent(@event.Block, r), @event.SlotIndex);
159+
}
160+
152161
private void ApplyTimeImplicitEvents(ulong blockNumber, DateTime eventsUtc)
153162
{
154163
foreach (var r in requests)

ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainStateChangeHandlerMux.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,10 @@ public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
5151
{
5252
foreach (var handler in Handlers) handler.OnSlotFreed(requestEvent, slotIndex);
5353
}
54+
55+
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
56+
{
57+
foreach (var handler in Handlers) handler.OnSlotReservationsFull(requestEvent, slotIndex);
58+
}
5459
}
5560
}

ProjectPlugins/CodexContractsPlugin/ChainMonitor/DoNothingChainEventHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger
3232
public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
3333
{
3434
}
35+
36+
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
37+
{
38+
}
3539
}
3640
}

ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CodexContractsPlugin.Marketplace;
22
using GethPlugin;
33
using Logging;
4+
using Nethereum.Contracts;
45
using Nethereum.Hex.HexTypes;
56
using NethereumWorkflow.BlockUtils;
67
using Utils;
@@ -16,6 +17,7 @@ public interface ICodexContractsEvents
1617
RequestFailedEventDTO[] GetRequestFailedEvents();
1718
SlotFilledEventDTO[] GetSlotFilledEvents();
1819
SlotFreedEventDTO[] GetSlotFreedEvents();
20+
SlotReservationsFullEventDTO[] GetSlotReservationsFull();
1921
}
2022

2123
public class CodexContractsEvents : ICodexContractsEvents
@@ -38,49 +40,32 @@ public Request[] GetStorageRequests()
3840
{
3941
var events = gethNode.GetEvents<StorageRequestedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
4042
var i = new ContractInteractions(log, gethNode);
41-
return events
42-
.Select(e =>
43+
return events.Select(e =>
4344
{
44-
var requestEvent = i.GetRequest(deployment.MarketplaceAddress, e.Event.RequestId);
45-
var result = requestEvent.ReturnValue1;
46-
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
47-
result.RequestId = e.Event.RequestId;
48-
return result;
49-
})
50-
.ToArray();
45+
var requestEvent = i.GetRequest(deployment.MarketplaceAddress, e.Event.RequestId);
46+
var result = requestEvent.ReturnValue1;
47+
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
48+
result.RequestId = e.Event.RequestId;
49+
return result;
50+
}).ToArray();
5151
}
5252

5353
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents()
5454
{
5555
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
56-
return events.Select(e =>
57-
{
58-
var result = e.Event;
59-
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
60-
return result;
61-
}).ToArray();
56+
return events.Select(SetBlockOnEvent).ToArray();
6257
}
6358

6459
public RequestCancelledEventDTO[] GetRequestCancelledEvents()
6560
{
6661
var events = gethNode.GetEvents<RequestCancelledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
67-
return events.Select(e =>
68-
{
69-
var result = e.Event;
70-
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
71-
return result;
72-
}).ToArray();
62+
return events.Select(SetBlockOnEvent).ToArray();
7363
}
7464

7565
public RequestFailedEventDTO[] GetRequestFailedEvents()
7666
{
7767
var events = gethNode.GetEvents<RequestFailedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
78-
return events.Select(e =>
79-
{
80-
var result = e.Event;
81-
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
82-
return result;
83-
}).ToArray();
68+
return events.Select(SetBlockOnEvent).ToArray();
8469
}
8570

8671
public SlotFilledEventDTO[] GetSlotFilledEvents()
@@ -98,12 +83,20 @@ public SlotFilledEventDTO[] GetSlotFilledEvents()
9883
public SlotFreedEventDTO[] GetSlotFreedEvents()
9984
{
10085
var events = gethNode.GetEvents<SlotFreedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
101-
return events.Select(e =>
102-
{
103-
var result = e.Event;
104-
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
105-
return result;
106-
}).ToArray();
86+
return events.Select(SetBlockOnEvent).ToArray();
87+
}
88+
89+
public SlotReservationsFullEventDTO[] GetSlotReservationsFull()
90+
{
91+
var events = gethNode.GetEvents<SlotReservationsFullEventDTO>(deployment.MarketplaceAddress, BlockInterval);
92+
return events.Select(SetBlockOnEvent).ToArray();
93+
}
94+
95+
private T SetBlockOnEvent<T>(EventLog<T> e) where T : IHasBlock
96+
{
97+
var result = e.Event;
98+
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
99+
return result;
107100
}
108101

109102
private BlockTimeEntry GetBlock(ulong number)

ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@ public partial class SlotFreedEventDTO : IHasBlock
5858
[JsonIgnore]
5959
public BlockTimeEntry Block { get; set; }
6060
}
61+
62+
public partial class SlotReservationsFullEventDTO : IHasBlock
63+
{
64+
[JsonIgnore]
65+
public BlockTimeEntry Block { get; set; }
66+
}
6167
}
6268
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

Tools/MarketInsights/ContributionBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
5151
{
5252
}
5353

54+
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
55+
{
56+
}
57+
5458
public MarketTimeSegment GetSegment()
5559
{
5660
return segment;

Tools/TestNetRewarder/EventsFormatter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
7575
);
7676
}
7777

78+
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
79+
{
80+
AddRequestBlock(requestEvent, "Slot Reservations Full",
81+
$"Slot Index: {slotIndex}"
82+
);
83+
}
84+
7885
private void AddRequestBlock(RequestEvent requestEvent, string eventName, params string[] content)
7986
{
8087
var blockNumber = $"[{requestEvent.Block.BlockNumber} {FormatDateTime(requestEvent.Block.Utc)}]";

Tools/TestNetRewarder/RewardCheck.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
7272
{
7373
}
7474

75+
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
76+
{
77+
}
78+
7579
private void GiveReward(RewardConfig reward, EthAddress receiver)
7680
{
7781
giver.Give(reward, receiver);

0 commit comments

Comments
 (0)