|
7 | 7 |
|
8 | 8 |
|
9 | 9 | from jam.types.state.pi import ServiceStat |
10 | | -from jam.utils.constants import EPOCH_LENGTH, SEGMENT_SIZE |
| 10 | +from jam.utils.constants import EPOCH_LENGTH, SEGMENT_SIZE, ROTATION_PERIOD |
| 11 | +from jam.state.transitions.report.guarantee_assignment import assign_fn |
11 | 12 | from tsrkit_types import Uint |
12 | 13 |
|
13 | 14 |
|
@@ -56,11 +57,40 @@ def transition( |
56 | 57 | for preimage in block.extrinsic.preimages: |
57 | 58 | pi_curr[author_index].pre_images_size += len(preimage.blob) |
58 | 59 |
|
59 | | - reporter_set = set([ |
60 | | - sig.validator_index |
61 | | - for guarantee in block.extrinsic.guarantees |
62 | | - for sig in guarantee.signatures |
63 | | - ]) |
| 60 | + curr_mapping, _, prev_mapping, _ = assign_fn(state) |
| 61 | + |
| 62 | + # Build map for remapping keys to current indices |
| 63 | + kappa_lookup = {v.ed25519: i for i, v in enumerate(state.kappa)} |
| 64 | + |
| 65 | + reporter_set = set() |
| 66 | + for guarantee in block.extrinsic.guarantees: |
| 67 | + report_slot = guarantee.slot |
| 68 | + block_slot = block.header.slot |
| 69 | + |
| 70 | + # Determine which mapping to use based on rotation |
| 71 | + is_current_rotation = (report_slot // ROTATION_PERIOD) == (block_slot // ROTATION_PERIOD) |
| 72 | + |
| 73 | + mapping = curr_mapping if is_current_rotation else prev_mapping |
| 74 | + |
| 75 | + assigned_validators = mapping.get(guarantee.report.core_index, []) |
| 76 | + |
| 77 | + # Create a set for O(1) lookup of assigned validator indices |
| 78 | + assigned_validator_indices = {v for v in assigned_validators} |
| 79 | + |
| 80 | + for sig in guarantee.signatures: |
| 81 | + # Check 1: Validator must be assigned to this core |
| 82 | + if sig.validator_index in assigned_validator_indices: |
| 83 | + # If prior rotation (epoch change), map lambda index to kappa index |
| 84 | + if not is_current_rotation and (report_slot // EPOCH_LENGTH) != (block_slot // EPOCH_LENGTH): |
| 85 | + # Get pubkey from Lambda (priot validator set) |
| 86 | + pubkey = state.lambda_[sig.validator_index].ed25519 |
| 87 | + # Add to reporter set if the prior validaor still exists in Kappa |
| 88 | + # Find index in Kappa |
| 89 | + if pubkey in kappa_lookup: |
| 90 | + reporter_set.add(kappa_lookup[pubkey]) |
| 91 | + else: |
| 92 | + reporter_set.add(sig.validator_index) |
| 93 | + |
64 | 94 | for validator_index in reporter_set: |
65 | 95 | pi_curr[validator_index].guarantees += 1 |
66 | 96 |
|
|
0 commit comments