Skip to content

Commit a434227

Browse files
committed
Adds retry for block transaction fetch
1 parent 62e5f52 commit a434227

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

Framework/NethereumWorkflow/NethereumInteraction.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ public BlockTimeEntry GetBlockForNumber(ulong number)
146146

147147
public BlockWithTransactions GetBlockWithTransactions(ulong number)
148148
{
149-
return Time.Wait(web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(new BlockParameter(number)));
149+
var retry = new Retry(nameof(GetBlockWithTransactions),
150+
maxTimeout: TimeSpan.FromMinutes(1.0),
151+
sleepAfterFail: TimeSpan.FromSeconds(1.0),
152+
onFail: f => { },
153+
failFast: false);
154+
155+
return retry.Run(() => Time.Wait(web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(new BlockParameter(number))));
150156
}
151157
}
152158
}

ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ICodexContractsEvents
1919
SlotFreedEventDTO[] GetSlotFreedEvents();
2020
SlotReservationsFullEventDTO[] GetSlotReservationsFullEvents();
2121
ProofSubmittedEventDTO[] GetProofSubmittedEvents();
22-
ReserveSlotFunction[] GetReserveSlotCalls();
22+
void GetReserveSlotCalls(Action<ReserveSlotFunction> onFunction);
2323
}
2424

2525
public class CodexContractsEvents : ICodexContractsEvents
@@ -100,15 +100,13 @@ public ProofSubmittedEventDTO[] GetProofSubmittedEvents()
100100
return events.Select(SetBlockOnEvent).ToArray();
101101
}
102102

103-
public ReserveSlotFunction[] GetReserveSlotCalls()
103+
public void GetReserveSlotCalls(Action<ReserveSlotFunction> onFunction)
104104
{
105-
var result = new List<ReserveSlotFunction>();
106105
gethNode.IterateFunctionCalls<ReserveSlotFunction>(BlockInterval, (b, fn) =>
107106
{
108107
fn.Block = b;
109-
result.Add(fn);
108+
onFunction(fn);
110109
});
111-
return result.ToArray();
112110
}
113111

114112
private T SetBlockOnEvent<T>(EventLog<T> e) where T : IHasBlock

Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ protected void WaitForContractStarted(IStoragePurchaseContract r)
266266
// should have filled the slot.
267267

268268
var requestId = r.PurchaseId.ToLowerInvariant();
269-
var calls = GetContracts().GetEvents(GetTestRunTimeRange()).GetReserveSlotCalls();
269+
var calls = new List<ReserveSlotFunction>();
270+
GetContracts().GetEvents(GetTestRunTimeRange()).GetReserveSlotCalls(calls.Add);
270271

271-
Log($"Request '{requestId}' failed to start. There were {calls.Length} hosts who called reserve-slot for it:");
272+
Log($"Request '{requestId}' failed to start. There were {calls.Count} hosts who called reserve-slot for it:");
272273
foreach (var c in calls)
273274
{
274275
Log($" - {c.Block.Utc} Host: {c.FromAddress} RequestId: {c.RequestId.ToHex()} SlotIndex: {c.SlotIndex}");

Tools/TraceContract/ChainTracer.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ public TimeRange TraceChainTimeline()
3636

3737
// For this timeline, we log all the calls to reserve-slot.
3838
var events = contracts.GetEvents(requestTimeline);
39-
output.LogReserveSlotCalls(Filter(events.GetReserveSlotCalls()));
39+
40+
events.GetReserveSlotCalls(call =>
41+
{
42+
if (IsThisRequest(call.RequestId))
43+
{
44+
output.LogReserveSlotCall(call);
45+
log.Log("Found reserve-slot call for slotIndex " + call.SlotIndex);
46+
}
47+
});
4048

4149
log.Log("Writing blockchain output...");
4250
output.WriteContractEvents();
@@ -67,11 +75,6 @@ private DateTime RunToContractEnd(Request request)
6775
return tracker.FinishUtc;
6876
}
6977

70-
private ReserveSlotFunction[] Filter(ReserveSlotFunction[] calls)
71-
{
72-
return calls.Where(c => IsThisRequest(c.RequestId)).ToArray();
73-
}
74-
7578
private Request? GetRequest()
7679
{
7780
var request = FindRequest(LastHour());

Tools/TraceContract/Output.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void Write(Entry e)
113113
log.Log($"[{Time.FormatTimestamp(e.Utc)}] {e.Msg}");
114114
}
115115

116-
private void LogReserveSlotCall(ReserveSlotFunction call)
116+
public void LogReserveSlotCall(ReserveSlotFunction call)
117117
{
118118
Add(call.Block.Utc, $"Reserve-slot called. Index: {call.SlotIndex} Host: '{call.FromAddress}'");
119119
}

0 commit comments

Comments
 (0)