remove several IntSet usages in lieu of seq[ValidatorIndex] (#2288)
* remove several IntSet usages in lieu of seq[ValidatorIndex] * convert smaller types to larger types * larger type, again
This commit is contained in:
parent
ece50c4706
commit
8d25663681
|
@ -8,7 +8,7 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[intsets, options, sequtils],
|
std/[options, sequtils],
|
||||||
chronos, chronicles,
|
chronos, chronicles,
|
||||||
./spec/[
|
./spec/[
|
||||||
beaconstate, datatypes, crypto, digest, helpers, network, signatures],
|
beaconstate, datatypes, crypto, digest, helpers, network, signatures],
|
||||||
|
@ -163,7 +163,7 @@ proc validateAttestation*(
|
||||||
pool: var AttestationPool,
|
pool: var AttestationPool,
|
||||||
attestation: Attestation, wallTime: BeaconTime,
|
attestation: Attestation, wallTime: BeaconTime,
|
||||||
topicCommitteeIndex: uint64, checksExpensive: bool):
|
topicCommitteeIndex: uint64, checksExpensive: bool):
|
||||||
Result[IntSet, (ValidationResult, cstring)] =
|
Result[seq[ValidatorIndex], (ValidationResult, cstring)] =
|
||||||
# [REJECT] The attestation's epoch matches its target -- i.e.
|
# [REJECT] The attestation's epoch matches its target -- i.e.
|
||||||
# attestation.data.target.epoch ==
|
# attestation.data.target.epoch ==
|
||||||
# compute_epoch_at_slot(attestation.data.slot)
|
# compute_epoch_at_slot(attestation.data.slot)
|
||||||
|
@ -252,7 +252,7 @@ proc validateAttestation*(
|
||||||
# validator index.
|
# validator index.
|
||||||
# Slightly modified to allow only newer attestations than were previously
|
# Slightly modified to allow only newer attestations than were previously
|
||||||
# seen (no point in propagating older votes)
|
# seen (no point in propagating older votes)
|
||||||
if (pool.nextAttestationEpoch.len > validator_index) and
|
if (pool.nextAttestationEpoch.lenu64 > validator_index.uint64) and
|
||||||
pool.nextAttestationEpoch[validator_index].subnet >
|
pool.nextAttestationEpoch[validator_index].subnet >
|
||||||
attestation.data.target.epoch:
|
attestation.data.target.epoch:
|
||||||
return err((ValidationResult.Ignore, cstring(
|
return err((ValidationResult.Ignore, cstring(
|
||||||
|
@ -286,9 +286,10 @@ proc validateAttestation*(
|
||||||
return err((ValidationResult.Reject, cstring(
|
return err((ValidationResult.Reject, cstring(
|
||||||
"validateAttestation: attestation's target block not an ancestor of LMD vote block")))
|
"validateAttestation: attestation's target block not an ancestor of LMD vote block")))
|
||||||
|
|
||||||
# Only valid attestations go in the list
|
# Only valid attestations go in the list, which keeps validator_index
|
||||||
if not (pool.nextAttestationEpoch.len > validator_index):
|
# in range
|
||||||
pool.nextAttestationEpoch.setLen(validator_index + 1)
|
if not (pool.nextAttestationEpoch.lenu64 > validator_index.uint64):
|
||||||
|
pool.nextAttestationEpoch.setLen(validator_index.int + 1)
|
||||||
pool.nextAttestationEpoch[validator_index].subnet =
|
pool.nextAttestationEpoch[validator_index].subnet =
|
||||||
attestation.data.target.epoch + 1
|
attestation.data.target.epoch + 1
|
||||||
|
|
||||||
|
@ -298,7 +299,7 @@ proc validateAttestation*(
|
||||||
proc validateAggregate*(
|
proc validateAggregate*(
|
||||||
pool: var AttestationPool,
|
pool: var AttestationPool,
|
||||||
signedAggregateAndProof: SignedAggregateAndProof, wallTime: BeaconTime):
|
signedAggregateAndProof: SignedAggregateAndProof, wallTime: BeaconTime):
|
||||||
Result[IntSet, (ValidationResult, cstring)] =
|
Result[seq[ValidatorIndex], (ValidationResult, cstring)] =
|
||||||
let
|
let
|
||||||
aggregate_and_proof = signedAggregateAndProof.message
|
aggregate_and_proof = signedAggregateAndProof.message
|
||||||
aggregate = aggregate_and_proof.aggregate
|
aggregate = aggregate_and_proof.aggregate
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard libraries
|
# Standard libraries
|
||||||
std/[deques, intsets, options, sequtils, tables],
|
std/[deques, options, sequtils, tables],
|
||||||
# Status libraries
|
# Status libraries
|
||||||
chronicles, stew/[byteutils], json_serialization/std/sets as jsonSets,
|
chronicles, stew/[byteutils], json_serialization/std/sets as jsonSets,
|
||||||
# Internal
|
# Internal
|
||||||
|
@ -19,7 +19,7 @@ import
|
||||||
./beacon_node_types,
|
./beacon_node_types,
|
||||||
./fork_choice/fork_choice
|
./fork_choice/fork_choice
|
||||||
|
|
||||||
export beacon_node_types, intsets
|
export beacon_node_types
|
||||||
|
|
||||||
logScope: topics = "attpool"
|
logScope: topics = "attpool"
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ proc init*(T: type AttestationPool, chainDag: ChainDAGRef, quarantine: Quarantin
|
||||||
)
|
)
|
||||||
|
|
||||||
proc addForkChoiceVotes(
|
proc addForkChoiceVotes(
|
||||||
pool: var AttestationPool, slot: Slot, participants: IntSet,
|
pool: var AttestationPool, slot: Slot, participants: seq[ValidatorIndex],
|
||||||
block_root: Eth2Digest, wallSlot: Slot) =
|
block_root: Eth2Digest, wallSlot: Slot) =
|
||||||
# Add attestation votes to fork choice
|
# Add attestation votes to fork choice
|
||||||
if (let v = pool.forkChoice.on_attestation(
|
if (let v = pool.forkChoice.on_attestation(
|
||||||
|
@ -150,7 +150,7 @@ func addToAggregates(pool: var AttestationPool, attestation: Attestation) =
|
||||||
|
|
||||||
proc addAttestation*(pool: var AttestationPool,
|
proc addAttestation*(pool: var AttestationPool,
|
||||||
attestation: Attestation,
|
attestation: Attestation,
|
||||||
participants: IntSet,
|
participants: seq[ValidatorIndex],
|
||||||
wallSlot: Slot) =
|
wallSlot: Slot) =
|
||||||
## Add an attestation to the pool, assuming it's been validated already.
|
## Add an attestation to the pool, assuming it's been validated already.
|
||||||
## Attestations may be either agggregated or not - we're pursuing an eager
|
## Attestations may be either agggregated or not - we're pursuing an eager
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[algorithm, intsets, sequtils],
|
std/[algorithm, sequtils],
|
||||||
chronicles,
|
chronicles,
|
||||||
../spec/[
|
../spec/[
|
||||||
crypto, datatypes, digest, helpers, presets, signatures,
|
crypto, datatypes, digest, helpers, presets, signatures,
|
||||||
|
@ -82,11 +82,10 @@ iterator get_attesting_indices*(epochRef: EpochRef,
|
||||||
func get_attesting_indices*(epochRef: EpochRef,
|
func get_attesting_indices*(epochRef: EpochRef,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
bits: CommitteeValidatorsBits):
|
bits: CommitteeValidatorsBits):
|
||||||
IntSet =
|
seq[ValidatorIndex] =
|
||||||
|
# TODO sequtils2 mapIt
|
||||||
for idx in get_attesting_indices(epochRef, data, bits):
|
for idx in get_attesting_indices(epochRef, data, bits):
|
||||||
# Because it must have been in get_beacon_committee(...), it's a valid
|
result.add(idx)
|
||||||
# validator index, so the conversion is as safe as it is anywhere.
|
|
||||||
result.incl(idx.int)
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/beacon-chain.md#get_indexed_attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/beacon-chain.md#get_indexed_attestation
|
||||||
func get_indexed_attestation*(epochRef: EpochRef, attestation: Attestation): IndexedAttestation =
|
func get_indexed_attestation*(epochRef: EpochRef, attestation: Attestation): IndexedAttestation =
|
||||||
|
@ -146,7 +145,7 @@ proc is_valid_indexed_attestation*(
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||||
proc is_valid_indexed_attestation*(
|
proc is_valid_indexed_attestation*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
epochRef: EpochRef, attesting_indices: IntSet,
|
epochRef: EpochRef, attesting_indices: auto,
|
||||||
attestation: SomeAttestation, flags: UpdateFlags): Result[void, cstring] =
|
attestation: SomeAttestation, flags: UpdateFlags): Result[void, cstring] =
|
||||||
# This is a variation on `is_valid_indexed_attestation` that works directly
|
# This is a variation on `is_valid_indexed_attestation` that works directly
|
||||||
# with an attestation instead of first constructing an `IndexedAttestation`
|
# with an attestation instead of first constructing an `IndexedAttestation`
|
||||||
|
|
|
@ -60,7 +60,7 @@ type
|
||||||
|
|
||||||
AttestationEntry* = object
|
AttestationEntry* = object
|
||||||
v*: Attestation
|
v*: Attestation
|
||||||
attesting_indices*: IntSet
|
attesting_indices*: seq[ValidatorIndex]
|
||||||
|
|
||||||
AggregateEntry* = AttestationEntry
|
AggregateEntry* = AttestationEntry
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ proc blockValidator*(
|
||||||
|
|
||||||
proc checkForPotentialDoppelganger(
|
proc checkForPotentialDoppelganger(
|
||||||
self: var Eth2Processor, attestationData: AttestationData,
|
self: var Eth2Processor, attestationData: AttestationData,
|
||||||
attesterIndices: IntSet, wallSlot: Slot) =
|
attesterIndices: openArray[ValidatorIndex], wallSlot: Slot) =
|
||||||
let epoch = wallSlot.epoch
|
let epoch = wallSlot.epoch
|
||||||
if epoch < self.doppelgangerDetection.broadcastStartEpoch:
|
if epoch < self.doppelgangerDetection.broadcastStartEpoch:
|
||||||
let tgtBlck = self.chainDag.getRef(attestationData.target.root)
|
let tgtBlck = self.chainDag.getRef(attestationData.target.root)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
std/[intsets, sequtils, tables],
|
std/[sequtils, tables],
|
||||||
# Status libraries
|
# Status libraries
|
||||||
stew/results, chronicles,
|
stew/results, chronicles,
|
||||||
# Internal
|
# Internal
|
||||||
|
@ -18,7 +18,7 @@ import
|
||||||
./fork_choice_types, ./proto_array,
|
./fork_choice_types, ./proto_array,
|
||||||
../block_pools/[spec_cache, chain_dag]
|
../block_pools/[spec_cache, chain_dag]
|
||||||
|
|
||||||
export intsets, results, fork_choice_types
|
export results, fork_choice_types
|
||||||
export proto_array.len
|
export proto_array.len
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/fork-choice.md
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/fork-choice.md
|
||||||
|
@ -174,7 +174,7 @@ proc on_attestation*(
|
||||||
dag: ChainDAGRef,
|
dag: ChainDAGRef,
|
||||||
attestation_slot: Slot,
|
attestation_slot: Slot,
|
||||||
beacon_block_root: Eth2Digest,
|
beacon_block_root: Eth2Digest,
|
||||||
attesting_indices: IntSet,
|
attesting_indices: seq[ValidatorIndex],
|
||||||
wallSlot: Slot
|
wallSlot: Slot
|
||||||
): FcResult[void] =
|
): FcResult[void] =
|
||||||
? self.update_time(dag, wallSlot)
|
? self.update_time(dag, wallSlot)
|
||||||
|
@ -191,7 +191,7 @@ proc on_attestation*(
|
||||||
else:
|
else:
|
||||||
self.queuedAttestations.add(QueuedAttestation(
|
self.queuedAttestations.add(QueuedAttestation(
|
||||||
slot: attestation_slot,
|
slot: attestation_slot,
|
||||||
attesting_indices: toSeq(attesting_indices),
|
attesting_indices: attesting_indices,
|
||||||
block_root: beacon_block_root))
|
block_root: beacon_block_root))
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -160,7 +160,7 @@ type
|
||||||
|
|
||||||
QueuedAttestation* = object
|
QueuedAttestation* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
attesting_indices*: seq[int]
|
attesting_indices*: seq[ValidatorIndex]
|
||||||
block_root*: Eth2Digest
|
block_root*: Eth2Digest
|
||||||
target_epoch*: Epoch
|
target_epoch*: Epoch
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2019-2020 Status Research & Development GmbH
|
# Copyright (c) 2019-2021 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -117,7 +117,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
||||||
data: data,
|
data: data,
|
||||||
aggregation_bits: aggregation_bits,
|
aggregation_bits: aggregation_bits,
|
||||||
signature: sig
|
signature: sig
|
||||||
), [validatorIdx.int].toIntSet(), data.slot)
|
), @[validatorIdx], data.slot)
|
||||||
|
|
||||||
proc proposeBlock(slot: Slot) =
|
proc proposeBlock(slot: Slot) =
|
||||||
if rand(r, 1.0) > blockRatio:
|
if rand(r, 1.0) > blockRatio:
|
||||||
|
|
|
@ -77,7 +77,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
state.data.data, state.blck.root, beacon_committee[0], cache)
|
state.data.data, state.blck.root, beacon_committee[0], cache)
|
||||||
|
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(
|
||||||
attestation, [beacon_committee[0]].toIntSet(), attestation.data.slot)
|
attestation, @[beacon_committee[0]], attestation.data.slot)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
||||||
|
@ -106,10 +106,8 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
state.data.data, state.blck.root, bc1[0], cache)
|
state.data.data, state.blck.root, bc1[0], cache)
|
||||||
|
|
||||||
# test reverse order
|
# test reverse order
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation1, @[bc1[0]], attestation1.data.slot)
|
||||||
attestation1, [bc1[0]].toIntSet, attestation1.data.slot)
|
pool[].addAttestation(attestation0, @[bc0[0]], attestation1.data.slot)
|
||||||
pool[].addAttestation(
|
|
||||||
attestation0, [bc0[0]].toIntSet, attestation1.data.slot)
|
|
||||||
|
|
||||||
discard process_slots(
|
discard process_slots(
|
||||||
state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
||||||
|
@ -130,10 +128,8 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
attestation1 = makeAttestation(
|
attestation1 = makeAttestation(
|
||||||
state.data.data, state.blck.root, bc0[1], cache)
|
state.data.data, state.blck.root, bc0[1], cache)
|
||||||
|
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation0, @[bc0[0]], attestation0.data.slot)
|
||||||
attestation0, [bc0[0]].toIntSet, attestation0.data.slot)
|
pool[].addAttestation(attestation1, @[bc0[1]], attestation1.data.slot)
|
||||||
pool[].addAttestation(
|
|
||||||
attestation1, [bc0[1]].toIntSet, attestation1.data.slot)
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
||||||
|
@ -157,10 +153,8 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
|
|
||||||
attestation0.combine(attestation1)
|
attestation0.combine(attestation1)
|
||||||
|
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation0, @[bc0[0]], attestation0.data.slot)
|
||||||
attestation0, [bc0[0]].toIntSet, attestation0.data.slot)
|
pool[].addAttestation(attestation1, @[bc0[1]], attestation1.data.slot)
|
||||||
pool[].addAttestation(
|
|
||||||
attestation1, [bc0[1]].toIntSet, attestation1.data.slot)
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
||||||
|
@ -183,10 +177,8 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
|
|
||||||
attestation0.combine(attestation1)
|
attestation0.combine(attestation1)
|
||||||
|
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation1, @[bc0[1]], attestation1.data.slot)
|
||||||
attestation1, [bc0[1]].toIntSet, attestation1.data.slot)
|
pool[].addAttestation(attestation0, @[bc0[0]], attestation0.data.slot)
|
||||||
pool[].addAttestation(
|
|
||||||
attestation0, [bc0[0]].toIntSet, attestation0.data.slot)
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot + 1, cache)
|
||||||
|
@ -253,8 +245,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
state.data.data, state.data.data.slot - 1, 1.CommitteeIndex, cache)
|
state.data.data, state.data.data.slot - 1, 1.CommitteeIndex, cache)
|
||||||
attestation0 = makeAttestation(state.data.data, b10.root, bc1[0], cache)
|
attestation0 = makeAttestation(state.data.data, b10.root, bc1[0], cache)
|
||||||
|
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation0, @[bc1[0]], attestation0.data.slot)
|
||||||
attestation0, [bc1[0]].toIntSet, attestation0.data.slot)
|
|
||||||
|
|
||||||
let head2 = pool[].selectHead(b10Add[].slot)
|
let head2 = pool[].selectHead(b10Add[].slot)
|
||||||
|
|
||||||
|
@ -265,8 +256,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
let
|
let
|
||||||
attestation1 = makeAttestation(state.data.data, b11.root, bc1[1], cache)
|
attestation1 = makeAttestation(state.data.data, b11.root, bc1[1], cache)
|
||||||
attestation2 = makeAttestation(state.data.data, b11.root, bc1[2], cache)
|
attestation2 = makeAttestation(state.data.data, b11.root, bc1[2], cache)
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation1, @[bc1[1]], attestation1.data.slot)
|
||||||
attestation1, [bc1[1]].toIntSet, attestation1.data.slot)
|
|
||||||
|
|
||||||
let head3 = pool[].selectHead(b10Add[].slot)
|
let head3 = pool[].selectHead(b10Add[].slot)
|
||||||
let bigger = if b11.root.data < b10.root.data: b10Add else: b11Add
|
let bigger = if b11.root.data < b10.root.data: b10Add else: b11Add
|
||||||
|
@ -275,8 +265,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
# Ties broken lexicographically in spec -> ?
|
# Ties broken lexicographically in spec -> ?
|
||||||
head3 == bigger[]
|
head3 == bigger[]
|
||||||
|
|
||||||
pool[].addAttestation(
|
pool[].addAttestation(attestation2, @[bc1[2]], attestation2.data.slot)
|
||||||
attestation2, [bc1[2]].toIntSet, attestation2.data.slot)
|
|
||||||
|
|
||||||
let head4 = pool[].selectHead(b11Add[].slot)
|
let head4 = pool[].selectHead(b11Add[].slot)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue