mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-06 23:43:07 +00:00
Makes chainState fetch requests from chain when it sees events for requests it doesn't already know.
This commit is contained in:
parent
3fe2827080
commit
a4994f96b8
@ -199,21 +199,23 @@ namespace CodexContractsPlugin.ChainMonitor
|
|||||||
private ChainStateRequest? FindRequest(IHasRequestId request)
|
private ChainStateRequest? FindRequest(IHasRequestId request)
|
||||||
{
|
{
|
||||||
var r = requests.SingleOrDefault(r => Equal(r.Request.RequestId, request.RequestId));
|
var r = requests.SingleOrDefault(r => Equal(r.Request.RequestId, request.RequestId));
|
||||||
if (r == null)
|
if (r != null) return r;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var blockNumber = "unknown";
|
var req = contracts.GetRequest(request.RequestId);
|
||||||
if (request is IHasBlock blk)
|
var state = contracts.GetRequestState(req);
|
||||||
{
|
var newRequest = new ChainStateRequest(log, req, state);
|
||||||
blockNumber = blk.Block.BlockNumber.ToString();
|
requests.Add(newRequest);
|
||||||
}
|
return newRequest;
|
||||||
|
}
|
||||||
var msg = $"Received event of type '{request.GetType()}' in block '{blockNumber}' for request by Id: '{request.RequestId}'. " +
|
catch (Exception ex)
|
||||||
$"Failed to find request. Request creation event not seen! (Tracker start time: {TotalSpan.From})";
|
{
|
||||||
|
var msg = "Failed to get request from chain: " + ex;
|
||||||
log.Error(msg);
|
log.Error(msg);
|
||||||
handler.OnError(msg);
|
handler.OnError(msg);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool Equal(byte[] a, byte[] b)
|
private bool Equal(byte[] a, byte[] b)
|
||||||
|
|||||||
@ -3,11 +3,8 @@ using CodexContractsPlugin.Marketplace;
|
|||||||
using GethPlugin;
|
using GethPlugin;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Nethereum.ABI;
|
using Nethereum.ABI;
|
||||||
using Nethereum.ABI.FunctionEncoding.Attributes;
|
|
||||||
using Nethereum.Contracts;
|
using Nethereum.Contracts;
|
||||||
using Nethereum.Hex.HexConvertors.Extensions;
|
|
||||||
using Nethereum.Util;
|
using Nethereum.Util;
|
||||||
using NethereumWorkflow;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Utils;
|
using Utils;
|
||||||
@ -28,6 +25,7 @@ namespace CodexContractsPlugin
|
|||||||
ICodexContractsEvents GetEvents(BlockInterval blockInterval);
|
ICodexContractsEvents GetEvents(BlockInterval blockInterval);
|
||||||
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
||||||
RequestState GetRequestState(Request request);
|
RequestState GetRequestState(Request request);
|
||||||
|
Request GetRequest(byte[] requestId);
|
||||||
ulong GetPeriodNumber(DateTime utc);
|
ulong GetPeriodNumber(DateTime utc);
|
||||||
void WaitUntilNextPeriod();
|
void WaitUntilNextPeriod();
|
||||||
ProofState GetProofState(Request storageRequest, decimal slotIndex, ulong blockNumber, ulong period);
|
ProofState GetProofState(Request storageRequest, decimal slotIndex, ulong blockNumber, ulong period);
|
||||||
@ -126,6 +124,17 @@ namespace CodexContractsPlugin
|
|||||||
return gethNode.Call<RequestStateFunction, RequestState>(Deployment.MarketplaceAddress, func);
|
return gethNode.Call<RequestStateFunction, RequestState>(Deployment.MarketplaceAddress, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Request GetRequest(byte[] requestId)
|
||||||
|
{
|
||||||
|
var func = new GetRequestFunction
|
||||||
|
{
|
||||||
|
RequestId = requestId
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = gethNode.Call<GetRequestFunction, GetRequestOutputDTO>(Deployment.MarketplaceAddress, func);
|
||||||
|
return request.ReturnValue1;
|
||||||
|
}
|
||||||
|
|
||||||
public ulong GetPeriodNumber(DateTime utc)
|
public ulong GetPeriodNumber(DateTime utc)
|
||||||
{
|
{
|
||||||
DateTimeOffset utco = DateTime.SpecifyKind(utc, DateTimeKind.Utc);
|
DateTimeOffset utco = DateTime.SpecifyKind(utc, DateTimeKind.Utc);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user