Skip to content

Commit 87acb82

Browse files
committed
MX-17306 Cleanup, added miniblock timeline gap indicator
1 parent 0a5a890 commit 87acb82

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

multiversx_cross_shard_analysis/miniblock_data.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ def get_data_for_header_report(self) -> dict[int, dict[int, Any]]:
138138
if "proposed" in mention_type:
139139
continue
140140

141-
print(f"Processing miniblock {mb_hash} mentioned in header nonce {header.get('nonce')} round {header.get('round')} epoch {header.get('epoch')} shard {header.get('shard_id')}")
142-
# epoch = header.get('epoch')
143141
if epoch not in report:
144142
report[epoch] = {}
145143

@@ -160,7 +158,30 @@ def get_data_for_header_report(self) -> dict[int, dict[int, Any]]:
160158

161159
report[epoch][shard_id][nonce][round_number].append((label, mb_hash[:15] + '...', color))
162160

163-
with open('debug_miniblock_header_report.json', 'w') as f:
164-
import json
165-
json.dump(report, f, indent=4, default=lambda o: o.name if isinstance(o, Enum) else str(o))
166-
return report
161+
return sort_report(report)
162+
163+
164+
def sort_report(report: dict[int, dict[int, Any]]) -> dict[int, dict[int, Any]]:
165+
out: dict[int, dict[int, Any]] = {}
166+
167+
for epoch in sorted(report.keys()):
168+
out[epoch] = {}
169+
170+
# metas hard (4294967295) last
171+
shard_ids = sorted(
172+
report[epoch].keys(),
173+
key=lambda s: (s == 4294967295, s),
174+
)
175+
176+
for shard_id in shard_ids:
177+
out[epoch][shard_id] = {}
178+
179+
for nonce in sorted(report[epoch][shard_id].keys()):
180+
rounds = report[epoch][shard_id][nonce]
181+
182+
out[epoch][shard_id][nonce] = {
183+
r: rounds[r]
184+
for r in sorted(rounds.keys())
185+
}
186+
187+
return out

multiversx_cross_shard_analysis/miniblocks_timeline_report.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ def build_stack_for_round(items: list[tuple[str, str, colors.Color]], col_width:
123123
# -----------------------------
124124
# miniblock section
125125
# -----------------------------
126+
def has_round_gap(rounds: list[int]) -> bool:
127+
if len(rounds) < 2:
128+
return False
129+
for a, b in zip(rounds, rounds[1:]):
130+
if b != a + 1:
131+
return True
132+
return False
133+
134+
126135
def build_miniblock_section(miniblock: dict[str, Any], page_usable_width: float) -> list[Flowable]:
127136
flow = []
128137
styles = getSampleStyleSheet()
@@ -143,9 +152,8 @@ def build_miniblock_section(miniblock: dict[str, Any], page_usable_width: float)
143152
flow.append(Spacer(1, 6))
144153
return flow
145154

146-
first_r = miniblock.get("first_seen_round", 0)
147-
last_r = miniblock.get("last_seen_round", 0)
148-
rounds = list(range(first_r, last_r + 1))
155+
mentioned = miniblock.get("mentioned", {})
156+
rounds = sorted(mentioned.keys())
149157

150158
num_cols = max(1, len(rounds))
151159
col_width = page_usable_width / num_cols
@@ -160,24 +168,26 @@ def build_miniblock_section(miniblock: dict[str, Any], page_usable_width: float)
160168
items = mentioned.get(r, [])
161169
drawing = build_stack_for_round(items, col_width)
162170
cells.append(drawing)
171+
gap = has_round_gap(rounds)
163172

164173
tbl = Table(
165174
[header, cells],
166175
colWidths=[col_width] * num_cols,
167176
hAlign="LEFT",
168177
)
169178

170-
tbl.setStyle(
171-
TableStyle(
172-
[
173-
("GRID", (0, 0), (-1, -1), 0.25, colors.grey),
174-
("BACKGROUND", (0, 0), (-1, 0), colors.whitesmoke),
175-
("ALIGN", (0, 0), (-1, 0), "CENTER"),
176-
("FONTSIZE", (0, 0), (-1, 0), ROUND_HEADER_FONT),
177-
("VALIGN", (0, 1), (-1, -1), "TOP"),
178-
]
179-
)
180-
)
179+
style = [
180+
("GRID", (0, 0), (-1, -1), 0.25, colors.grey),
181+
("BACKGROUND", (0, 0), (-1, 0), colors.whitesmoke),
182+
("ALIGN", (0, 0), (-1, 0), "CENTER"),
183+
("FONTSIZE", (0, 0), (-1, 0), ROUND_HEADER_FONT),
184+
("VALIGN", (0, 1), (-1, -1), "TOP"),
185+
]
186+
187+
if gap:
188+
style.append(("BOX", (0, 0), (-1, -1), 2, colors.red))
189+
190+
tbl.setStyle(TableStyle(style))
181191

182192
flow.append(tbl)
183193
flow.append(Spacer(1, 8))

0 commit comments

Comments
 (0)