2020-04-22 05:53:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
import
|
2020-04-28 08:08:32 +00:00
|
|
|
deques, tables,
|
2020-05-19 14:37:29 +00:00
|
|
|
stew/endians2,
|
2019-07-03 07:35:05 +00:00
|
|
|
spec/[datatypes, crypto, digest],
|
2020-05-19 14:18:07 +00:00
|
|
|
block_pools/block_pools_types,
|
2020-06-24 18:24:36 +00:00
|
|
|
block_pool, # TODO: refactoring compat shim
|
|
|
|
fork_choice/fork_choice_types
|
2020-05-19 14:18:07 +00:00
|
|
|
|
|
|
|
export block_pools_types
|
2019-03-12 15:03:14 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
# #############################################
|
|
|
|
#
|
|
|
|
# Attestation Pool
|
|
|
|
#
|
|
|
|
# #############################################
|
|
|
|
Validation* = object
|
2019-07-03 07:35:05 +00:00
|
|
|
aggregation_bits*: CommitteeValidatorsBits
|
2019-03-12 15:03:14 +00:00
|
|
|
aggregate_signature*: ValidatorSig
|
|
|
|
|
|
|
|
# Per Danny as of 2018-12-21:
|
|
|
|
# Yeah, you can do any linear combination of signatures. but you have to
|
|
|
|
# remember the linear combination of pubkeys that constructed
|
|
|
|
# if you have two instances of a signature from pubkey p, then you need 2*p
|
2019-07-03 07:35:05 +00:00
|
|
|
# in the group pubkey because the attestation bitlist is only 1 bit per
|
2019-03-12 15:03:14 +00:00
|
|
|
# pubkey right now, attestations do not support this it could be extended to
|
|
|
|
# support N overlaps up to N times per pubkey if we had N bits per validator
|
|
|
|
# instead of 1
|
|
|
|
# We are shying away from this for the time being. If there end up being
|
|
|
|
# substantial difficulties in network layer aggregation, then adding bits to
|
|
|
|
# aid in supporting overlaps is one potential solution
|
|
|
|
|
|
|
|
AttestationEntry* = object
|
|
|
|
data*: AttestationData
|
|
|
|
blck*: BlockRef
|
|
|
|
validations*: seq[Validation] ## \
|
|
|
|
## Instead of aggregating the signatures eagerly, we simply dump them in
|
|
|
|
## this seq and aggregate only when needed
|
|
|
|
## TODO there are obvious caching opportunities here..
|
|
|
|
|
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
|
|
|
|
|
|
|
|
UnresolvedAttestation* = object
|
|
|
|
attestation*: Attestation
|
|
|
|
tries*: int
|
|
|
|
|
|
|
|
AttestationPool* = object
|
|
|
|
## The attestation pool keeps all attestations that are known to the
|
|
|
|
## client - each attestation counts as votes towards the fork choice
|
|
|
|
## rule that determines which block we consider to be the head. The pool
|
|
|
|
## contains both votes that have been included in the chain and those that
|
|
|
|
## have not.
|
|
|
|
|
2020-06-10 06:58:12 +00:00
|
|
|
mapSlotsToAttestations*: Deque[AttestationsSeen] ## \
|
2019-03-12 15:03:14 +00:00
|
|
|
## We keep one item per slot such that indexing matches slot number
|
|
|
|
## together with startingSlot
|
|
|
|
|
|
|
|
startingSlot*: Slot ## \
|
|
|
|
## Generally, we keep attestations only until a slot has been finalized -
|
|
|
|
## after that, they may no longer affect fork choice.
|
|
|
|
|
|
|
|
blockPool*: BlockPool
|
|
|
|
|
|
|
|
unresolved*: Table[Eth2Digest, UnresolvedAttestation]
|
|
|
|
|
2019-03-13 22:59:20 +00:00
|
|
|
latestAttestations*: Table[ValidatorPubKey, BlockRef] ##\
|
|
|
|
## Map that keeps track of the most recent vote of each attester - see
|
|
|
|
## fork_choice
|
2020-06-24 18:24:36 +00:00
|
|
|
forkChoice_v2*: ForkChoice ##\
|
|
|
|
## The alternative fork choice "proto_array" that will ultimately
|
|
|
|
## replace the original one
|
2019-03-13 22:59:20 +00:00
|
|
|
|
2019-03-12 15:03:14 +00:00
|
|
|
# #############################################
|
|
|
|
#
|
|
|
|
# Validator Pool
|
|
|
|
#
|
|
|
|
# #############################################
|
|
|
|
ValidatorKind* = enum
|
|
|
|
inProcess
|
|
|
|
remote
|
|
|
|
|
|
|
|
ValidatorConnection* = object
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
ValidatorPool* = object
|
2019-03-18 03:54:08 +00:00
|
|
|
validators*: Table[ValidatorPubKey, AttachedValidator]
|
2019-03-19 17:22:17 +00:00
|
|
|
|
2019-04-06 07:46:07 +00:00
|
|
|
proc shortLog*(v: AttachedValidator): string = shortLog(v.pubKey)
|