Merge pull request #91 from status-im/spec-cleanup

spec: remove unused code, fix state_sim speed
This commit is contained in:
Dustin Brody 2019-02-07 14:23:15 +00:00 committed by GitHub
commit 2774e5a67a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 28 deletions

View File

@ -156,7 +156,9 @@ proc makeAttestation(node: BeaconNode,
if get_current_epoch(node.beaconState) == node.beaconState.justified_epoch:
return
let justifiedBlockRoot = get_block_root(node.beaconState, get_epoch_start_slot(node.beaconState.justified_epoch))
let justifiedBlockRoot =
get_block_root(node.beaconState,
get_epoch_start_slot(node.beaconState.justified_epoch))
var attestationData = AttestationData(
slot: slot,
@ -281,9 +283,9 @@ proc scheduleEpochActions(node: BeaconNode, epoch: uint64) =
# see the comments in `get_beacon_proposer_index`
var nextState = node.beaconState
for i in 1.uint64 ..< EPOCH_LENGTH:
for i in 0.uint64 ..< EPOCH_LENGTH:
# Schedule block proposals
let slot = epoch * EPOCH_LENGTH + i
let slot = epoch * EPOCH_LENGTH + i + 1
nextState.slot = slot
let proposerIdx = get_beacon_proposer_index(nextState, slot)
let validator = node.getAttachedValidator(proposerIdx)
@ -295,12 +297,9 @@ proc scheduleEpochActions(node: BeaconNode, epoch: uint64) =
scheduleBlockProposal(node, slot, validator)
# Schedule attestations
let
committeesIdx = get_shard_committees_index(nextState, slot)
#for shard in node.beaconState.shard_committees_at_slots[committees_idx]:
for crosslink_committee in get_crosslink_committees_at_slot(
node.beaconState, committees_idx):
node.beaconState, slot):
#for i, validatorIdx in shard.committee:
for i, validatorIdx in crosslink_committee.committee:
let validator = node.getAttachedValidator(validatorIdx)

View File

@ -31,9 +31,6 @@ func verify_bitfield*(bitfield: openarray[byte], committee_size: int): bool =
true
func mod_get[T](arr: openarray[T], pos: Natural): T =
arr[pos mod arr.len]
func shuffle*[T](values: seq[T], seed: Eth2Digest): seq[T] =
## Returns the shuffled ``values`` with seed as entropy.
## TODO: this calls out for tests, but I odn't particularly trust spec
@ -114,15 +111,6 @@ func repeat_hash*(v: Eth2Digest, n: SomeInteger): Eth2Digest =
result = eth2hash(result.data)
dec n
func get_shard_committees_index*(state: BeaconState, slot: uint64): uint64 =
# TODO temporary adapter; remove when all users gone
## Warning: as it stands, this helper only works during state updates _after_
## state.slot has been incremented but before shard_committees_at_slots has
## been updated!
# TODO spec unsigned-unsafe here
doAssert slot + (state.slot mod EPOCH_LENGTH) + EPOCH_LENGTH > state.slot
slot + (state.slot mod EPOCH_LENGTH) + EPOCH_LENGTH - state.slot
func integer_squareroot*(n: SomeInteger): SomeInteger =
## The largest integer ``x`` such that ``x**2`` is less than ``n``.
var

View File

@ -66,13 +66,6 @@ func get_previous_epoch_committee_count(state: BeaconState): uint64 =
)
get_epoch_committee_count(len(previous_active_validators))
func get_current_epoch_committee_count_per_slot(state: BeaconState): uint64 =
let current_active_validators = get_active_validator_indices(
state.validator_registry,
state.current_calculation_epoch,
)
get_epoch_committee_count(len(current_active_validators))
func get_crosslink_committees_at_slot*(state: BeaconState, slot: uint64):
seq[CrosslinkCommittee] =
## Returns the list of ``(committee, shard)`` tuples for the ``slot``.
@ -86,7 +79,7 @@ func get_crosslink_committees_at_slot*(state: BeaconState, slot: uint64):
assert previous_epoch <= epoch
assert epoch < next_epoch
func get_epoch_specific_params() : auto =
template get_epoch_specific_params(): auto =
if epoch < current_epoch:
let
committees_per_epoch = get_previous_epoch_committee_count(state)
@ -102,7 +95,8 @@ func get_crosslink_committees_at_slot*(state: BeaconState, slot: uint64):
shuffling_start_shard = state.current_epoch_start_shard
(committees_per_epoch, seed, shuffling_epoch, shuffling_start_shard)
let (committees_per_epoch, seed, shuffling_epoch, shuffling_start_shard) = get_epoch_specific_params()
let (committees_per_epoch, seed, shuffling_epoch, shuffling_start_shard) =
get_epoch_specific_params()
let
shuffling = get_shuffling(