mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 22:36:01 +00:00
properly construct attestation data for selected slot
This commit is contained in:
parent
fbdb078eb3
commit
741570113b
@ -5,15 +5,9 @@
|
|||||||
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
# * 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.
|
# 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
|
# Have an an aggregated aggregation ready for broadcast at
|
||||||
# network + attestation pool lag to collect attestations, if one wants a
|
# SECONDS_PER_SLOT * 2 / 3, i.e. 2/3 through relevant slot
|
||||||
# maximally updated pool (but could also just only aggregate to previous
|
# intervals.
|
||||||
# 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.
|
|
||||||
#
|
#
|
||||||
# The other part is arguably part of attestation pool -- the validation's
|
# The other part is arguably part of attestation pool -- the validation's
|
||||||
# something that should be happing on receipt, not aggregation per se. In
|
# something that should be happing on receipt, not aggregation per se. In
|
||||||
@ -23,23 +17,21 @@
|
|||||||
# already done.
|
# already done.
|
||||||
#
|
#
|
||||||
# Finally, some of the filtering's libp2p stuff. Consistency checks between
|
# 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
|
import
|
||||||
options,
|
options,
|
||||||
./spec/[datatypes, crypto, digest, helpers, validator],
|
./spec/[beaconstate, datatypes, crypto, digest, helpers, validator],
|
||||||
./attestation_pool, ./beacon_node_types, ./ssz
|
./attestation_pool, ./beacon_node_types, ./ssz
|
||||||
|
|
||||||
# TODO gossipsub validation lives somewhere, maybe here
|
# TODO gossipsub validation lives somewhere, maybe here
|
||||||
# TODO add tests, especially for validation
|
# TODO add tests, especially for validation
|
||||||
# https://github.com/status-im/nim-beacon-chain/issues/122#issuecomment-562479965
|
# 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
|
const
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/networking/p2p-interface.md#configuration
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/networking/p2p-interface.md#configuration
|
||||||
ATTESTATION_PROPAGATION_SLOT_RANGE* = 32
|
ATTESTATION_PROPAGATION_SLOT_RANGE = 32
|
||||||
GOSSIP_MAX_SIZE = 1048576
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
# 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):
|
func get_slot_signature(state: BeaconState, slot: Slot, privkey: ValidatorPrivKey):
|
||||||
@ -77,18 +69,18 @@ proc aggregate_attestations*(
|
|||||||
if not is_aggregator(state, slot, index, slot_signature):
|
if not is_aggregator(state, slot, index, slot_signature):
|
||||||
return none(AggregateAndProof)
|
return none(AggregateAndProof)
|
||||||
|
|
||||||
|
let attestation_data =
|
||||||
|
makeAttestationData(state, slot, index, get_block_root_at_slot(state, slot))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#construct-aggregate
|
# 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)
|
for attestation in getAttestationsForBlock(pool, state, slot):
|
||||||
|
if attestation.data == attestation_data:
|
||||||
var correct_attestation_data: AttestationData
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
||||||
|
|
||||||
for attestation in attestations:
|
|
||||||
if attestation.data == correct_attestation_data:
|
|
||||||
return some(AggregateAndProof(
|
return some(AggregateAndProof(
|
||||||
aggregator_index: index,
|
aggregator_index: index,
|
||||||
aggregate: attestation,
|
aggregate: attestation,
|
||||||
selection_proof: slot_signature))
|
selection_proof: slot_signature))
|
||||||
|
|
||||||
|
# TODO in catch-up mode, we could get here, so probably shouldn't assert
|
||||||
|
doAssert false
|
||||||
none(AggregateAndProof)
|
none(AggregateAndProof)
|
||||||
# SECONDS_PER_SLOT / 3 in: initial aggregation TODO adjust this elsewhere
|
|
||||||
# SECONDS_PER_SLOT * 2 / 3
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user