fix get crosslink committee and finalitytests

This commit is contained in:
Danny Ryan 2019-10-12 13:06:52 +09:00
parent b3b9b434b4
commit d98cabf7e7
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
7 changed files with 19 additions and 16 deletions

View File

@ -4,8 +4,8 @@
# Misc
# ---------------------------------------------------------------
# [customized] Just 8 shards for testing purposes
SHARD_COUNT: 8
# [customized] Just 2 committees for slot for testing purposes
COMMITTEES_PER_SLOT: 2
# [customized] unsecure, but fast
TARGET_COMMITTEE_SIZE: 4
# 2**12 (= 4,096)

View File

@ -880,15 +880,16 @@ def get_committee_count(state: BeaconState, epoch: Epoch) -> uint64:
#### `get_crosslink_committee`
```python
def get_crosslink_committee(state: BeaconState, epoch: Epoch, index: uint64) -> Sequence[ValidatorIndex]:
def get_crosslink_committee(state: BeaconState, slot: Slot, index: uint64) -> Sequence[ValidatorIndex]:
"""
Return the crosslink committee at ``epoch`` for ``index``.
"""
epoch = compute_epoch_of_slot(slot)
return compute_committee(
indices=get_active_validator_indices(state, epoch),
seed=get_seed(state, epoch, DOMAIN_BEACON_ATTESTER),
index=index,
count=get_committee_count(state, epoch),
index=(slot % SLOTS_PER_EPOCH) * COMMITTEES_PER_SLOT + index,
count=COMMITTEES_PER_SLOT * SLOTS_PER_EPOCH,
)
```
@ -966,7 +967,7 @@ def get_attesting_indices(state: BeaconState,
"""
Return the set of attesting indices corresponding to ``data`` and ``bits``.
"""
committee = get_crosslink_committee(state, data.target.epoch, data.index)
committee = get_crosslink_committee(state, data.slot, data.index)
return set(index for i, index in enumerate(committee) if bits[i])
```
@ -1506,7 +1507,7 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
assert data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot <= data.slot + SLOTS_PER_EPOCH
committee = get_crosslink_committee(state, data.target.epoch, data.index)
committee = get_crosslink_committee(state, data.slot, data.index)
assert len(attestation.aggregation_bits) == len(attestation.custody_bits) == len(committee)
pending_attestation = PendingAttestation(

View File

@ -150,7 +150,7 @@ def get_committee_assignment(state: BeaconState,
start_slot = compute_start_slot_of_epoch(epoch)
for slot in range(start_slot, start_slot + SLOTS_PER_EPOCH):
for index in range(COMMITTEES_PER_SLOT):
committee = get_crosslink_committee(state, epoch, index)
committee = get_crosslink_committee(state, Slot(slot), index)
if validator_index in committee:
return committee, index, Slot(slot)
return None

View File

@ -48,7 +48,7 @@ def get_valid_attestation(spec, state, slot=None, index=None, signed=False):
crosslink_committee = spec.get_crosslink_committee(
state,
attestation_data.target.epoch,
attestation_data.slot,
attestation_data.index,
)
@ -117,7 +117,7 @@ def get_attestation_signature(spec, state, attestation_data, privkey, custody_bi
def fill_aggregate_attestation(spec, state, attestation):
crosslink_committee = spec.get_crosslink_committee(
state,
attestation.data.target.epoch,
attestation.data.slot,
attestation.data.index,
)
for i in range(len(crosslink_committee)):

View File

@ -82,7 +82,7 @@ def bitlist_from_int(max_len, num_bits, n):
def get_valid_bit_challenge(spec, state, attestation, invalid_custody_bit=False):
crosslink_committee = spec.get_crosslink_committee(
state,
attestation.data.target.epoch,
attestation.data.slot,
attestation.data.crosslink.shard,
)
responder_index = crosslink_committee[0]

View File

@ -53,13 +53,15 @@ def next_epoch_with_attestations(spec,
if fill_cur_epoch and post_state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY:
slot_to_attest = post_state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1
if slot_to_attest >= spec.compute_start_slot_of_epoch(spec.get_current_epoch(post_state)):
cur_attestation = get_valid_attestation(spec, post_state, slot_to_attest)
block.body.attestations.append(cur_attestation)
for index in range(spec.COMMITTEES_PER_SLOT):
cur_attestation = get_valid_attestation(spec, post_state, slot_to_attest, index=index)
block.body.attestations.append(cur_attestation)
if fill_prev_epoch:
slot_to_attest = post_state.slot - spec.SLOTS_PER_EPOCH + 1
prev_attestation = get_valid_attestation(spec, post_state, slot_to_attest)
block.body.attestations.append(prev_attestation)
for index in range(spec.COMMITTEES_PER_SLOT):
prev_attestation = get_valid_attestation(spec, post_state, slot_to_attest, index=index)
block.body.attestations.append(prev_attestation)
state_transition_and_sign_block(spec, post_state, block)
blocks.append(block)

View File

@ -41,7 +41,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support
if remaining_balance < 0:
return
committee = spec.get_crosslink_committee(state, spec.compute_epoch_of_slot(slot), shard)
committee = spec.get_crosslink_committee(state, slot, shard)
# Create a bitfield filled with the given count per attestation,
# exactly on the right-most part of the committee field.