2020-04-22 05:53:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
import
|
2020-09-24 17:05:49 +00:00
|
|
|
std/[deques, sets, streams, tables],
|
2020-05-19 14:37:29 +00:00
|
|
|
stew/endians2,
|
2020-09-14 11:13:30 +00:00
|
|
|
spec/[datatypes, digest, crypto],
|
2020-05-19 14:18:07 +00:00
|
|
|
block_pools/block_pools_types,
|
2020-09-16 11:30:03 +00:00
|
|
|
fork_choice/fork_choice_types,
|
|
|
|
validator_slashing_protection
|
2020-05-19 14:18:07 +00:00
|
|
|
|
2020-10-20 12:31:20 +00:00
|
|
|
from libp2p/protocols/pubsub/pubsub import ValidationResult
|
|
|
|
|
|
|
|
export block_pools_types, ValidationResult
|
2019-03-12 15:03:14 +00:00
|
|
|
|
2020-07-28 13:54:32 +00:00
|
|
|
const
|
|
|
|
ATTESTATION_LOOKBACK* =
|
|
|
|
min(4'u64, SLOTS_PER_EPOCH) + MIN_ATTESTATION_INCLUSION_DELAY
|
|
|
|
## The number of slots we'll keep track of in terms of "free" attestations
|
|
|
|
## that potentially could be added to a newly created block
|
|
|
|
|
2019-03-12 15:03:14 +00:00
|
|
|
type
|
|
|
|
# #############################################
|
|
|
|
#
|
|
|
|
# Attestation Pool
|
|
|
|
#
|
|
|
|
# #############################################
|
|
|
|
Validation* = object
|
2020-07-27 16:04:44 +00:00
|
|
|
## Validations collect a set of signatures for a distict attestation - in
|
|
|
|
## eth2, a single bit is used to keep track of which signatures have been
|
|
|
|
## added to the aggregate meaning that only non-overlapping aggregates may
|
|
|
|
## be further combined.
|
2019-07-03 07:35:05 +00:00
|
|
|
aggregation_bits*: CommitteeValidatorsBits
|
2019-03-12 15:03:14 +00:00
|
|
|
aggregate_signature*: ValidatorSig
|
|
|
|
|
|
|
|
AttestationEntry* = object
|
2020-07-27 16:04:44 +00:00
|
|
|
## Each entry holds the known signatures for a particular, distinct vote
|
2019-03-12 15:03:14 +00:00
|
|
|
data*: AttestationData
|
|
|
|
blck*: BlockRef
|
2020-07-27 16:04:44 +00:00
|
|
|
validations*: seq[Validation]
|
2019-03-12 15:03:14 +00:00
|
|
|
|
2020-06-10 06:58:12 +00:00
|
|
|
AttestationsSeen* = object
|
2019-03-12 15:03:14 +00:00
|
|
|
attestations*: seq[AttestationEntry] ## \
|
|
|
|
## Depending on the world view of the various validators, they may have
|
|
|
|
## voted on different states - here we collect all the different
|
|
|
|
## combinations that validators have come up with so that later, we can
|
|
|
|
## count how popular each world view is (fork choice)
|
|
|
|
## TODO this could be a Table[AttestationData, seq[Validation] or something
|
|
|
|
## less naive
|
|
|
|
|
|
|
|
AttestationPool* = object
|
2020-07-27 16:04:44 +00:00
|
|
|
## The attestation pool keeps track of all attestations that potentially
|
|
|
|
## could be added to a block during block production.
|
|
|
|
## These attestations also contribute to the fork choice, which combines
|
|
|
|
## "free" attestations with those found in past blocks - these votes
|
|
|
|
## are tracked separately in the fork choice.
|
2019-03-12 15:03:14 +00:00
|
|
|
|
2020-09-14 11:13:30 +00:00
|
|
|
attestationAggregates*: Table[Slot, Table[Eth2Digest, Attestation]]
|
|
|
|
## An up-to-date aggregate of each (htr-ed) attestation_data we see for
|
|
|
|
## each slot. We keep aggregates up to 32 slots back from the current slot.
|
|
|
|
|
2020-07-28 13:54:32 +00:00
|
|
|
candidates*: array[ATTESTATION_LOOKBACK, AttestationsSeen] ## \
|
|
|
|
## We keep one item per slot such that indexing matches slot number
|
|
|
|
## together with startingSlot
|
2019-03-12 15:03:14 +00:00
|
|
|
|
|
|
|
startingSlot*: Slot ## \
|
|
|
|
## Generally, we keep attestations only until a slot has been finalized -
|
|
|
|
## after that, they may no longer affect fork choice.
|
|
|
|
|
2020-07-31 14:49:06 +00:00
|
|
|
chainDag*: ChainDAGRef
|
|
|
|
quarantine*: QuarantineRef
|
2019-03-12 15:03:14 +00:00
|
|
|
|
2020-07-25 19:41:12 +00:00
|
|
|
forkChoice*: ForkChoice
|
2019-03-13 22:59:20 +00:00
|
|
|
|
2020-09-25 17:51:44 +00:00
|
|
|
lastVotedEpoch*: seq[Option[Epoch]] # Sequence based on validator indices
|
|
|
|
|
2020-09-14 14:26:31 +00:00
|
|
|
ExitPool* = object
|
|
|
|
## The exit pool tracks attester slashings, proposer slashings, and
|
|
|
|
## voluntary exits that could be added to a proposed block.
|
|
|
|
|
|
|
|
attester_slashings*: Deque[AttesterSlashing] ## \
|
|
|
|
## Not a function of chain DAG branch; just used as a FIFO queue for blocks
|
|
|
|
|
|
|
|
proposer_slashings*: Deque[ProposerSlashing] ## \
|
|
|
|
## Not a function of chain DAG branch; just used as a FIFO queue for blocks
|
|
|
|
|
2020-09-24 17:05:49 +00:00
|
|
|
voluntary_exits*: Deque[SignedVoluntaryExit] ## \
|
2020-09-14 14:26:31 +00:00
|
|
|
## Not a function of chain DAG branch; just used as a FIFO queue for blocks
|
|
|
|
|
2020-10-07 16:57:21 +00:00
|
|
|
prior_seen_attester_slashed_indices*: HashSet[uint64] ##\
|
2020-09-24 17:05:49 +00:00
|
|
|
## Records attester-slashed indices seen.
|
|
|
|
|
2020-10-07 16:57:21 +00:00
|
|
|
prior_seen_proposer_slashed_indices*: HashSet[uint64] ##\
|
2020-09-24 17:05:49 +00:00
|
|
|
## Records proposer-slashed indices seen.
|
|
|
|
|
2020-10-07 16:57:21 +00:00
|
|
|
prior_seen_voluntary_exit_indices*: HashSet[uint64] ##\
|
2020-09-24 17:05:49 +00:00
|
|
|
## Records voluntary exit indices seen.
|
|
|
|
|
2020-09-14 14:26:31 +00:00
|
|
|
chainDag*: ChainDAGRef
|
|
|
|
quarantine*: QuarantineRef
|
|
|
|
|
2019-03-12 15:03:14 +00:00
|
|
|
# #############################################
|
|
|
|
#
|
|
|
|
# Validator Pool
|
|
|
|
#
|
|
|
|
# #############################################
|
|
|
|
ValidatorKind* = enum
|
|
|
|
inProcess
|
|
|
|
remote
|
|
|
|
|
|
|
|
ValidatorConnection* = object
|
2020-09-01 13:44:40 +00:00
|
|
|
inStream*: Stream
|
|
|
|
outStream*: Stream
|
|
|
|
pubKeyStr*: string
|
2019-03-12 15:03:14 +00:00
|
|
|
|
|
|
|
AttachedValidator* = ref object
|
2019-04-06 07:46:07 +00:00
|
|
|
pubKey*: ValidatorPubKey
|
|
|
|
|
2019-03-12 15:03:14 +00:00
|
|
|
case kind*: ValidatorKind
|
|
|
|
of inProcess:
|
|
|
|
privKey*: ValidatorPrivKey
|
|
|
|
else:
|
|
|
|
connection*: ValidatorConnection
|
|
|
|
|
2020-11-27 23:34:25 +00:00
|
|
|
# The index at which this validator has been observed in the chain -
|
|
|
|
# it does not change as long as there are no reorgs on eth1 - however, the
|
|
|
|
# index might not be valid in all eth2 histories, so it should not be
|
|
|
|
# assumed that a valid index is stored here!
|
|
|
|
index*: Option[ValidatorIndex]
|
|
|
|
|
2019-03-12 15:03:14 +00:00
|
|
|
ValidatorPool* = object
|
2019-03-18 03:54:08 +00:00
|
|
|
validators*: Table[ValidatorPubKey, AttachedValidator]
|
2020-09-16 11:30:03 +00:00
|
|
|
slashingProtection*: SlashingProtectionDB
|
2019-03-19 17:22:17 +00:00
|
|
|
|
2020-09-06 08:39:25 +00:00
|
|
|
func shortLog*(v: AttachedValidator): string = shortLog(v.pubKey)
|