spec: remove unused code, fix state_sim speed

This commit is contained in:
Jacek Sieka 2019-02-07 13:03:02 +01:00
parent d75b6bc3a8
commit 976e1e1f10
No known key found for this signature in database
GPG Key ID: 6299FEB3EB6FA465
3 changed files with 6 additions and 26 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,
@ -294,10 +296,6 @@ proc scheduleEpochActions(node: BeaconNode, epoch: uint64) =
# missing blocks if necessary
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):

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(