Skip to content

Commit 25a7a30

Browse files
committed
Better proof period reporting. Default proofSubmitted events to OFF.
1 parent 96510df commit 25a7a30

File tree

4 files changed

+103
-17
lines changed

4 files changed

+103
-17
lines changed

ProjectPlugins/CodexContractsPlugin/ChainMonitor/PeriodMonitor.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public void Update(ulong blockNumber, DateTime eventUtc, IChainStateRequest[] re
3030
currentPeriod = period;
3131
}
3232

33-
public PeriodReport[] GetAndClearReports()
33+
public PeriodMonitorResult GetAndClearReports()
3434
{
3535
var result = reports.ToArray();
3636
reports.Clear();
37-
return result;
37+
return new PeriodMonitorResult(result);
3838
}
3939

4040
private void CreateReportForPeriod(ulong lastBlockInPeriod, ulong periodNumber, IChainStateRequest[] requests)
@@ -67,6 +67,46 @@ private void CreateReportForPeriod(ulong lastBlockInPeriod, ulong periodNumber,
6767
}
6868
}
6969

70+
public class PeriodMonitorResult
71+
{
72+
public PeriodMonitorResult(PeriodReport[] reports)
73+
{
74+
Reports = reports;
75+
76+
CalcStats();
77+
}
78+
79+
public PeriodReport[] Reports { get; }
80+
81+
public bool IsEmpty { get; private set; }
82+
public ulong PeriodLow { get; private set; }
83+
public ulong PeriodHigh { get; private set; }
84+
public float AverageNumSlots { get; private set; }
85+
public float AverageNumProofsRequired { get; private set; }
86+
87+
private void CalcStats()
88+
{
89+
IsEmpty = true;
90+
PeriodLow = ulong.MaxValue;
91+
PeriodHigh = ulong.MinValue;
92+
AverageNumSlots = 0.0f;
93+
AverageNumProofsRequired = 0.0f;
94+
float count = Reports.Length;
95+
96+
foreach (var report in Reports)
97+
{
98+
if (report.TotalProofsRequired > 0) IsEmpty = false;
99+
PeriodLow = Math.Min(PeriodLow, report.PeriodNumber);
100+
PeriodHigh = Math.Min(PeriodHigh, report.PeriodNumber);
101+
AverageNumSlots += Convert.ToSingle(report.TotalNumSlots);
102+
AverageNumProofsRequired += Convert.ToSingle(report.TotalProofsRequired);
103+
}
104+
105+
AverageNumSlots = AverageNumSlots / count;
106+
AverageNumProofsRequired = AverageNumProofsRequired / count;
107+
}
108+
}
109+
70110
public class PeriodReport
71111
{
72112
public PeriodReport(ulong periodNumber, ulong totalNumSlots, ulong totalProofsRequired, PeriodProofMissed[] missedProofs)

Tools/TestNetRewarder/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class Configuration
3131
public int ShowProofPeriodReports { get; set; } = 1;
3232

3333
[Uniform("proof-submitted-events", "pse", "PROOFSUBMITTEDEVENTS", false, "When greater than zero, chain event summary will include proof-submitted events.")]
34-
public int ShowProofSubmittedEvents { get; set; } = 1;
34+
public int ShowProofSubmittedEvents { get; set; } = 0; // Defaulted to zero, aprox 7 to 10 such events every 2 minutes in testnet (from autoclient alone!)
3535

3636
public string LogPath
3737
{

Tools/TestNetRewarder/EmojiMaps.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public class EmojiMaps
8585
public string Failed => "❌";
8686
public string ProofSubmitted => "🎵";
8787
public string ProofReport => "🔎";
88+
public string NoProofsMissed => "🏛";
89+
public string ManyProofsMissed => "😱";
8890

8991
public string StringToEmojis(string input, int outLength)
9092
{

Tools/TestNetRewarder/EventsFormatter.cs

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,60 @@ public void OnError(string msg)
118118
errors.Add(msg);
119119
}
120120

121-
public void ProcessPeriodReports(PeriodReport[] periodReports)
121+
public void ProcessPeriodReports(PeriodMonitorResult reports)
122122
{
123-
var lines = periodReports.Select(FormatPeriodReport).ToList();
124-
lines.Insert(0, FormatPeriodReportLine("period", "totalSlots", "required", "missed"));
123+
if (reports.IsEmpty) return;
124+
125+
var lines = new List<string> {
126+
$"Periods: [{reports.PeriodLow} ... {reports.PeriodHigh}]",
127+
$"Average number of slots: {reports.AverageNumSlots.ToString("F2")}",
128+
$"Average number of proofs required: {reports.AverageNumProofsRequired.ToString("F2")}"
129+
};
130+
131+
AddMissedProofDetails(lines, reports.Reports);
132+
125133
AddBlock(0, $"{emojiMaps.ProofReport} **Proof system report**", lines.ToArray());
126134
}
127135

128-
private string FormatPeriodReport(PeriodReport report)
136+
private void AddMissedProofDetails(List<string> lines, PeriodReport[] reports)
129137
{
130-
return FormatPeriodReportLine(
131-
periodNumber: report.PeriodNumber.ToString(),
132-
totalSlots: report.TotalNumSlots.ToString(),
133-
totalRequired: report.TotalProofsRequired.ToString(),
134-
totalMissed: report.MissedProofs.Length.ToString()
135-
);
138+
var reportsWithMissedProofs = reports.Where(r => r.MissedProofs.Length > 0).ToArray();
139+
if (reportsWithMissedProofs.Length < 1)
140+
{
141+
lines.Add($"No proofs were missed {emojiMaps.NoProofsMissed}");
142+
return;
143+
}
144+
145+
var totalMissed = reportsWithMissedProofs.Sum(r => r.MissedProofs.Length);
146+
if (totalMissed > 10)
147+
{
148+
lines.Add($"[{totalMissed}] proofs were missed {emojiMaps.ManyProofsMissed}");
149+
return;
150+
}
151+
152+
foreach (var report in reportsWithMissedProofs)
153+
{
154+
DescribeMissedProof(lines, report);
155+
}
136156
}
137157

138-
private string FormatPeriodReportLine(string periodNumber, string totalSlots, string totalRequired, string totalMissed)
158+
private void DescribeMissedProof(List<string> lines, PeriodReport report)
139159
{
140-
return $"{periodNumber.PadLeft(10)} {totalSlots.PadLeft(10)} {totalRequired.PadLeft(10)} {totalMissed.PadLeft(10)}";
160+
foreach (var missedProof in report.MissedProofs)
161+
{
162+
DescribeMissedProof(lines, missedProof);
163+
}
164+
}
165+
166+
private void DescribeMissedProof(List<string> lines, PeriodProofMissed missedProof)
167+
{
168+
lines.Add($"[{FormatHost(missedProof.Host)}] missed proof for {FormatRequestId(missedProof.Request)} (slotIndex: {missedProof.SlotIndex})");
169+
}
170+
171+
private string FormatHost(EthAddress? host)
172+
{
173+
if (host == null) return "Unknown host";
174+
return host.Address;
141175
}
142176

143177
private void AddRequestBlock(RequestEvent requestEvent, string eventName, params string[] content)
@@ -189,10 +223,20 @@ private string FormatDateTime(DateTime utc)
189223
}
190224

191225
private string FormatRequestId(RequestEvent requestEvent)
226+
{
227+
return FormatRequestId(requestEvent.Request);
228+
}
229+
230+
private string FormatRequestId(IChainStateRequest request)
231+
{
232+
return FormatRequestId(request.Request.Id);
233+
}
234+
235+
private string FormatRequestId(string id)
192236
{
193237
return
194-
$"({emojiMaps.StringToEmojis(requestEvent.Request.Request.Id, 3)})" +
195-
$"`{requestEvent.Request.Request.Id}`";
238+
$"({emojiMaps.StringToEmojis(id, 3)})" +
239+
$"`{id}`";
196240
}
197241

198242
private string BytesToHexString(byte[] bytes)

0 commit comments

Comments
 (0)