This commit is contained in:
Danny Ryan 2020-04-02 16:58:39 -06:00
parent 6067c511c5
commit d61b2991a0
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
2 changed files with 19 additions and 13 deletions

View File

@ -108,7 +108,7 @@ SSZObject = TypeVar('SSZObject', bound=View)
PHASE1_IMPORTS = '''from eth2spec.phase0 import spec as phase0 PHASE1_IMPORTS = '''from eth2spec.phase0 import spec as phase0
from eth2spec.config.config_util import apply_constants_config from eth2spec.config.config_util import apply_constants_config
from typing import ( from typing import (
Any, Dict, Set, Sequence, NewType, Tuple, TypeVar, Callable Any, Dict, Set, Sequence, NewType, Tuple, Optional, TypeVar, Callable
) )
from dataclasses import ( from dataclasses import (
@ -373,11 +373,13 @@ class PySpecCommand(Command):
self.md_doc_paths = """ self.md_doc_paths = """
specs/phase0/beacon-chain.md specs/phase0/beacon-chain.md
specs/phase0/fork-choice.md specs/phase0/fork-choice.md
specs/phase0/validator.md
specs/phase1/custody-game.md specs/phase1/custody-game.md
specs/phase1/beacon-chain.md specs/phase1/beacon-chain.md
specs/phase1/fraud-proofs.md specs/phase1/fraud-proofs.md
specs/phase1/fork-choice.md specs/phase1/fork-choice.md
specs/phase1/phase1-fork.md specs/phase1/phase1-fork.md
specs/phase1/validator.md
""" """
else: else:
raise Exception('no markdown files specified, and spec fork "%s" is unknown', self.spec_fork) raise Exception('no markdown files specified, and spec fork "%s" is unknown', self.spec_fork)

View File

@ -132,6 +132,7 @@ def get_successful_shard_transitions(state: BeaconState,
attestations: Attestation) -> Tuple[Sequence[Shard], Sequence[Root]]: attestations: Attestation) -> Tuple[Sequence[Shard], Sequence[Root]]:
shards = [] shards = []
winning_roots = [] winning_roots = []
online_indices = get_online_validator_indices(state)
committee_count = get_committee_count_at_slot(state, slot) committee_count = get_committee_count_at_slot(state, slot)
for committee_index in map(CommitteeIndex, range(committee_count)): for committee_index in map(CommitteeIndex, range(committee_count)):
shard = compute_shard_from_committee_index(state, committee_index, slot) shard = compute_shard_from_committee_index(state, committee_index, slot)
@ -160,7 +161,7 @@ def get_successful_shard_transitions(state: BeaconState,
) )
if enough_online_stake: if enough_online_stake:
shards.append(shard) shards.append(shard)
transitions.append(shard_transition_root) winning_roots.append(shard_transition_root)
break break
return shards, winning_roots return shards, winning_roots
@ -184,7 +185,7 @@ def get_best_light_client_aggregate(block: BeaconBlock,
return max( return max(
viable_aggregates, viable_aggregates,
key=lambda a: len([_ for i in a.aggregation_bits if i == 1]), key=lambda a: len([i for i in a.aggregation_bits if i == 1]),
default=LightClientVote(), default=LightClientVote(),
) )
``` ```
@ -251,9 +252,13 @@ Set `attestation_data.head_shard_root = hash_tree_root(head_shard_block)`.
Set `shard_transition` to the value returned by `get_shard_transition()`. Set `shard_transition` to the value returned by `get_shard_transition()`.
```python ```python
def get_shard_transition(state: BeaconState, shard: Shard, shard_blocks: Sequence[ShardBlock]) -> ShardTransition: def get_shard_transition(state: BeaconState,
shard: Shard,
shard_blocks: Sequence[ShardBlockWrapper]) -> ShardTransition:
"""
latest_shard_slot = get_latest_slot_for_shard(state, shard) latest_shard_slot = get_latest_slot_for_shard(state, shard)
offset_slots = [Slot(latest_shard_slot + x) for x in SHARD_BLOCK_OFFSETS if latest_shard_slot + x <= state.slot] offset_slots = [Slot(latest_shard_slot + x) for x in SHARD_BLOCK_OFFSETS if latest_shard_slot + x <= state.slot]
"""
return ShardTransition() return ShardTransition()
``` ```
@ -279,9 +284,8 @@ Set `attestation.signature = attestation_signature` where `attestation_signature
```python ```python
def get_attestation_signature(state: BeaconState, def get_attestation_signature(state: BeaconState,
attestation_data: AttestationData, attestation_data: AttestationData,
custody_bits_blocks, cb_blocks: List[Bitlist[MAX_VALIDATORS_PER_COMMITTEE], MAX_SHARD_BLOCKS_PER_ATTESTATION],
privkey: int privkey: int) -> BLSSignature:
) -> List[Bitlist[MAX_VALIDATORS_PER_COMMITTEE], MAX_SHARD_BLOCKS_PER_ATTESTATION]:
pass pass
``` ```
@ -408,9 +412,9 @@ First, `light_aggregate_and_proof = get_light_aggregate_and_proof(state, validat
```python ```python
def get_light_aggregate_and_proof(state: BeaconState, def get_light_aggregate_and_proof(state: BeaconState,
aggregator_index: ValidatorIndex, aggregator_index: ValidatorIndex,
aggregate: Attestation, aggregate: Attestation,
privkey: int) -> LightAggregateAndProof: privkey: int) -> LightAggregateAndProof:
return LightAggregateAndProof( return LightAggregateAndProof(
aggregator_index=aggregator_index, aggregator_index=aggregator_index,
aggregate=aggregate, aggregate=aggregate,
@ -422,10 +426,10 @@ Then `signed_light_aggregate_and_proof = SignedLightAggregateAndProof(message=li
```python ```python
def get_light_aggregate_and_proof_signature(state: BeaconState, def get_light_aggregate_and_proof_signature(state: BeaconState,
aggregate_and_proof: LightAggregateAndProof, aggregate_and_proof: LightAggregateAndProof,
privkey: int) -> BLSSignature: privkey: int) -> BLSSignature:
aggregate = aggregate_and_proof.aggregate aggregate = aggregate_and_proof.aggregate
domain = get_domain(state, DOMAIN_CLIENT_AGGREGATE_AND_PROOF, compute_epoch_at_slot(aggregate.data.slot)) domain = get_domain(state, DOMAIN_LIGHT_AGGREGATE_AND_PROOF, compute_epoch_at_slot(aggregate.data.slot))
signing_root = compute_signing_root(aggregate_and_proof, domain) signing_root = compute_signing_root(aggregate_and_proof, domain)
return bls.Sign(privkey, signing_root) return bls.Sign(privkey, signing_root)
``` ```