|
1 | 1 | from eth_consensus_specs.test.gloas.block_processing.test_process_payload_attestation import ( |
2 | 2 | prepare_signed_payload_attestation, |
3 | 3 | ) |
| 4 | +from eth_consensus_specs.test.helpers.block import build_empty_block_for_next_slot |
| 5 | +from eth_consensus_specs.test.helpers.execution_payload import ( |
| 6 | + build_signed_execution_payload_envelope, |
| 7 | +) |
| 8 | +from eth_consensus_specs.test.helpers.fork_choice import ( |
| 9 | + add_execution_payload, |
| 10 | + setup_one_block_store, |
| 11 | + tick_and_add_block, |
| 12 | +) |
| 13 | +from eth_consensus_specs.test.helpers.state import state_transition_and_sign_block |
4 | 14 |
|
5 | 15 |
|
6 | 16 | def get_random_payload_attestations(spec, state, rng): |
@@ -36,3 +46,60 @@ def get_random_payload_attestations(spec, state, rng): |
36 | 46 | ) |
37 | 47 |
|
38 | 48 | return [payload_attestation] |
| 49 | + |
| 50 | + |
| 51 | +def ptc_size_balances(spec): |
| 52 | + """ |
| 53 | + Return a balances list sized to PTC_SIZE so each PTC seat can be pinned to a unique validator. |
| 54 | + """ |
| 55 | + return [spec.MAX_EFFECTIVE_BALANCE] * spec.PTC_SIZE |
| 56 | + |
| 57 | + |
| 58 | +def setup_verified_parent_with_distinct_ptc(spec, state): |
| 59 | + """ |
| 60 | + Build a Gloas store with one block at state.slot+1 whose envelope has been delivered, |
| 61 | + and pin each PTC seat for that slot to a distinct validator so each cast vote later |
| 62 | + lands on exactly one position. |
| 63 | + """ |
| 64 | + block_slot = state.slot + 1 |
| 65 | + window_idx = spec.SLOTS_PER_EPOCH + block_slot % spec.SLOTS_PER_EPOCH |
| 66 | + for i in range(spec.PTC_SIZE): |
| 67 | + state.ptc_window[window_idx][i] = spec.ValidatorIndex(i) |
| 68 | + |
| 69 | + store, block_root, block_state, signed_block, test_steps = yield from setup_one_block_store( |
| 70 | + spec, state |
| 71 | + ) |
| 72 | + envelope = build_signed_execution_payload_envelope(spec, block_state, block_root, signed_block) |
| 73 | + yield from add_execution_payload(spec, store, envelope, test_steps) |
| 74 | + return store, block_root, block_state, test_steps |
| 75 | + |
| 76 | + |
| 77 | +def vote_via_child_block( |
| 78 | + spec, |
| 79 | + store, |
| 80 | + parent_root, |
| 81 | + parent_state, |
| 82 | + positions, |
| 83 | + test_steps, |
| 84 | + payload_present=True, |
| 85 | + blob_data_available=True, |
| 86 | +): |
| 87 | + """ |
| 88 | + Deliver PTC votes for parent_root through a child block at parent_state.slot + 1 |
| 89 | + that carries a PayloadAttestation aggregate. |
| 90 | + """ |
| 91 | + aggregate = prepare_signed_payload_attestation( |
| 92 | + spec, |
| 93 | + parent_state, |
| 94 | + slot=parent_state.slot, |
| 95 | + beacon_block_root=parent_root, |
| 96 | + payload_present=payload_present, |
| 97 | + blob_data_available=blob_data_available, |
| 98 | + attesting_indices=[spec.ValidatorIndex(p) for p in positions], |
| 99 | + ) |
| 100 | + |
| 101 | + child_state = parent_state.copy() |
| 102 | + child_block = build_empty_block_for_next_slot(spec, child_state) |
| 103 | + child_block.body.payload_attestations.append(aggregate) |
| 104 | + signed_child = state_transition_and_sign_block(spec, child_state, child_block) |
| 105 | + yield from tick_and_add_block(spec, store, signed_child, test_steps) |
0 commit comments