diff --git a/.github/workflows/trace-contract.yaml b/.github/workflows/trace-contract.yaml index f990d4ed..b09ceae1 100644 --- a/.github/workflows/trace-contract.yaml +++ b/.github/workflows/trace-contract.yaml @@ -11,7 +11,7 @@ on: env: SOURCE: ${{ format('{0}/{1}', github.server_url, github.repository) }} BRANCH: ${{ github.ref_name }} - OUTPUT_FOLDER: "~/output" + OUTPUT_FOLDER: output ES_USERNAME: ${{ secrets.ES_USERNAME }} ES_PASSWORD: ${{ secrets.ES_PASSWORD }} ES_HOST: ${{ secrets.ES_HOST }} @@ -38,6 +38,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: contract-trace - path: ~/output/* + path: ${{ env.OUTPUT_FOLDER }}/ if-no-files-found: error retention-days: 7 diff --git a/Framework/NethereumWorkflow/NethereumInteraction.cs b/Framework/NethereumWorkflow/NethereumInteraction.cs index 6a34e848..47b7ee20 100644 --- a/Framework/NethereumWorkflow/NethereumInteraction.cs +++ b/Framework/NethereumWorkflow/NethereumInteraction.cs @@ -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)))); } } } diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs index b46f3c96..eadbf4e9 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs @@ -29,6 +29,7 @@ namespace CodexContractsPlugin AddEnvVar("DISTTEST_NETWORK_URL", address.ToString()); AddEnvVar("HARDHAT_NETWORK", "codexdisttestnetwork"); + AddEnvVar("HARDHAT_IGNITION_CONFIRM_DEPLOYMENT", "false"); AddEnvVar("KEEP_ALIVE", "1"); } diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs index e2d8a11a..6adf4ae7 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsEvents.cs @@ -19,7 +19,7 @@ namespace CodexContractsPlugin SlotFreedEventDTO[] GetSlotFreedEvents(); SlotReservationsFullEventDTO[] GetSlotReservationsFullEvents(); ProofSubmittedEventDTO[] GetProofSubmittedEvents(); - ReserveSlotFunction[] GetReserveSlotCalls(); + void GetReserveSlotCalls(Action onFunction); } public class CodexContractsEvents : ICodexContractsEvents @@ -100,15 +100,13 @@ namespace CodexContractsPlugin return events.Select(SetBlockOnEvent).ToArray(); } - public ReserveSlotFunction[] GetReserveSlotCalls() + public void GetReserveSlotCalls(Action onFunction) { - var result = new List(); gethNode.IterateFunctionCalls(BlockInterval, (b, fn) => { fn.Block = b; - result.Add(fn); + onFunction(fn); }); - return result.ToArray(); } private T SetBlockOnEvent(EventLog e) where T : IHasBlock diff --git a/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs b/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs index 39d2e1b3..390e138b 100644 --- a/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs +++ b/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs @@ -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(); + 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}"); diff --git a/Tools/TraceContract/ChainTracer.cs b/Tools/TraceContract/ChainTracer.cs index c678667a..ec723084 100644 --- a/Tools/TraceContract/ChainTracer.cs +++ b/Tools/TraceContract/ChainTracer.cs @@ -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()); diff --git a/Tools/TraceContract/Output.cs b/Tools/TraceContract/Output.cs index a5d09bb1..255bbf3e 100644 --- a/Tools/TraceContract/Output.cs +++ b/Tools/TraceContract/Output.cs @@ -1,5 +1,4 @@ -using System.IO.Compression; -using System.Numerics; +using System.Numerics; using CodexContractsPlugin.ChainMonitor; using CodexContractsPlugin.Marketplace; using Logging; @@ -24,18 +23,16 @@ namespace TraceContract private readonly ILog log; private readonly List entries = new(); private readonly string folder; - private readonly List files = new(); private readonly Input input; private readonly Config config; public Output(ILog log, Input input, Config config) { - folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + folder = config.GetOuputFolder(); Directory.CreateDirectory(folder); var filename = Path.Combine(folder, $"contract_{input.PurchaseId}"); var fileLog = new FileLog(filename); - files.Add(fileLog.FullFilename + ".log"); foreach (var pair in config.LogReplacements) { fileLog.AddStringReplace(pair.Key, pair.Value); @@ -101,9 +98,14 @@ namespace TraceContract public LogFile CreateNodeLogTargetFile(string node) { - var file = log.CreateSubfile(node); - files.Add(file.Filename); - return file; + return log.CreateSubfile(node); + } + + public void ShowOutputFiles(ILog console) + { + console.Log("Files in output folder:"); + var files = Directory.GetFiles(folder); + foreach (var file in files) console.Log(file); } private void Write(Entry e) @@ -111,21 +113,11 @@ 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}'"); } - public string Package() - { - var outputFolder = config.GetOuputFolder(); - Directory.CreateDirectory(outputFolder); - var filename = Path.Combine(outputFolder, $"contract_{input.PurchaseId}.zip"); - - ZipFile.CreateFromDirectory(folder, filename); - return filename; - } - private void Add(DateTime utc, string msg) { entries.Add(new Entry(utc, msg)); diff --git a/Tools/TraceContract/Program.cs b/Tools/TraceContract/Program.cs index d239373c..50ade56d 100644 --- a/Tools/TraceContract/Program.cs +++ b/Tools/TraceContract/Program.cs @@ -55,9 +55,7 @@ namespace TraceContract Log("Downloading storage nodes logs for the request timerange..."); DownloadStorageNodeLogs(requestTimeRange, entryPoint.Tools); - Log("Packaging..."); - var zipFilename = output.Package(); - Log($"Saved to '{zipFilename}'"); + output.ShowOutputFiles(log); entryPoint.Decommission(false, false, false); Log("Done"); diff --git a/docs/TraceContract_HowTo.png b/docs/TraceContract_HowTo.png new file mode 100644 index 00000000..eaed80f0 Binary files /dev/null and b/docs/TraceContract_HowTo.png differ