reduce validator key count again, fix valid attestation creation - snippet from Danny

This commit is contained in:
protolambda 2019-05-17 21:26:18 +02:00
parent 08d0ff9336
commit 0f00b43698
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 9 additions and 9 deletions

View File

@ -6,7 +6,7 @@ from .helpers.genesis import create_genesis_state
from .utils import spectest, with_args
# Provides a genesis state as first argument to the function decorated with this
with_state = with_args(lambda: [create_genesis_state(spec.SHARD_COUNT * 2)])
with_state = with_args(lambda: [create_genesis_state(spec.SLOTS_PER_EPOCH * 8)])
# shorthand for decorating @with_state @spectest()

View File

@ -6,8 +6,9 @@ from eth2spec.phase0.spec import (
Attestation,
AttestationData,
AttestationDataAndCustodyBit,
get_epoch_start_slot, get_block_root, get_current_epoch, get_previous_epoch, slot_to_epoch, get_shard_delta,
get_crosslink_committee, get_domain, IndexedAttestation, get_attesting_indices, BeaconState, get_block_root_at_slot)
get_epoch_start_slot, get_block_root, get_current_epoch, get_previous_epoch, slot_to_epoch,
get_crosslink_committee, get_domain, IndexedAttestation, get_attesting_indices, BeaconState, get_block_root_at_slot,
get_epoch_start_shard, get_epoch_committee_count)
from eth2spec.phase0.state_transition import (
state_transition, state_transition_to
)
@ -59,11 +60,10 @@ def get_valid_attestation(state, slot=None, signed=False):
if slot is None:
slot = state.slot
if slot_to_epoch(slot) == get_current_epoch(state):
shard = (state.latest_start_shard + slot) % spec.SLOTS_PER_EPOCH
else:
previous_shard_delta = get_shard_delta(state, get_previous_epoch(state))
shard = (state.latest_start_shard - previous_shard_delta + slot) % spec.SHARD_COUNT
epoch = slot_to_epoch(slot)
epoch_start_shard = get_epoch_start_shard(state, epoch)
committees_per_slot = get_epoch_committee_count(state, epoch) // spec.SLOTS_PER_EPOCH
shard = (epoch_start_shard + committees_per_slot * (slot % spec.SLOTS_PER_EPOCH)) % spec.SHARD_COUNT
attestation_data = build_attestation_data(state, slot, shard)

View File

@ -1,6 +1,6 @@
from py_ecc import bls
from eth2spec.phase0 import spec
privkeys = [i + 1 for i in range(spec.SHARD_COUNT * 8)]
privkeys = [i + 1 for i in range(spec.SLOTS_PER_EPOCH * 16)]
pubkeys = [bls.privtopub(privkey) for privkey in privkeys]
pubkey_to_privkey = {pubkey: privkey for privkey, pubkey in zip(privkeys, pubkeys)}