Adds block numbers to chainstate event logging
This commit is contained in:
parent
1fa7787d3b
commit
d3488dc907
|
@ -29,6 +29,12 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
TotalSpan = timeRange;
|
TotalSpan = timeRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ChainState FromTimeRange(ILog log, ICodexContracts contracts, TimeRange timeRange, IChainStateChangeHandler changeHandler)
|
||||||
|
{
|
||||||
|
var events = ChainEvents.FromTimeRange(contracts, timeRange);
|
||||||
|
return FromEvents(log, events, changeHandler);
|
||||||
|
}
|
||||||
|
|
||||||
public static ChainState FromEvents(ILog log, ChainEvents events, IChainStateChangeHandler changeHandler)
|
public static ChainState FromEvents(ILog log, ChainEvents events, IChainStateChangeHandler changeHandler)
|
||||||
{
|
{
|
||||||
var state = new ChainState(log, changeHandler, events.BlockInterval.TimeRange);
|
var state = new ChainState(log, changeHandler, events.BlockInterval.TimeRange);
|
||||||
|
@ -69,13 +75,13 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
for (var b = events.BlockInterval.From; b <= events.BlockInterval.To; b++)
|
for (var b = events.BlockInterval.From; b <= events.BlockInterval.To; b++)
|
||||||
{
|
{
|
||||||
var blockEvents = events.All.Where(e => e.Block.BlockNumber == b).ToArray();
|
var blockEvents = events.All.Where(e => e.Block.BlockNumber == b).ToArray();
|
||||||
ApplyEvents(blockEvents, eventUtc);
|
ApplyEvents(b, blockEvents, eventUtc);
|
||||||
|
|
||||||
eventUtc += spanPerBlock;
|
eventUtc += spanPerBlock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyEvents(IHasBlock[] blockEvents, DateTime eventsUtc)
|
private void ApplyEvents(ulong blockNumber, IHasBlock[] blockEvents, DateTime eventsUtc)
|
||||||
{
|
{
|
||||||
foreach (var e in blockEvents)
|
foreach (var e in blockEvents)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +89,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
ApplyEvent(d);
|
ApplyEvent(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyTimeImplicitEvents(eventsUtc);
|
ApplyTimeImplicitEvents(blockNumber, eventsUtc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyEvent(Request request)
|
private void ApplyEvent(Request request)
|
||||||
|
@ -101,7 +107,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
{
|
{
|
||||||
var r = FindRequest(request.RequestId);
|
var r = FindRequest(request.RequestId);
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
r.UpdateState(RequestState.Started);
|
r.UpdateState(request.Block.BlockNumber, RequestState.Started);
|
||||||
handler.OnRequestFulfilled(r);
|
handler.OnRequestFulfilled(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +115,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
{
|
{
|
||||||
var r = FindRequest(request.RequestId);
|
var r = FindRequest(request.RequestId);
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
r.UpdateState(RequestState.Cancelled);
|
r.UpdateState(request.Block.BlockNumber, RequestState.Cancelled);
|
||||||
handler.OnRequestCancelled(r);
|
handler.OnRequestCancelled(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +123,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
{
|
{
|
||||||
var r = FindRequest(request.RequestId);
|
var r = FindRequest(request.RequestId);
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
r.Log("SlotFilled");
|
r.Log($"[{request.Block.BlockNumber}] SlotFilled");
|
||||||
handler.OnSlotFilled(r, request.SlotIndex);
|
handler.OnSlotFilled(r, request.SlotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,18 +131,18 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
{
|
{
|
||||||
var r = FindRequest(request.RequestId);
|
var r = FindRequest(request.RequestId);
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
r.Log("SlotFreed");
|
r.Log($"[{request.Block.BlockNumber}] SlotFreed");
|
||||||
handler.OnSlotFreed(r, request.SlotIndex);
|
handler.OnSlotFreed(r, request.SlotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyTimeImplicitEvents(DateTime eventsUtc)
|
private void ApplyTimeImplicitEvents(ulong blockNumber, DateTime eventsUtc)
|
||||||
{
|
{
|
||||||
foreach (var r in requests)
|
foreach (var r in requests)
|
||||||
{
|
{
|
||||||
if (r.State == RequestState.Started
|
if (r.State == RequestState.Started
|
||||||
&& r.FinishedUtc < eventsUtc)
|
&& r.FinishedUtc < eventsUtc)
|
||||||
{
|
{
|
||||||
r.UpdateState(RequestState.Finished);
|
r.UpdateState(blockNumber, RequestState.Finished);
|
||||||
handler.OnRequestFinished(r);
|
handler.OnRequestFinished(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
ExpiryUtc = request.Block.Utc + TimeSpan.FromSeconds((double)request.Expiry);
|
ExpiryUtc = request.Block.Utc + TimeSpan.FromSeconds((double)request.Expiry);
|
||||||
FinishedUtc = request.Block.Utc + TimeSpan.FromSeconds((double)request.Ask.Duration);
|
FinishedUtc = request.Block.Utc + TimeSpan.FromSeconds((double)request.Ask.Duration);
|
||||||
|
|
||||||
Log($"Created as {State}.");
|
Log($"[{request.Block.BlockNumber}] Created as {State}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request Request { get; }
|
public Request Request { get; }
|
||||||
|
@ -32,9 +32,9 @@ namespace CodexContractsPlugin.ChainMonitor
|
||||||
public DateTime ExpiryUtc { get; }
|
public DateTime ExpiryUtc { get; }
|
||||||
public DateTime FinishedUtc { get; }
|
public DateTime FinishedUtc { get; }
|
||||||
|
|
||||||
public void UpdateState(RequestState newState)
|
public void UpdateState(ulong blockNumber, RequestState newState)
|
||||||
{
|
{
|
||||||
Log($"Transit: {State} -> {newState}");
|
Log($"[{blockNumber}] Transit: {State} -> {newState}");
|
||||||
State = newState;
|
State = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue