scaffolding to remove last vestiges of get_committee_count(...), SHARD_COUNT, and rest of that 0.8.x infrastructure; this demonstrates equivalence between two, before discarding old code

This commit is contained in:
Dustin Brody 2019-11-14 18:37:51 +01:00
parent f98dd9b1bf
commit c08698bffe
No known key found for this signature in database
GPG Key ID: 3D7A11A0156519DC
6 changed files with 36 additions and 22 deletions

View File

@ -547,20 +547,28 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
let
epoch = compute_epoch_at_slot(slot)
committees_per_slot =
# get_committee_count_at_slot(state, slot)
get_committee_count_at_slot(state, epoch.compute_start_slot_at_epoch)
offset = committees_per_slot * (slot mod SLOTS_PER_EPOCH)
slot_start_shard = (get_start_shard(state, epoch) + offset) mod SHARD_COUNT
for i in 0'u64..<committees_per_slot:
for committee_index in 0'u64..<committees_per_slot:
let
shard = Shard((slot_start_shard + i) mod SHARD_COUNT)
committee = get_crosslink_committee(state, epoch, shard, cache)
shard = Shard((slot_start_shard + committee_index) mod SHARD_COUNT)
shard_committee = get_crosslink_committee(state, epoch, shard, cache)
committee = get_beacon_committee(state, slot, committee_index, cache)
for i, validatorIdx in committee:
for index_in_committee, validatorIdx in committee:
let validator = node.getAttachedValidator(state, validatorIdx)
if validator != nil:
let ad = makeAttestationData(state, shard, blck.root)
attestations.add((ad, committee.len, i, validator))
let ad = makeAttestationData(state, slot, committee_index, blck.root)
let
(hm_slot, hm_index) = get_slot_and_index(state, epoch, shard)
shard_ad = makeAttestationData(state, hm_slot, hm_index, blck.root)
doAssert slot == hm_slot
doAssert hm_index == committee_index
attestations.add((ad, committee.len, index_in_committee, validator))
#attestations.add((shard_ad, committee.len, index_in_committee, validator))
for a in attestations:
traceAsyncErrors sendAttestation(

View File

@ -487,7 +487,7 @@ proc process_attestation*(
false
proc makeAttestationData*(
state: BeaconState, shard: uint64,
state: BeaconState, slot: Slot, committee_index: uint64,
beacon_block_root: Eth2Digest): AttestationData =
## Create an attestation / vote for the block `beacon_block_root` using the
## data in `state` to fill in the rest of the fields.
@ -502,11 +502,12 @@ proc makeAttestationData*(
epoch_boundary_block_root =
if start_slot == state.slot: beacon_block_root
else: get_block_root_at_slot(state, start_slot)
(a_slot, a_index) = get_slot_and_index(state, current_epoch, shard)
doAssert slot.compute_epoch_at_slot == current_epoch
AttestationData(
slot: a_slot,
index: a_index,
slot: slot,
index: committee_index,
beacon_block_root: beacon_block_root,
source: state.current_justified_checkpoint,
target: Checkpoint(

View File

@ -6,9 +6,11 @@ NODE_ID=${1}
shift
# Read in variables
# shellcheck source=/dev/null
source "$(dirname "$0")/vars.sh"
# set up the environment
# shellcheck source=/dev/null
source "${SIM_ROOT}/../../env.sh"
cd "$GIT_ROOT"

View File

@ -3,9 +3,11 @@
set -eo pipefail
# Read in variables
# shellcheck source=/dev/null
source "$(dirname "$0")/vars.sh"
# set up the environment
# shellcheck source=/dev/null
source "${SIM_ROOT}/../../env.sh"
cd "$SIM_ROOT"

View File

@ -31,21 +31,21 @@ import
suite "[Unit - Spec - Genesis] Genesis block checks " & preset():
test "is_valid_genesis_state for a valid state":
let state = initGenesisState(
discard initGenesisState(
num_validators = MIN_GENESIS_ACTIVE_VALIDATOR_COUNT,
genesis_time = MIN_GENESIS_TIME
)
discard "TODO"
test "Invalid genesis time":
let state = initGenesisState(
discard initGenesisState(
num_validators = MIN_GENESIS_ACTIVE_VALIDATOR_COUNT,
genesis_time = MIN_GENESIS_TIME.uint64 - 1
)
discard "TODO"
test "Not enough validators":
let state = initGenesisState(
discard initGenesisState(
num_validators = MIN_GENESIS_ACTIVE_VALIDATOR_COUNT.uint64 - 1,
genesis_time = MIN_GENESIS_TIME.uint64 - 1
)

View File

@ -157,28 +157,29 @@ proc makeBlock*(
var next_state = state
addBlock(next_state, previous_block_root, body)
proc find_shard_committee(
proc find_beacon_committee(
state: BeaconState, validator_index: ValidatorIndex): auto =
let epoch = compute_epoch_at_slot(state.slot)
var cache = get_empty_per_epoch_cache()
for shard in 0'u64 ..< get_committee_count_at_slot(
for epoch_committee_index in 0'u64 ..< get_committee_count_at_slot(
state, epoch.compute_start_slot_at_epoch) * SLOTS_PER_EPOCH:
let committee = get_crosslink_committee(state, epoch,
(shard + get_start_shard(state, epoch)) mod SHARD_COUNT, cache)
let
slot = ((epoch_committee_index mod SLOTS_PER_EPOCH) +
epoch.compute_start_slot_at_epoch.uint64).Slot
index = epoch_committee_index div SLOTS_PER_EPOCH
committee = get_beacon_committee(state, slot, index, cache)
if validator_index in committee:
return (committee, shard)
return (committee, slot, index)
doAssert false
proc makeAttestation*(
state: BeaconState, beacon_block_root: Eth2Digest,
validator_index: ValidatorIndex, flags: UpdateFlags = {}): Attestation =
let
(committee, shard) = find_shard_committee(state, validator_index)
(committee, slot, index) = find_beacon_committee(state, validator_index)
validator = state.validators[validator_index]
sac_index = committee.find(validator_index)
data = makeAttestationData(state,
(shard + get_start_shard(state, compute_epoch_at_slot(state.slot))) mod
SHARD_COUNT, beacon_block_root)
data = makeAttestationData(state, slot, index, beacon_block_root)
doAssert sac_index != -1, "find_shard_committee should guarantee this"