Skip to content

Commit 700fe16

Browse files
committed
Clean up
1 parent feab65d commit 700fe16

File tree

2 files changed

+22
-124
lines changed

2 files changed

+22
-124
lines changed

eth/beacon/helpers.py

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,6 @@ def get_hashes_to_sign(latest_block_hashes: Sequence[Hash32],
138138
yield block.hash
139139

140140

141-
@to_tuple
142-
def get_signed_parent_hashes(latest_block_hashes: Sequence[Hash32],
143-
block: 'BaseBeaconBlock',
144-
attestation: 'AttestationRecord',
145-
epoch_length: int) -> Iterable[Hash32]:
146-
"""
147-
Given an attestation and the block they were included in,
148-
the list of hashes that were included in the signature.
149-
"""
150-
yield from get_hashes_from_latest_block_hashes(
151-
latest_block_hashes,
152-
block.slot,
153-
from_slot=attestation.slot - epoch_length + 1,
154-
to_slot=attestation.slot - len(attestation.oblique_parent_hashes),
155-
epoch_length=epoch_length,
156-
)
157-
yield from attestation.oblique_parent_hashes
158-
159-
160141
@to_tuple
161142
def get_new_latest_block_hashes(old_block_hashes: Sequence[Hash32],
162143
parent_slot: int,
@@ -199,7 +180,7 @@ def get_shard_committees_at_slot(state: 'BeaconState',
199180
slot: int,
200181
epoch_length: int) -> Tuple[ShardCommittee]:
201182
"""
202-
Returns the ``ShardCommittee`` for the ``slot``.
183+
Return the ``ShardCommittee`` for the ``slot``.
203184
"""
204185
return _get_shard_committees_at_slot(
205186
latest_state_recalculation_slot=state.latest_state_recalculation_slot,
@@ -209,30 +190,9 @@ def get_shard_committees_at_slot(state: 'BeaconState',
209190
)
210191

211192

212-
@to_tuple
213-
def get_attestation_indices(crystallized_state: 'CrystallizedState',
214-
attestation: 'AttestationRecord',
215-
epoch_length: int) -> Iterable[int]:
216-
"""
217-
FIXME
218-
Return committee of the given attestation.
219-
"""
220-
shard_id = attestation.shard_id
221-
222-
shards_committees_for_slot = get_shard_committees_at_slot(
223-
crystallized_state,
224-
attestation.slot,
225-
epoch_length,
226-
)
227-
228-
for shard_committee in shards_committees_for_slot:
229-
if shard_committee.shard_id == shard_id:
230-
yield from shard_committee.committee
231-
232-
233193
def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tuple[int, ...]:
234194
"""
235-
Gets indices of active validators from ``validators``.
195+
Get indices of active validators from ``validators``.
236196
"""
237197
return tuple(
238198
i for i, v in enumerate(validators)
@@ -250,7 +210,7 @@ def _get_shards_committees_for_shard_indices(
250210
total_validator_count: int,
251211
shard_count: int) -> Iterable[ShardCommittee]:
252212
"""
253-
Returns filled [ShardCommittee] tuple.
213+
Return filled [ShardCommittee] tuple.
254214
"""
255215
for index, indices in enumerate(shard_indices):
256216
yield ShardCommittee(
@@ -383,7 +343,7 @@ def get_beacon_proposer_index(state: 'BeaconState',
383343
slot: int,
384344
epoch_length: int) -> int:
385345
"""
386-
Returns the beacon proposer index for the ``slot``.
346+
Return the beacon proposer index for the ``slot``.
387347
"""
388348
shard_committees = get_shard_committees_at_slot(
389349
state,
@@ -408,14 +368,6 @@ def get_beacon_proposer_index(state: 'BeaconState',
408368
#
409369
# Bitfields
410370
#
411-
@to_tuple
412-
def _get_shard_committees(shard_committees: Sequence[ShardCommittee],
413-
shard: int) -> Iterable[ShardCommittee]:
414-
for item in shard_committees:
415-
if item.shard == shard:
416-
yield item
417-
418-
419371
@to_tuple
420372
def get_attestation_participants(state: 'BeaconState',
421373
slot: int,
@@ -427,14 +379,21 @@ def get_attestation_participants(state: 'BeaconState',
427379
from ``participation_bitfield``.
428380
"""
429381
# Find the relevant committee
430-
shard_committees = _get_shard_committees(
431-
shard_committees=get_shard_committees_at_slot(
432-
state,
433-
slot,
434-
epoch_length,
435-
),
436-
shard=shard,
382+
# Filter by slot
383+
shard_committees_at_slot = get_shard_committees_at_slot(
384+
state,
385+
slot,
386+
epoch_length,
387+
)
388+
# Filter by shard
389+
shard_committees = tuple(
390+
[
391+
shard_committee
392+
for shard_committee in shard_committees_at_slot
393+
if shard_committee.shard == shard
394+
]
437395
)
396+
438397
try:
439398
shard_committee = shard_committees[0]
440399
except IndexError:

tests/beacon/test_helpers.py

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from eth.beacon.enums.validator_status_codes import (
44
ValidatorStatusCode,
55
)
6-
from eth.beacon.types.attestation_records import AttestationRecord
76
from eth.beacon.types.blocks import BaseBeaconBlock
87
from eth.beacon.types.shard_committees import ShardCommittee
98
from eth.beacon.types.states import BeaconState
@@ -12,14 +11,12 @@
1211
_get_element_from_recent_list,
1312
get_active_validator_indices,
1413
get_attestation_participants,
15-
get_attestation_indices,
1614
get_beacon_proposer_index,
1715
get_block_hash,
1816
get_hashes_from_latest_block_hashes,
1917
get_hashes_to_sign,
2018
get_new_shuffling,
2119
_get_shard_committees_at_slot,
22-
get_signed_parent_hashes,
2320
get_block_committees_info,
2421
)
2522

@@ -145,7 +142,6 @@ def test_get_block_hash(
145142
)
146143

147144

148-
@pytest.mark.xfail(reason="Need to be fixed")
149145
@pytest.mark.parametrize(
150146
(
151147
'epoch_length,current_block_slot,from_slot,to_slot'
@@ -156,13 +152,13 @@ def test_get_block_hash(
156152
],
157153
)
158154
def test_get_hashes_from_latest_block_hashes(
159-
genesis_block,
155+
sample_block,
160156
current_block_slot,
161157
from_slot,
162158
to_slot,
163159
epoch_length):
164160
_, latest_block_hashes = generate_mock_latest_block_hashes(
165-
genesis_block,
161+
sample_block,
166162
current_block_slot,
167163
epoch_length,
168164
)
@@ -177,12 +173,11 @@ def test_get_hashes_from_latest_block_hashes(
177173
assert len(result) == to_slot - from_slot + 1
178174

179175

180-
@pytest.mark.xfail(reason="Need to be fixed")
181-
def test_get_hashes_to_sign(genesis_block, epoch_length):
176+
def test_get_hashes_to_sign(sample_block, epoch_length):
182177
epoch_length = epoch_length
183178
current_block_slot = 1
184179
blocks, latest_block_hashes = generate_mock_latest_block_hashes(
185-
genesis_block,
180+
sample_block,
186181
current_block_slot,
187182
epoch_length,
188183
)
@@ -197,34 +192,6 @@ def test_get_hashes_to_sign(genesis_block, epoch_length):
197192
assert result[-1] == block.hash
198193

199194

200-
@pytest.mark.xfail(reason="Need to be fixed")
201-
def test_get_new_latest_block_hashes(genesis_block,
202-
epoch_length,
203-
sample_attestation_record_params):
204-
epoch_length = epoch_length
205-
current_block_slot = 15
206-
blocks, latest_block_hashes = generate_mock_latest_block_hashes(
207-
genesis_block,
208-
current_block_slot,
209-
epoch_length,
210-
)
211-
212-
block = blocks[current_block_slot]
213-
oblique_parent_hashes = [b'\x77' * 32]
214-
attestation = AttestationRecord(**sample_attestation_record_params).copy(
215-
slot=10,
216-
oblique_parent_hashes=oblique_parent_hashes,
217-
)
218-
result = get_signed_parent_hashes(
219-
latest_block_hashes,
220-
block,
221-
attestation,
222-
epoch_length,
223-
)
224-
assert len(result) == epoch_length
225-
assert result[-1] == oblique_parent_hashes[-1]
226-
227-
228195
#
229196
# Get shards_committees or indices
230197
#
@@ -325,34 +292,6 @@ def test_get_shard_committee_for_slot(
325292
)
326293

327294

328-
@pytest.mark.xfail(reason="Need to be fixed")
329-
# @pytest.mark.parametrize(
330-
# (
331-
# 'num_validators,'
332-
# 'epoch_length,min_committee_size'
333-
# ),
334-
# [
335-
# (1000, 20, 10),
336-
# ],
337-
# )
338-
def test_get_attestation_indices(genesis_crystallized_state,
339-
sample_attestation_record_params,
340-
epoch_length,
341-
min_committee_size):
342-
attestation = AttestationRecord(**sample_attestation_record_params)
343-
attestation = attestation.copy(
344-
slot=0,
345-
shard_id=0,
346-
)
347-
348-
attestation_indices = get_attestation_indices(
349-
genesis_crystallized_state,
350-
attestation,
351-
epoch_length,
352-
)
353-
assert len(attestation_indices) >= min_committee_size
354-
355-
356295
#
357296
# Shuffling
358297
#

0 commit comments

Comments
 (0)