Add `shard: Shard` field to `AttestationData`
This commit is contained in:
parent
e955e6f6e1
commit
3ee0761d17
|
@ -55,7 +55,6 @@
|
|||
- [`get_indexed_attestation`](#get_indexed_attestation)
|
||||
- [`get_committee_count_delta`](#get_committee_count_delta)
|
||||
- [`get_start_shard`](#get_start_shard)
|
||||
- [`get_shard`](#get_shard)
|
||||
- [`get_latest_slot_for_shard`](#get_latest_slot_for_shard)
|
||||
- [`get_offset_slots`](#get_offset_slots)
|
||||
- [Predicates](#predicates)
|
||||
|
@ -165,6 +164,8 @@ class AttestationData(Container):
|
|||
# FFG vote
|
||||
source: Checkpoint
|
||||
target: Checkpoint
|
||||
# Shard vote
|
||||
shard: Shard
|
||||
# Current-slot shard block root
|
||||
shard_head_root: Root
|
||||
# Shard transition root
|
||||
|
@ -624,16 +625,6 @@ def get_start_shard(state: BeaconState, slot: Slot) -> Shard:
|
|||
)
|
||||
```
|
||||
|
||||
#### `get_shard`
|
||||
|
||||
```python
|
||||
def get_shard(state: BeaconState, attestation: Attestation) -> Shard:
|
||||
"""
|
||||
Return the shard that the given ``attestation`` is attesting.
|
||||
"""
|
||||
return compute_shard_from_committee_index(state, attestation.data.index, attestation.data.slot)
|
||||
```
|
||||
|
||||
#### `get_latest_slot_for_shard`
|
||||
|
||||
```python
|
||||
|
@ -833,12 +824,15 @@ def validate_attestation(state: BeaconState, attestation: Attestation) -> None:
|
|||
else:
|
||||
assert attestation.data.source == state.previous_justified_checkpoint
|
||||
|
||||
assert attestation.data.shard == compute_shard_from_committee_index(
|
||||
state, attestation.data.index, attestation.data.slot)
|
||||
|
||||
# Type 1: on-time attestations, the custody bits should be non-empty.
|
||||
if attestation.custody_bits_blocks != []:
|
||||
# Ensure on-time attestation
|
||||
assert is_on_time_attestation(state, attestation)
|
||||
# Correct data root count
|
||||
shard = get_shard(state, attestation)
|
||||
shard = attestation.data.shard
|
||||
assert len(attestation.custody_bits_blocks) == len(get_offset_slots(state, shard))
|
||||
# Correct parent block root
|
||||
assert data.beacon_block_root == get_block_root_at_slot(state, compute_previous_slot(state.slot))
|
||||
|
|
|
@ -47,7 +47,8 @@ class LatestMessage(object):
|
|||
def update_latest_messages(store: Store, attesting_indices: Sequence[ValidatorIndex], attestation: Attestation) -> None:
|
||||
target = attestation.data.target
|
||||
beacon_block_root = attestation.data.beacon_block_root
|
||||
shard = get_shard(store.block_states[beacon_block_root], attestation)
|
||||
# TODO: separate shard chain vote
|
||||
shard = attestation.data.shard
|
||||
for i in attesting_indices:
|
||||
if i not in store.latest_messages or target.epoch > store.latest_messages[i].epoch:
|
||||
store.latest_messages[i] = LatestMessage(
|
||||
|
|
|
@ -148,8 +148,7 @@ def is_valid_fraud_proof(beacon_state: BeaconState,
|
|||
# 2. Check if the shard state transition result is wrong between
|
||||
# `transition.shard_states[offset_index - 1]` to `transition.shard_states[offset_index]`.
|
||||
if offset_index == 0:
|
||||
shard = get_shard(beacon_state, attestation)
|
||||
shard_states = beacon_parent_block.body.shard_transitions[shard].shard_states
|
||||
shard_states = beacon_parent_block.body.shard_transitions[attestation.data.shard].shard_states
|
||||
shard_state = shard_states[len(shard_states) - 1]
|
||||
else:
|
||||
shard_state = transition.shard_states[offset_index - 1] # Not doing the actual state updates here.
|
||||
|
|
|
@ -31,7 +31,7 @@ def run_on_attestation(spec, state, store, attestation, valid=True):
|
|||
latest_message = spec.LatestMessage(
|
||||
epoch=attestation.data.target.epoch,
|
||||
root=attestation.data.beacon_block_root,
|
||||
shard=spec.get_shard(state, attestation),
|
||||
shard=attestation.data.shard,
|
||||
shard_root=attestation.data.shard_head_root,
|
||||
)
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ def apply_shard_and_beacon(spec, state, store, shard_store, shard_blocks_buffer)
|
|||
shard_transition=shard_transition,
|
||||
signed=False,
|
||||
)
|
||||
assert spec.get_shard(state, attestation) == shard
|
||||
assert attestation.data.shard == shard
|
||||
beacon_block.body.attestations = [attestation]
|
||||
beacon_block.body.shard_transitions = shard_transitions
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ def run_attestation_processing(spec, state, attestation, valid=True):
|
|||
yield 'post', state
|
||||
|
||||
|
||||
def build_attestation_data(spec, state, slot, index, shard_transition=None, on_time=True):
|
||||
def build_attestation_data(spec, state, slot, index, shard=None, shard_transition=None, on_time=True):
|
||||
assert state.slot >= slot
|
||||
|
||||
if slot == state.slot:
|
||||
|
@ -77,13 +77,15 @@ def build_attestation_data(spec, state, slot, index, shard_transition=None, on_t
|
|||
)
|
||||
|
||||
if spec.fork == PHASE1:
|
||||
if shard is None:
|
||||
shard = spec.compute_shard_from_committee_index(state, attestation_data.index, attestation_data.slot)
|
||||
attestation_data.shard = shard
|
||||
|
||||
if shard_transition is not None:
|
||||
lastest_shard_data_root_index = len(shard_transition.shard_data_roots) - 1
|
||||
attestation_data.shard_head_root = shard_transition.shard_data_roots[lastest_shard_data_root_index]
|
||||
attestation_data.shard_transition_root = shard_transition.hash_tree_root()
|
||||
else:
|
||||
# No shard transition -> no shard block
|
||||
shard = spec.get_shard(state, spec.Attestation(data=attestation_data))
|
||||
if on_time:
|
||||
shard_transition = spec.get_shard_transition(state, shard, shard_blocks=[])
|
||||
lastest_shard_data_root_index = len(shard_transition.shard_data_roots) - 1
|
||||
|
@ -96,7 +98,7 @@ def build_attestation_data(spec, state, slot, index, shard_transition=None, on_t
|
|||
|
||||
|
||||
def convert_to_valid_on_time_attestation(spec, state, attestation, signed=False):
|
||||
shard = spec.get_shard(state, attestation)
|
||||
shard = spec.compute_shard_from_committee_index(state, attestation.data.index, attestation.data.slot)
|
||||
offset_slots = spec.compute_offset_slots(
|
||||
spec.get_latest_slot_for_shard(state, shard),
|
||||
attestation.data.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY,
|
||||
|
|
Loading…
Reference in New Issue