Adds retry for block transaction fetch

This commit is contained in:
Ben 2025-05-22 13:55:03 +02:00
parent 62e5f523e8
commit a4342273f2
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
5 changed files with 23 additions and 15 deletions

View File

@ -146,7 +146,13 @@ namespace NethereumWorkflow
public BlockWithTransactions GetBlockWithTransactions(ulong number)
{
return Time.Wait(web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(new BlockParameter(number)));
var retry = new Retry(nameof(GetBlockWithTransactions),
maxTimeout: TimeSpan.FromMinutes(1.0),
sleepAfterFail: TimeSpan.FromSeconds(1.0),
onFail: f => { },
failFast: false);
return retry.Run(() => Time.Wait(web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(new BlockParameter(number))));
}
}
}

View File

@ -19,7 +19,7 @@ namespace CodexContractsPlugin
SlotFreedEventDTO[] GetSlotFreedEvents();
SlotReservationsFullEventDTO[] GetSlotReservationsFullEvents();
ProofSubmittedEventDTO[] GetProofSubmittedEvents();
ReserveSlotFunction[] GetReserveSlotCalls();
void GetReserveSlotCalls(Action<ReserveSlotFunction> onFunction);
}
public class CodexContractsEvents : ICodexContractsEvents
@ -100,15 +100,13 @@ namespace CodexContractsPlugin
return events.Select(SetBlockOnEvent).ToArray();
}
public ReserveSlotFunction[] GetReserveSlotCalls()
public void GetReserveSlotCalls(Action<ReserveSlotFunction> onFunction)
{
var result = new List<ReserveSlotFunction>();
gethNode.IterateFunctionCalls<ReserveSlotFunction>(BlockInterval, (b, fn) =>
{
fn.Block = b;
result.Add(fn);
onFunction(fn);
});
return result.ToArray();
}
private T SetBlockOnEvent<T>(EventLog<T> e) where T : IHasBlock

View File

@ -266,9 +266,10 @@ namespace CodexReleaseTests.MarketTests
// should have filled the slot.
var requestId = r.PurchaseId.ToLowerInvariant();
var calls = GetContracts().GetEvents(GetTestRunTimeRange()).GetReserveSlotCalls();
var calls = new List<ReserveSlotFunction>();
GetContracts().GetEvents(GetTestRunTimeRange()).GetReserveSlotCalls(calls.Add);
Log($"Request '{requestId}' failed to start. There were {calls.Length} hosts who called reserve-slot for it:");
Log($"Request '{requestId}' failed to start. There were {calls.Count} hosts who called reserve-slot for it:");
foreach (var c in calls)
{
Log($" - {c.Block.Utc} Host: {c.FromAddress} RequestId: {c.RequestId.ToHex()} SlotIndex: {c.SlotIndex}");

View File

@ -36,7 +36,15 @@ namespace TraceContract
// For this timeline, we log all the calls to reserve-slot.
var events = contracts.GetEvents(requestTimeline);
output.LogReserveSlotCalls(Filter(events.GetReserveSlotCalls()));
events.GetReserveSlotCalls(call =>
{
if (IsThisRequest(call.RequestId))
{
output.LogReserveSlotCall(call);
log.Log("Found reserve-slot call for slotIndex " + call.SlotIndex);
}
});
log.Log("Writing blockchain output...");
output.WriteContractEvents();
@ -67,11 +75,6 @@ namespace TraceContract
return tracker.FinishUtc;
}
private ReserveSlotFunction[] Filter(ReserveSlotFunction[] calls)
{
return calls.Where(c => IsThisRequest(c.RequestId)).ToArray();
}
private Request? GetRequest()
{
var request = FindRequest(LastHour());

View File

@ -113,7 +113,7 @@ namespace TraceContract
log.Log($"[{Time.FormatTimestamp(e.Utc)}] {e.Msg}");
}
private void LogReserveSlotCall(ReserveSlotFunction call)
public void LogReserveSlotCall(ReserveSlotFunction call)
{
Add(call.Block.Utc, $"Reserve-slot called. Index: {call.SlotIndex} Host: '{call.FromAddress}'");
}