|
22 | 22 | from ..checkpoint import Checkpoint |
23 | 23 | from ..config import Config |
24 | 24 | from ..slot import Slot |
25 | | -from .helpers import flatten_justifications_map, get_justifications_map |
| 25 | +from .helpers import flatten_justifications_map |
26 | 26 | from .types import ( |
27 | 27 | HistoricalBlockHashes, |
28 | 28 | JustificationRoots, |
@@ -337,12 +337,35 @@ def process_attestations( |
337 | 337 | State |
338 | 338 | A new state with updated justification/finalization. |
339 | 339 | """ |
340 | | - # Get justifications, justified slots and historical block hashes are already up to |
341 | | - # date as per the processing in process_block_header |
342 | | - justifications = get_justifications_map( |
343 | | - justifications_roots=self.justifications_roots, |
344 | | - justifications_validators=self.justifications_validators, |
345 | | - validator_count=self.validators.count, |
| 340 | + # NOTE: |
| 341 | + # The state already contains three pieces of data: |
| 342 | + # 1. A list of block roots that have received justification votes. |
| 343 | + # 2. A long sequence of boolean entries representing all validator votes, |
| 344 | + # flattened into a single list. |
| 345 | + # 3. The total number of validators. |
| 346 | + # |
| 347 | + # The flattened vote list is organized so that votes from all validators for |
| 348 | + # each block root appear together, and those groups are simply placed back-to-back. |
| 349 | + # |
| 350 | + # To work with attestations, we must rebuild the intuitive structure: |
| 351 | + # “for each block root, here is the list of validator votes for it”. |
| 352 | + # |
| 353 | + # Reconstructing this is done by cutting the long vote list into consecutive |
| 354 | + # segments, where: |
| 355 | + # - each segment corresponds to one block root, |
| 356 | + # - each segment has length equal to the number of validators, |
| 357 | + # - and the ordering of block roots is preserved. |
| 358 | + flat_justifications = list(self.justifications_validators) |
| 359 | + |
| 360 | + justifications = ( |
| 361 | + { |
| 362 | + root: flat_justifications[ |
| 363 | + i * self.validators.count : (i + 1) * self.validators.count |
| 364 | + ] |
| 365 | + for i, root in enumerate(self.justifications_roots) |
| 366 | + } |
| 367 | + if self.justifications_roots |
| 368 | + else {} |
346 | 369 | ) |
347 | 370 |
|
348 | 371 | # Track state changes to be applied at the end |
|
0 commit comments