From 015eaef638831e67e9a3a2388bbfca181592a4e1 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 21 Aug 2025 09:54:46 +0200 Subject: [PATCH] Prints all chain calls every period --- Framework/Utils/TimeRange.cs | 5 ++ .../ChainMonitor/PeriodMonitor.cs | 81 ++++++++++++++----- .../ChainMonitor/PeriodReport.cs | 8 +- .../ChainMonitor/ProofPeriod.cs | 12 +-- .../CodexPlugin/CodexStartupConfig.cs | 10 ++- 5 files changed, 86 insertions(+), 30 deletions(-) diff --git a/Framework/Utils/TimeRange.cs b/Framework/Utils/TimeRange.cs index 35578d17..3812565b 100644 --- a/Framework/Utils/TimeRange.cs +++ b/Framework/Utils/TimeRange.cs @@ -20,5 +20,10 @@ public DateTime From { get; } public DateTime To { get; } public TimeSpan Duration { get; } + + public override string ToString() + { + return $"{Time.FormatTimestamp(From)} -> {Time.FormatTimestamp(To)} ({Time.FormatDuration(Duration)})"; + } } } diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodMonitor.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodMonitor.cs index 4991db7c..35bb462c 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodMonitor.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodMonitor.cs @@ -74,17 +74,13 @@ namespace CodexContractsPlugin.ChainMonitor var callReports = new List(); geth.IterateTransactions(blockRange, (t, blkI, blkUtc) => { - CreateFunctionCallReport(callReports, t, blkUtc); - CreateFunctionCallReport(callReports, t, blkUtc); - CreateFunctionCallReport(callReports, t, blkUtc); - CreateFunctionCallReport(callReports, t, blkUtc); + var reporter = new CallReporter(callReports, t, blkUtc, blkI); + reporter.Run(); + }); var report = new PeriodReport( - new ProofPeriod( - currentPeriod.PeriodNumber, - timeRange.From, - timeRange.To), + new ProofPeriod(currentPeriod.PeriodNumber, timeRange, blockRange), currentPeriod.RequiredProofs.ToArray(), callReports.ToArray()); @@ -92,16 +88,6 @@ namespace CodexContractsPlugin.ChainMonitor reports.Add(report); } - private void CreateFunctionCallReport(List reports, Transaction t, DateTime blockUtc) where TFunc : FunctionMessage, new() - { - if (t.IsTransactionForFunctionMessage()) - { - var func = t.DecodeTransactionToFunctionMessage(); - - reports.Add(new FunctionCallReport(blockUtc, typeof(TFunc).Name, JsonConvert.SerializeObject(func))); - } - } - private void ForEachActiveSlot(IChainStateRequest[] requests, Action action) { foreach (var request in requests) @@ -114,6 +100,65 @@ namespace CodexContractsPlugin.ChainMonitor } } + public class CallReporter + { + private readonly List reports; + private readonly Transaction t; + private readonly DateTime blockUtc; + private readonly ulong blockNumber; + + public CallReporter(List reports, Transaction t, DateTime blockUtc, ulong blockNumber) + { + this.reports = reports; + this.t = t; + this.blockUtc = blockUtc; + this.blockNumber = blockNumber; + } + + public void Run() + { + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + CreateFunctionCallReport(); + } + + private void CreateFunctionCallReport() where TFunc : FunctionMessage, new() + { + if (t.IsTransactionForFunctionMessage()) + { + var func = t.DecodeTransactionToFunctionMessage(); + + reports.Add(new FunctionCallReport(blockUtc, blockNumber, typeof(TFunc).Name, JsonConvert.SerializeObject(func))); + } + } + } + public class PeriodMonitorResult { public PeriodMonitorResult(PeriodReport[] reports) diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodReport.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodReport.cs index 0e2f6dc3..177fe2e9 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodReport.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodReport.cs @@ -23,7 +23,7 @@ namespace CodexContractsPlugin.ChainMonitor { log.Log($" Required: {r.Describe()}"); } - log.Log(" - Calls:"); + log.Log($" - Calls: {FunctionCalls.Length}"); foreach (var f in FunctionCalls) { log.Log($" - {f.Describe()}"); @@ -33,20 +33,22 @@ namespace CodexContractsPlugin.ChainMonitor public class FunctionCallReport { - public FunctionCallReport(DateTime utc, string name, string payload) + public FunctionCallReport(DateTime utc, ulong blockNumber, string name, string payload) { Utc = utc; + BlockNumber = blockNumber; Name = name; Payload = payload; } public DateTime Utc { get; } + public ulong BlockNumber { get; } public string Name { get; } public string Payload { get; } public string Describe() { - return $"[{Time.FormatTimestamp(Utc)}] {Name} = \"{Payload}\""; + return $"[{Time.FormatTimestamp(Utc)}][{BlockNumber}] {Name} = \"{Payload}\""; } } } diff --git a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ProofPeriod.cs b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ProofPeriod.cs index ca428170..25ad5cc8 100644 --- a/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ProofPeriod.cs +++ b/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ProofPeriod.cs @@ -4,20 +4,20 @@ namespace CodexContractsPlugin.ChainMonitor { public class ProofPeriod { - public ProofPeriod(ulong periodNumber, DateTime startUtc, DateTime endUtc) + public ProofPeriod(ulong periodNumber, TimeRange timeRange, BlockInterval blockRange) { PeriodNumber = periodNumber; - StartUtc = startUtc; - EndUtc = endUtc; + TimeRange = timeRange; + BlockRange = blockRange; } public ulong PeriodNumber { get; } - public DateTime StartUtc { get; } - public DateTime EndUtc { get; } + public TimeRange TimeRange { get; } + public BlockInterval BlockRange { get; } public override string ToString() { - return $"{PeriodNumber} - {Time.FormatTimestamp(StartUtc)} -> {Time.FormatTimestamp(EndUtc)}"; + return $"{{{PeriodNumber} - {TimeRange} {BlockRange}}}"; } } } diff --git a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs index 30948506..e5c8db73 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -85,8 +85,11 @@ namespace CodexPlugin { "JSONRPC-WS-CLIENT", "JSONRPC-HTTP-CLIENT", - "codex", - "repostore" + }; + + var alwaysIgnoreTopics = new [] + { + "JSONRPC-CLIENT" }; level = $"{level};" + @@ -94,7 +97,8 @@ namespace CodexPlugin $"{CustomTopics.Libp2p.ToString()!.ToLowerInvariant()}:{string.Join(",", libp2pTopics)};" + $"{CustomTopics.ContractClock.ToString().ToLowerInvariant()}:{string.Join(",", contractClockTopics)};" + $"{CustomTopics.JsonSerialize.ToString().ToLowerInvariant()}:{string.Join(",", jsonSerializeTopics)};" + - $"{CustomTopics.MarketplaceInfra.ToString().ToLowerInvariant()}:{string.Join(",", marketplaceInfraTopics)}"; + $"{CustomTopics.MarketplaceInfra.ToString().ToLowerInvariant()}:{string.Join(",", marketplaceInfraTopics)};" + + $"{CodexLogLevel.Error.ToString()}:{string.Join(",", alwaysIgnoreTopics)}"; if (CustomTopics.BlockExchange != null) {