@@ -58,6 +58,8 @@ def __init__(self):
5858 self .seen_miniblock_hashes = set ()
5959
6060 def add_node (self , node_data : HeaderData ):
61+ if node_data .header_dictionary ['commited_headers' ] == []:
62+ node_data .header_dictionary ['commited_headers' ] = node_data .header_dictionary ['proposed_headers' ].copy ()
6163 for header_status in node_data .header_dictionary .keys ():
6264 for header in node_data .header_dictionary [header_status ]:
6365 shard_id = get_shard_id (header )
@@ -74,102 +76,16 @@ def add_node(self, node_data: HeaderData):
7476 def add_miniblocks (self , header : dict [str , Any ], status : str ):
7577 header_struct = Header (header , status )
7678
77- for mention_type , mb in header_struct .miniblocks :
79+ for mention_type , mb , metadata in header_struct .miniblocks :
7880 mb_hash = mb .get ('hash' )
7981 if mb_hash not in self .seen_miniblock_hashes :
8082 self .seen_miniblock_hashes .add (mb_hash )
8183 self .miniblocks [mb_hash ] = mb .copy ()
8284 self .miniblocks [mb_hash ]['mentioned' ] = []
83- metadata = header_struct .metadata .copy ()
85+ # metadata = header_struct.metadata.copy()
8486 metadata ["reserved" ] = decode_reserved_field (mb .get ("reserved" , "" ), mb .get ("txCount" , 0 ))
8587 self .miniblocks [mb_hash ]['mentioned' ].append ((mention_type , metadata ))
8688
87- def get_data_for_header_vertical_report (self ) -> dict [str , dict [int , Any ]]:
88- miniblocks = MiniblockData (self .miniblocks )
89- report : dict [str , dict [int , Any ]] = {}
90- last_epoch = None
91-
92- for shard_id , header_data in self .parsed_headers .items ():
93- header_group_count = 0
94- header_count = 0
95- header_group_name = ""
96- last_epoch = None
97-
98- for header in sorted (header_data .header_dictionary ['commited_headers' ],
99- key = lambda x : get_value ('nonce' , x )):
100-
101- epoch = get_value ('epoch' , header )
102-
103- # reset counters when epoch changes
104- if epoch != last_epoch :
105- header_group_count = 0
106- header_count = 0
107- header_group_name = ""
108- last_epoch = epoch
109-
110- # ensure epoch entry exists and contains all shards as keys
111- if epoch not in report :
112- report [epoch ] = {sid : {} for sid in self .parsed_headers .keys ()}
113-
114- if get_value ('miniBlockHeaders' , header ) == []:
115- continue
116-
117- nonce = get_value ('nonce' , header )
118- round_num = get_value ('round' , header )
119- print (f"Processing header: epoch={ epoch } , shard={ shard_id } , nonce={ nonce } , round={ round_num } " )
120-
121- # build result for this header (only cross-shard miniblocks)
122- result : dict [int , list ] = {}
123- for miniblock in [mb for mb in get_value ('miniBlockHeaders' , header ) if mb .get ('senderShardID' ) == shard_id and mb .get ('receiverShardID' ) != mb .get ('senderShardID' )]:
124- print (f" Processing miniblock: hash={ miniblock .get ('hash' )} , senderShardID={ miniblock .get ('senderShardID' )} , receiverShardID={ miniblock .get ('receiverShardID' )} " )
125- mb_hash = miniblock .get ('hash' )
126- for mention_type , metadata in self .miniblocks [mb_hash ]['mentioned' ]:
127- # skip proposed mentions
128- if 'proposed' in mention_type :
129- continue
130-
131- rn = metadata ['round' ]
132- color = miniblocks .get_color_for_state (mention_type , miniblock ['txCount' ], metadata )
133- shard_name = f'Shard { metadata ["shard_id" ]} ' if metadata ["shard_id" ] != 4294967295 else "MetaShard"
134- # append tuple (label, info, color)
135- result .setdefault (rn , []).append ((shard_name , mb_hash [:15 ] + '...' , COLORS_MAPPING [color ]))
136-
137- # if result empty -> we don't include this nonce at all, don't count it
138- if not result :
139- continue
140-
141- # --- Add this nonce to the report and handle grouping ---
142- # if group start (every 5 actual added nonces)
143- group_size = 5
144- if header_count % group_size == 0 :
145- header_group_count += 1
146- header_group_name = f"Nonces { nonce } "
147- # initialize structure for this group
148- report [epoch ][shard_id ][header_group_count ] = {
149- 'group_name' : header_group_name ,
150- 'rounds' : (round_num , round_num ),
151- 'nonces' : {}
152- }
153- print (f"Creating new header group: { header_group_name } " )
154- else :
155- # extend existing group's name
156- header_group_name += f" - { nonce } "
157- report [epoch ][shard_id ][header_group_count ]['group_name' ] = header_group_name
158-
159- # store the nonce's data
160- report [epoch ][shard_id ][header_group_count ]['nonces' ][nonce ] = result
161-
162- # update group's rounds min/max based on result keys
163- min_r , max_r = report [epoch ][shard_id ][header_group_count ]['rounds' ]
164- actual_min = min (result .keys ())
165- actual_max = max (result .keys ())
166- report [epoch ][shard_id ][header_group_count ]['rounds' ] = (min (min_r , actual_min ), max (max_r , actual_max ))
167-
168- # increment header_count because we added this nonce
169- header_count += 1
170-
171- return report
172-
17389 def get_data_for_header_horizontal_report (self ) -> dict [str , dict [int , Any ]]:
17490 miniblocks = MiniblockData (self .miniblocks )
17591 report : dict [str , dict [int , Any ]] = {}
@@ -193,7 +109,7 @@ def get_data_for_header_horizontal_report(self) -> dict[str, dict[int, Any]]:
193109
194110 # build result for this header (only cross-shard miniblocks)
195111 result : dict [int , list ] = {}
196- for miniblock in [mb for mb in get_value ('miniBlockHeaders' , header ) if mb .get ('senderShardID' ) == shard_id and mb . get ( 'receiverShardID' ) != mb . get ( 'senderShardID' ) ]:
112+ for miniblock in [mb for mb in get_value ('miniBlockHeaders' , header ) if mb .get ('senderShardID' ) == shard_id ]:
197113 mb_hash = miniblock .get ('hash' )
198114 for mention_type , metadata in self .miniblocks [mb_hash ]['mentioned' ]:
199115 # skip proposed mentions
@@ -228,7 +144,7 @@ def get_data_for_header_horizontal_report(self) -> dict[str, dict[int, Any]]:
228144class Header :
229145 def __init__ (self , header : dict [str , Any ], status : str ):
230146 self .metadata : dict [str , Any ] = self .get_header_metadata (header )
231- self .miniblocks : list [tuple [str , dict [str , Any ]]] = self .get_miniblocks (header , status )
147+ self .miniblocks : list [tuple [str , dict [str , Any ], dict [ str , Any ] ]] = self .get_miniblocks (header , status )
232148
233149 # returns 'origin' or 'dest' based on miniblock senderShardID
234150 def get_miniblock_shard_type (self , miniblock_shard_id : int ) -> str :
@@ -244,29 +160,34 @@ def get_header_metadata(self, header: dict[str, Any]) -> dict[str, Any]:
244160 "shard_id" : header .get ('shardID' , 4294967295 ),
245161 }
246162
247- def get_miniblocks (self , header : dict [str , Any ], status : str ) -> list [tuple [str , dict [str , Any ]]]:
163+ def get_miniblocks (self , header : dict [str , Any ], status : str ) -> list [tuple [str , dict [str , Any ], dict [ str , Any ] ]]:
248164 miniblocks = []
249165 if Header .isHeaderV2 (header ):
250166 header = header ['header' ]
251167 for miniblock in header .get ('miniBlockHeaders' , []):
252168 miniblock_mention = self .get_miniblock_shard_type (miniblock ["senderShardID" ]) + f'_{ status } '
253- miniblocks .append ((miniblock_mention , miniblock ))
169+ miniblocks .append ((miniblock_mention , miniblock , self . metadata . copy () ))
254170 if Header .isMetaHeader (header ):
255171 for shard_header in header ['shardInfo' ]:
256172 shard_metadata = self .get_header_metadata (shard_header )
257173 for miniblock in shard_header .get ('shardMiniBlockHeaders' , []):
258174 miniblock_mention = f'{ meta } _{ origin_shard if shard_metadata ['shard_id' ] == miniblock ['senderShardID' ] else dest_shard } _{ status } '
259- miniblocks .append ((miniblock_mention , miniblock ))
175+ miniblocks .append ((miniblock_mention , miniblock , self . metadata . copy () ))
260176 if Header .isMetaHeaderV3 (header ):
261177 for exec_result in shard_header .get ('executionResults' , []):
262178 for miniblock in exec_result .get ('miniBlockHeaders' , []):
263179 miniblock_mention = f'{ meta } _{ origin_shard if shard_metadata ["shard_id" ] == miniblock ["senderShardID" ] else dest_shard } _exec_{ status } '
264- miniblocks .append ((miniblock_mention , miniblock ))
180+ miniblocks .append ((miniblock_mention , miniblock , self . metadata . copy () ))
265181 if Header .isHeaderV3 (header ):
266182 for exec_result in header ['executionResults' ]:
183+ base_exec_result = exec_result .get ('baseExecutionResult' , {})
184+ exec_result_metadata = self .metadata .copy ()
185+ exec_result_metadata ['nonce' ] = base_exec_result .get ('headerNonce' , 0 )
186+
267187 for miniblock in exec_result .get ('miniBlockHeaders' , []):
268188 miniblock_mention = self .get_miniblock_shard_type (miniblock ["senderShardID" ]) + f'_{ status } _exec'
269- miniblocks .append ((miniblock_mention , miniblock ))
189+ exec_result_metadata ['exec_result_hash' ] = miniblock .get ('hash' , '' )
190+ miniblocks .append ((miniblock_mention , miniblock , exec_result_metadata .copy ()))
270191
271192 return miniblocks
272193
0 commit comments