apply suggestions

This commit is contained in:
dapplion 2024-03-11 11:10:41 +08:00
parent 43dbf8cef5
commit 5f78d2b436
2 changed files with 6 additions and 14 deletions

View File

@ -16,7 +16,6 @@
- [Misc](#misc) - [Misc](#misc)
- [`get_committee_indices`](#get_committee_indices) - [`get_committee_indices`](#get_committee_indices)
- [Beacon state accessors](#beacon-state-accessors) - [Beacon state accessors](#beacon-state-accessors)
- [New `get_committee_attesters`](#new-get_committee_attesters)
- [Modified `get_attesting_indices`](#modified-get_attesting_indices) - [Modified `get_attesting_indices`](#modified-get_attesting_indices)
- [Block processing](#block-processing) - [Block processing](#block-processing)
- [Modified `process_attestation`](#modified-process_attestation) - [Modified `process_attestation`](#modified-process_attestation)
@ -74,15 +73,6 @@ def get_committee_indices(commitee_bits: Bitvector) -> List[CommitteeIndex]:
### Beacon state accessors ### Beacon state accessors
#### New `get_committee_attesters`
```python
def get_committee_attesters(state: BeaconState, slot: Slot,
attesting_bits: Bitlist, index: CommitteeIndex) -> Set[ValidatorIndex]:
committee = get_beacon_committee(state, slot, index)
return set(index for i, index in enumerate(committee) if attesting_bits[i])
```
#### Modified `get_attesting_indices` #### Modified `get_attesting_indices`
```python ```python
@ -94,8 +84,9 @@ def get_attesting_indices(state: BeaconState, attestation: Attestation) -> Set[V
output = set() output = set()
committee_indices = get_committee_indices(attestation.committee_bits) committee_indices = get_committee_indices(attestation.committee_bits)
for index in committee_indices: for index in committee_indices:
attesting_bits = attestation.attesting_bits[index] attesting_bits = attestation.aggregation_bits[index]
committee_attesters = get_committee_attesters(state, attestation.data.slot, attesting_bits, index) committee = get_beacon_committee(state, attestation.data.slot, index)
committee_attesters = set(index for i, index in enumerate(committee) if attesting_bits[i])
output = output.union(committee_attesters) output = output.union(committee_attesters)
return output return output
@ -115,7 +106,6 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
# [Modified in EIP7549] # [Modified in EIP7549]
assert data.index == 0 assert data.index == 0
committee_indices = get_committee_indices(attestation.committee_bits) committee_indices = get_committee_indices(attestation.committee_bits)
assert len(committee_indices) > 0
assert len(committee_indices) == len(attestation.aggregation_bits) assert len(committee_indices) == len(attestation.aggregation_bits)
for index in committee_indices: for index in committee_indices:
assert index < get_committee_count_per_slot(state, data.target.epoch) assert index < get_committee_count_per_slot(state, data.target.epoch)

View File

@ -35,6 +35,8 @@ Attestations received from aggregators with disjoint `committee_bits` sets and e
- Set `attestation_data.index = 0`. - Set `attestation_data.index = 0`.
- Let `aggregation_bits` be a `Bitlist[MAX_VALIDATORS_PER_COMMITTEE]` of length `len(committee)`, where the bit of the index of the validator in the `committee` is set to `0b1`. - Let `aggregation_bits` be a `Bitlist[MAX_VALIDATORS_PER_COMMITTEE]` of length `len(committee)`, where the bit of the index of the validator in the `committee` is set to `0b1`.
- Set `attestation.aggregation_bits = [aggregation_bits]`, a list of length 1 - Set `attestation.aggregation_bits = [aggregation_bits]`, a list of length 1
- Let `committee_bits` be a `Bitvector[MAX_COMMITTEES_PER_SLOT]`, where the bit at the index associated with the validator's committee is set to `0b1`
- Set `attestation.committee_bits = committee_bits`
*Note*: Calling `get_attesting_indices(state, attestation)` should return a list of length equal to 1, containing `validator_index`. *Note*: Calling `get_attesting_indices(state, attestation)` should return a list of length equal to 1, containing `validator_index`.
@ -45,5 +47,5 @@ Attestations received from aggregators with disjoint `committee_bits` sets and e
- Set `attestation_data.index = 0`. - Set `attestation_data.index = 0`.
- Let `aggregation_bits` be a `Bitlist[MAX_VALIDATORS_PER_COMMITTEE]` of length `len(committee)`, where each bit set from each individual attestation is set to `0b1`. - Let `aggregation_bits` be a `Bitlist[MAX_VALIDATORS_PER_COMMITTEE]` of length `len(committee)`, where each bit set from each individual attestation is set to `0b1`.
- Set `attestation.aggregation_bits = [aggregation_bits]`, a list of length 1 - Set `attestation.aggregation_bits = [aggregation_bits]`, a list of length 1
- Set `attestation.committee_bits = committee_bits`, where `committee_bits` has the same value as in each individual attestation