Skip to content

Commit

Permalink
properly construct attestation data for selected slot
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Dec 13, 2019
1 parent fbdb078 commit 7415701
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions beacon_chain/attestation_aggregation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

# Mostly TODOs at this point, but basically, called every 1/3 + expected
# network + attestation pool lag to collect attestations, if one wants a
# maximally updated pool (but could also just only aggregate to previous
# slots, safer probably), check for some fixed slot offset to past for a
# locally attached validator (externally-to-this-module supplied), run a
# set of supplied algorithms (already implemented) to check if that is a
# matching pair. Aggregation itself's already implemented in attestation
# pool, so this is mostly (a) selection of when to aggregate, (b) change
# of validation, (c) and specific sending deadlines with slots.
# Have an an aggregated aggregation ready for broadcast at
# SECONDS_PER_SLOT * 2 / 3, i.e. 2/3 through relevant slot
# intervals.
#
# The other part is arguably part of attestation pool -- the validation's
# something that should be happing on receipt, not aggregation per se. In
Expand All @@ -23,23 +17,21 @@
# already done.
#
# Finally, some of the filtering's libp2p stuff. Consistency checks between
# topic/message types and GOSSIP_MAX_SIZE.
# topic/message types and GOSSIP_MAX_SIZE -- mostly doesn't belong here, so
# while TODO, isn't TODO for this module.

import
options,
./spec/[datatypes, crypto, digest, helpers, validator],
./spec/[beaconstate, datatypes, crypto, digest, helpers, validator],
./attestation_pool, ./beacon_node_types, ./ssz

# TODO gossipsub validation lives somewhere, maybe here
# TODO add tests, especially for validation
# https://github.com/status-im/nim-beacon-chain/issues/122#issuecomment-562479965
# it's conceptually separate, sort of, but depends on beaconstate, so isn't a
# pure libp2p thing.

const
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/networking/p2p-interface.md#configuration
ATTESTATION_PROPAGATION_SLOT_RANGE* = 32
GOSSIP_MAX_SIZE = 1048576
ATTESTATION_PROPAGATION_SLOT_RANGE = 32

# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#aggregation-selection
func get_slot_signature(state: BeaconState, slot: Slot, privkey: ValidatorPrivKey):
Expand Down Expand Up @@ -77,18 +69,18 @@ proc aggregate_attestations*(
if not is_aggregator(state, slot, index, slot_signature):
return none(AggregateAndProof)

# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#construct-aggregate
let attestations = getAttestationsForBlock(pool, state, slot)

var correct_attestation_data: AttestationData
let attestation_data =
makeAttestationData(state, slot, index, get_block_root_at_slot(state, slot))

for attestation in attestations:
if attestation.data == correct_attestation_data:
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#construct-aggregate
for attestation in getAttestationsForBlock(pool, state, slot):
if attestation.data == attestation_data:
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#aggregateandproof
return some(AggregateAndProof(
aggregator_index: index,
aggregate: attestation,
selection_proof: slot_signature))

# TODO in catch-up mode, we could get here, so probably shouldn't assert
doAssert false
none(AggregateAndProof)
# SECONDS_PER_SLOT / 3 in: initial aggregation TODO adjust this elsewhere
# SECONDS_PER_SLOT * 2 / 3

0 comments on commit 7415701

Please sign in to comment.