Skip to content

Commit 070a744

Browse files
committed
PR Feedback
1 parent bdfb226 commit 070a744

File tree

6 files changed

+45
-41
lines changed

6 files changed

+45
-41
lines changed

eth/beacon/helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _get_element_from_recent_list(
4545
target_slot: int,
4646
slot_relative_position: int) -> Any:
4747
"""
48-
Returns the element from ``target_list`` by the ``target_slot`` number,
48+
Return the element from ``target_list`` by the ``target_slot`` number,
4949
where the the element should be at ``target_slot - slot_relative_position``th
5050
element of the given ``target_list``.
5151
"""
@@ -75,7 +75,7 @@ def get_block_hash(
7575
slot: int,
7676
cycle_length: int) -> Hash32:
7777
"""
78-
Returns the blockhash from ``ActiveState.recent_block_hashes`` by
78+
Return the blockhash from ``ActiveState.recent_block_hashes`` by
7979
``current_block_slot_number``.
8080
"""
8181
if len(recent_block_hashes) != cycle_length * 2:
@@ -192,7 +192,7 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
192192
attestation: 'AttestationRecord',
193193
cycle_length: int) -> Iterable[int]:
194194
"""
195-
Returns committee of the given attestation.
195+
Return committee of the given attestation.
196196
"""
197197
shard_id = attestation.shard_id
198198

@@ -231,7 +231,7 @@ def _get_shuffling_committee_slot_portions(
231231
min_committee_size: int,
232232
shard_count: int) -> Tuple[int, int]:
233233
"""
234-
Returns committees number per slot and slots number per committee.
234+
Return committees number per slot and slots number per committee.
235235
"""
236236
# If there are enough active validators to form committees for every slot
237237
if active_validators_size >= cycle_length * min_committee_size:
@@ -279,7 +279,7 @@ def get_new_shuffling(*,
279279
min_committee_size: int,
280280
shard_count: int) -> Iterable[Iterable[ShardAndCommittee]]:
281281
"""
282-
Returns shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
282+
Return shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
283283
the given active ``validators``.
284284
285285
Two-dimensional:
@@ -356,7 +356,7 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
356356
cycle_length,
357357
)
358358
"""
359-
Returns the proposer index in committee and the ``shard_id``.
359+
Return the block committees and proposer info with BlockCommitteesInfo pack.
360360
"""
361361
# `proposer_index_in_committee` th attester in `shard_and_committee`
362362
# is the proposer of the parent block.

eth/beacon/state_machines/base.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def import_block(
260260
block,
261261
self.chaindb,
262262
self.config,
263+
is_validating_signatures=True,
263264
)
264265

265266
# Validate state roots
@@ -285,17 +286,20 @@ def process_block(
285286
active_state: ActiveState,
286287
block: BaseBeaconBlock,
287288
chaindb: BaseBeaconChainDB,
288-
config: BeaconConfig) -> Tuple[BaseBeaconBlock, CrystallizedState, ActiveState]:
289+
config: BeaconConfig,
290+
is_validating_signatures: bool=True
291+
) -> Tuple[BaseBeaconBlock, CrystallizedState, ActiveState]:
289292
"""
290293
Process ``block`` and return the new crystallized state and active state.
291294
"""
292295
# Process per block state changes (ActiveState)
293-
processing_active_state = cls.compute_per_block_transtion(
296+
processing_active_state = cls.compute_per_block_transition(
294297
crystallized_state,
295298
active_state,
296299
block,
297300
chaindb,
298301
config.CYCLE_LENGTH,
302+
is_validating_signatures=is_validating_signatures,
299303
)
300304

301305
# Process per cycle state changes (CrystallizedState and ActiveState)
@@ -309,12 +313,13 @@ def process_block(
309313
return result_block, processed_crystallized_state, processed_active_state
310314

311315
@classmethod
312-
def compute_per_block_transtion(cls,
313-
crystallized_state: CrystallizedState,
314-
active_state: ActiveState,
315-
block: BaseBeaconBlock,
316-
chaindb: BaseBeaconChainDB,
317-
cycle_length: int) -> ActiveState:
316+
def compute_per_block_transition(cls,
317+
crystallized_state: CrystallizedState,
318+
active_state: ActiveState,
319+
block: BaseBeaconBlock,
320+
chaindb: BaseBeaconChainDB,
321+
cycle_length: int,
322+
is_validating_signatures: bool=True) -> ActiveState:
318323
"""
319324
Process ``block`` and return the new ActiveState.
320325
@@ -349,6 +354,7 @@ def compute_per_block_transtion(cls,
349354
attestation,
350355
chaindb,
351356
cycle_length,
357+
is_validating_signatures=is_validating_signatures,
352358
)
353359

354360
return active_state.copy(
@@ -389,6 +395,7 @@ def propose_block(
389395
block_proposal.block,
390396
chaindb,
391397
config,
398+
is_validating_signatures=False,
392399
)
393400

394401
# Set state roots
@@ -405,7 +412,6 @@ def propose_block(
405412
proposer_attestation = self.attest_proposed_block(
406413
post_crystallized_state,
407414
post_active_state,
408-
active_state,
409415
filled_block_proposal,
410416
chaindb,
411417
config.CYCLE_LENGTH,
@@ -422,7 +428,6 @@ def _update_the_states(self,
422428
def attest_proposed_block(self,
423429
post_crystallized_state: CrystallizedState,
424430
post_active_state: ActiveState,
425-
pre_active_state: ActiveState,
426431
block_proposal: 'BlockProposal',
427432
chaindb: BaseBeaconChainDB,
428433
cycle_length: int,
@@ -461,13 +466,10 @@ def attest_proposed_block(self,
461466
block_proposal.shard_block_hash,
462467
justified_slot,
463468
)
464-
sigs = [
465-
bls.sign(
466-
message,
467-
private_key,
468-
)
469-
]
470-
aggregate_sig = bls.aggregate_sigs(sigs)
469+
sig = bls.sign(
470+
message,
471+
private_key,
472+
)
471473

472474
return self.get_attestation_record_class()(
473475
slot=block_proposal.block.slot_number,
@@ -477,7 +479,7 @@ def attest_proposed_block(self,
477479
attester_bitfield=attester_bitfield,
478480
justified_slot=justified_slot,
479481
justified_block_hash=justified_block_hash,
480-
aggregate_sig=aggregate_sig,
482+
aggregate_sig=sig,
481483
)
482484

483485
#

eth/beacon/state_machines/validation.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def validate_attestation(
9595
recent_block_hashes: Iterable[Hash32],
9696
attestation: 'AttestationRecord',
9797
chaindb: BaseBeaconChainDB,
98-
cycle_length: int) -> None:
98+
cycle_length: int,
99+
is_validating_signatures: bool=True) -> None:
99100
"""
100101
Validate the given ``attestation``.
101102
@@ -124,18 +125,19 @@ def validate_attestation(
124125
# TODO: implement versioning
125126
validate_version(crystallized_state, attestation)
126127

127-
parent_hashes = get_signed_parent_hashes(
128-
recent_block_hashes,
129-
block,
130-
attestation,
131-
cycle_length,
132-
)
133-
validate_aggregate_sig(
134-
crystallized_state,
135-
attestation,
136-
attestation_indices,
137-
parent_hashes,
138-
)
128+
if is_validating_signatures:
129+
parent_hashes = get_signed_parent_hashes(
130+
recent_block_hashes,
131+
block,
132+
attestation,
133+
cycle_length,
134+
)
135+
validate_aggregate_sig(
136+
crystallized_state,
137+
attestation,
138+
attestation_indices,
139+
parent_hashes,
140+
)
139141

140142

141143
def validate_slot(parent_block: 'BaseBeaconBlock',

tests/beacon/state_machines/test_state_machines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_import_block_one(fixture_sm_class,
8080
slot_number=genesis_block.slot_number + 1,
8181
)
8282
sm = fixture_sm_class(chaindb, block_1_shell)
83-
active_state_1 = sm.compute_per_block_transtion(
83+
active_state_1 = sm.compute_per_block_transition(
8484
sm.crystallized_state,
8585
sm.active_state,
8686
block_1_shell,

tests/beacon/test_aggregation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_aggregate_votes(votes_count, random, privkeys, pubkeys):
3232
pre_bitfield = get_empty_bitfield(bit_count)
3333
pre_sigs = ()
3434

35-
random_votes = random.sample([i for i in range(bit_count)], votes_count)
35+
random_votes = random.sample(range(bit_count), votes_count)
3636
message = b'hello'
3737

3838
# Get votes: (committee_index, sig, public_key)

tests/core/bitfield-utils/test_bitfields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_or_bitfields():
140140
@given(st.integers(1, 1000))
141141
def test_set_vote_and_has_vote(bit_count):
142142
bitfield = get_empty_bitfield(bit_count)
143-
index = random.choice([i for i in range(bit_count)])
143+
index = random.choice(range(bit_count))
144144
bitfield = set_voted(bitfield, index)
145145
assert has_voted(bitfield, index)
146146

@@ -150,7 +150,7 @@ def test_set_vote_and_has_vote(bit_count):
150150
def test_has_voted_random(votes_count):
151151
bit_count = 1000
152152
bitfield = get_empty_bitfield(bit_count)
153-
random_votes = random.sample([i for i in range(bit_count)], votes_count)
153+
random_votes = random.sample(range(bit_count), votes_count)
154154

155155
for index in random_votes:
156156
bitfield = set_voted(bitfield, index)

0 commit comments

Comments
 (0)