Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 8469ee3

Browse files
author
naterush
committed
minor lints and cleanup to sharding
1 parent d9e58c2 commit 8469ee3

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

casper/protocols/sharding/forkchoice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_max_weight_indexes(scores):
77

88
max_score = max(scores.values())
99

10-
assert max_score != 0, "max_score of a block should never be zero"
10+
assert max_score > 0, "max_score should be greater than zero"
1111

1212
max_weight_estimates = {e for e in scores if scores[e] == max_score}
1313

casper/protocols/sharding/sharding_view.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ def set_child_starting_block(self, tip_block, parent_id, child_id):
6565

6666
def select_random_shards(self, shards_forkchoice):
6767
"""Randomly selects a shard to build on, and sometimes selects another child shard"""
68-
shards_to_build_on = [r.choice([key for key in self.starting_blocks.keys()])]
69-
if (r.randint(0, 1) == 1):
70-
child = str(r.randint(0, 1))
71-
if shards_to_build_on[0] + child in self.starting_blocks:
72-
shards_to_build_on.append(shards_to_build_on[0] + child)
68+
shards_to_build_on = [r.choice(list(self.starting_blocks.keys()))]
69+
if r.choice([True, False]):
70+
child_shard_id = shards_to_build_on[0] + str(r.randint(0, 1))
71+
if child_shard_id in self.starting_blocks:
72+
shards_to_build_on.append(child_shard_id)
7373

7474
return set(shards_to_build_on)
7575

@@ -113,18 +113,6 @@ def update_safe_estimates(self, validator_set):
113113
# check the safety of the top shard!
114114
pass
115115

116-
tip = None
117-
118-
while tip and tip != self.starting_blocks['']:
119-
oracle = CliqueOracle(tip, self, validator_set)
120-
fault_tolerance, _ = oracle.check_estimate_safety()
121-
122-
if fault_tolerance > 0:
123-
self.starting_blocks[''] = tip
124-
return tip
125-
126-
tip = tip.prev_block('')
127-
128116
def _update_protocol_specific_view(self, message):
129117
"""Given a now justified message, updates children and when_recieved"""
130118
assert message.hash in self.justified_messages, "...should not have seen message!"

0 commit comments

Comments
 (0)