Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attestation committee refactor #1009

Merged
merged 21 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions scripts/phase0/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ def slot_to_epoch(x): return x // SLOTS_PER_EPOCH

code_lines.append("""
# Monkey patch validator get committee code
_compute_committee = compute_committee
_get_crosslink_committee = get_crosslink_committee
committee_cache = {}


def compute_committee(validator_indices: List[ValidatorIndex],
seed: Bytes32,
index: int,
total_committees: int) -> List[ValidatorIndex]:

param_hash = (hash_tree_root(validator_indices), seed, index, total_committees)
def get_crosslink_committee(state: BeaconState, epoch: Epoch, shard: Shard) -> List[ValidatorIndex]:
active_indices = get_active_validator_indices(state, epoch)
seed = generate_seed(state, epoch)
committee_count = get_epoch_committee_count(state, epoch)
committee_index = (shard + SHARD_COUNT - get_epoch_start_shard(state, epoch)) % SHARD_COUNT
param_hash = (hash_tree_root(active_indices), seed, committee_count, committee_index)

if param_hash in committee_cache:
# print("Cache hit, epoch={0}".format(epoch))
return committee_cache[param_hash]
else:
# print("Cache miss, epoch={0}".format(epoch))
ret = _compute_committee(validator_indices, seed, index, total_committees)
ret = _get_crosslink_committee(state, epoch, shard)
committee_cache[param_hash] = ret
return ret

Expand Down
Loading