-
Notifications
You must be signed in to change notification settings - Fork 973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework Shard transition processing
#1856
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,12 +61,14 @@ | |
- [Operations](#operations) | ||
- [New Attestation processing](#new-attestation-processing) | ||
- [`validate_attestation`](#validate_attestation) | ||
- [Updated `process_attestation`](#updated-process_attestation) | ||
- [Shard transition processing](#shard-transition-processing) | ||
- [`apply_shard_transition`](#apply_shard_transition) | ||
- [`process_crosslink_for_shard`](#process_crosslink_for_shard) | ||
- [`process_crosslinks`](#process_crosslinks) | ||
- [`process_attestation`](#process_attestation) | ||
- [`verify_empty_shard_transition`](#verify_empty_shard_transition) | ||
- [`process_shard_transitions`](#process_shard_transitions) | ||
- [New Attester slashing processing](#new-attester-slashing-processing) | ||
- [Verify empty shard transition](#verify-empty-shard-transition) | ||
- [Light client processing](#light-client-processing) | ||
- [Epoch transition](#epoch-transition) | ||
- [Custody game updates](#custody-game-updates) | ||
|
@@ -671,7 +673,6 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None: | |
process_eth1_data(state, block.body) | ||
process_light_client_signatures(state, block.body) | ||
process_operations(state, block.body) | ||
verify_empty_shard_transition(state, block.body) | ||
``` | ||
|
||
#### Operations | ||
|
@@ -695,7 +696,7 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: | |
# See custody game spec. | ||
process_custody_game_operations(state, body) | ||
|
||
process_crosslinks(state, body.shard_transitions, body.attestations) | ||
process_shard_transitions(state, body.shard_transitions, body.attestations) | ||
|
||
# TODO process_operations(body.shard_receipt_proofs, process_shard_receipt_proofs) | ||
``` | ||
|
@@ -742,6 +743,27 @@ def validate_attestation(state: BeaconState, attestation: Attestation) -> None: | |
assert is_valid_indexed_attestation(state, get_indexed_attestation(state, attestation)) | ||
``` | ||
|
||
###### Updated `process_attestation` | ||
|
||
```python | ||
def process_attestation(state: BeaconState, attestation: Attestation) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To reviewers: only moving the function block to here. Nothing was changed in this function. |
||
validate_attestation(state, attestation) | ||
# Store pending attestation for epoch processing | ||
pending_attestation = PendingAttestation( | ||
aggregation_bits=attestation.aggregation_bits, | ||
data=attestation.data, | ||
inclusion_delay=state.slot - attestation.data.slot, | ||
proposer_index=get_beacon_proposer_index(state), | ||
crosslink_success=False, # To be filled in during process_shard_transitions | ||
) | ||
if attestation.data.target.epoch == get_current_epoch(state): | ||
state.current_epoch_attestations.append(pending_attestation) | ||
else: | ||
state.previous_epoch_attestations.append(pending_attestation) | ||
``` | ||
|
||
##### Shard transition processing | ||
|
||
###### `apply_shard_transition` | ||
|
||
```python | ||
|
@@ -882,23 +904,30 @@ def process_crosslinks(state: BeaconState, | |
pending_attestation.crosslink_success = True | ||
``` | ||
|
||
###### `process_attestation` | ||
###### `verify_empty_shard_transition` | ||
|
||
```python | ||
def process_attestation(state: BeaconState, attestation: Attestation) -> None: | ||
validate_attestation(state, attestation) | ||
# Store pending attestation for epoch processing | ||
pending_attestation = PendingAttestation( | ||
aggregation_bits=attestation.aggregation_bits, | ||
data=attestation.data, | ||
inclusion_delay=state.slot - attestation.data.slot, | ||
proposer_index=get_beacon_proposer_index(state), | ||
crosslink_success=False, # To be filled in during process_crosslinks | ||
) | ||
if attestation.data.target.epoch == get_current_epoch(state): | ||
state.current_epoch_attestations.append(pending_attestation) | ||
else: | ||
state.previous_epoch_attestations.append(pending_attestation) | ||
def verify_empty_shard_transition(state: BeaconState, shard_transitions: Sequence[ShardTransition]) -> bool: | ||
""" | ||
Verify that a `shard_transition` in a block is empty if an attestation was not processed for it. | ||
""" | ||
for shard in range(get_active_shard_count(state)): | ||
if state.shard_states[shard].slot != compute_previous_slot(state.slot): | ||
if shard_transitions[shard] != ShardTransition(): | ||
return False | ||
return True | ||
``` | ||
|
||
###### `process_shard_transitions` | ||
|
||
```python | ||
def process_shard_transitions(state: BeaconState, | ||
shard_transitions: Sequence[ShardTransition], | ||
attestations: Sequence[Attestation]) -> None: | ||
# Process crosslinks | ||
process_crosslinks(state, shard_transitions, attestations) | ||
# Verify the empty proposal shard states | ||
assert verify_empty_shard_transition(state, shard_transitions) | ||
``` | ||
|
||
##### New Attester slashing processing | ||
|
@@ -943,18 +972,6 @@ def process_attester_slashing(state: BeaconState, attester_slashing: AttesterSla | |
assert slashed_any | ||
``` | ||
|
||
#### Verify empty shard transition | ||
|
||
```python | ||
def verify_empty_shard_transition(state: BeaconState, block_body: BeaconBlockBody) -> None: | ||
""" | ||
Verify that ``shard_transitions`` are empty if a crosslink was not formed for the associated shard in this slot. | ||
""" | ||
for shard in range(get_active_shard_count(state)): | ||
if state.shard_states[shard].slot != compute_previous_slot(state.slot): | ||
assert block_body.shard_transitions[shard] == ShardTransition() | ||
``` | ||
|
||
#### Light client processing | ||
|
||
```python | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be neat to convert to:
for_ops(body.shard_transitions, body.attestations, process_shard_transitions)
But it doesn't look feasible today 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But
for_ops
is mainly for executing operation one-by-one, and we need allbody.shard_transitions
andbody.attestations
to process crosslinks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!