some whole-file copies from altair branch (#2728)

* some whole-file copies from altair branch

* rpc/node_api and rpc/node_rest_api also need to be copied

* remove new sync committee-related functionality
This commit is contained in:
tersec 2021-07-19 11:58:30 +00:00 committed by GitHub
parent aebc606cb7
commit 9d9c37c561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 15 deletions

View File

@ -11,9 +11,8 @@ import
std/math,
stew/results,
chronicles, chronos, metrics,
../spec/[
crypto, datatypes/phase0, datatypes/altair, digest,
forkedbeaconstate_helpers],
../spec/datatypes/[phase0, altair],
../spec/[crypto, digest, forkedbeaconstate_helpers],
../consensus_object_pools/[block_clearance, blockchain_dag, attestation_pool],
./consensus_manager,
".."/[beacon_clock, beacon_node_types],
@ -123,7 +122,8 @@ proc addBlock*(
# sanity check
try:
self.blocksQueue.addLastNoWait(BlockEntry(
blck: blck, resfut: resfut, queueTick: Moment.now(),
blck: blck,
resfut: resfut, queueTick: Moment.now(),
validationDur: validationDur))
except AsyncQueueFullError:
raiseAssert "unbounded queue"

View File

@ -1050,7 +1050,7 @@ proc startSyncManager(node: BeaconNode) =
true
proc onDeletePeer(peer: Peer) =
if peer.connectionState notin {Disconnecting, Disconnected}:
if peer.connectionState notin {Disconnecting, ConnectionState.Disconnected}:
if peer.score < PeerScoreLowLimit:
debug "Peer was removed from PeerPool due to low score", peer = peer,
peer_score = peer.score, score_low_limit = PeerScoreLowLimit,

View File

@ -207,13 +207,13 @@ proc installNodeApiHandlers*(rpcServer: RpcServer, node: BeaconNode) {.
var res: NodePeerCountTuple
for item in node.network.peers.values():
case item.connectionState
of Connecting:
of ConnectionState.Connecting:
inc(res.connecting)
of Connected:
of ConnectionState.Connected:
inc(res.connected)
of Disconnecting:
of ConnectionState.Disconnecting:
inc(res.disconnecting)
of Disconnected:
of ConnectionState.Disconnected:
inc(res.disconnected)
of ConnectionState.None:
discard

View File

@ -203,13 +203,13 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
var res: RestNodePeerCount
for item in node.network.peers.values():
case item.connectionState
of Connecting:
of ConnectionState.Connecting:
inc(res.connecting)
of Connected:
of ConnectionState.Connected:
inc(res.connected)
of Disconnecting:
of ConnectionState.Disconnecting:
inc(res.disconnecting)
of Disconnected:
of ConnectionState.Disconnected:
inc(res.disconnected)
of ConnectionState.None:
discard

View File

@ -66,6 +66,8 @@ const
INACTIVITY_SCORE_BIAS* = 4
INACTIVITY_SCORE_RECOVERY_RATE* = 16
SYNC_SUBCOMMITTEE_SIZE* = SYNC_COMMITTEE_SIZE div SYNC_COMMITTEE_SUBNET_COUNT
# "Note: The sum of the weights equal WEIGHT_DENOMINATOR."
static: doAssert TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT +
TIMELY_HEAD_WEIGHT + SYNC_REWARD_WEIGHT + PROPOSER_WEIGHT ==
@ -103,6 +105,9 @@ type
## Signature by the validator over the block root of `slot`
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.8/specs/altair/validator.md#synccommitteecontribution
SyncCommitteeAggregationBits* =
BitArray[SYNC_SUBCOMMITTEE_SIZE]
SyncCommitteeContribution* = object
slot*: Slot ##\
## Slot to which this contribution pertains
@ -114,8 +119,7 @@ type
## The subcommittee this contribution pertains to out of the broader sync
## committee
aggregation_bits*:
BitArray[SYNC_COMMITTEE_SIZE div SYNC_COMMITTEE_SUBNET_COUNT] ##\
aggregation_bits*: SyncCommitteeAggregationBits ##\
## A bit is set if a signature from the validator at the corresponding
## index in the subcommittee is present in the aggregate `signature`.
@ -472,3 +476,13 @@ func shortLog*(v: SomeSignedBeaconBlock): auto =
blck: shortLog(v.message),
signature: shortLog(v.signature)
)
func shortLog*(v: SyncCommitteeMessage): auto =
(
slot: shortLog(v.slot),
beacon_block_root: shortLog(v.beacon_block_root),
validator_index: v.validator_index,
signature: shortLog(v.signature)
)
chronicles.formatIt SyncCommitteeMessage: shortLog(it)

View File

@ -311,3 +311,8 @@ iterator oneIndices*(a: BitArray): int =
for i in 0..<a.len:
if a[i]: yield i
func countOnes*(a: BitArray): int =
# TODO: This can be optimised to work on words
for bit in a:
if bit: inc result

View File

@ -13,6 +13,8 @@ import
../spec/[crypto, datatypes/base, datatypes/altair, datatypes/phase0, digest],
../consensus_object_pools/block_pools_types
from ../spec/datatypes/altair import SyncCommitteeMessage
# Dump errors are generally not fatal where used currently - the code calling
# these functions, like most code, is not exception safe
template logErrors(body: untyped) =
@ -54,3 +56,7 @@ proc dump*(dir: string, v: SomeHashedBeaconState) =
SSZ.saveFile(
dir / &"state-{v.data.slot}-{shortLog(v.root)}.ssz",
v.data)
proc dump*(dir: string, v: SyncCommitteeMessage, validator: ValidatorPubKey) =
logErrors:
SSZ.saveFile(dir / &"sync-committee-msg-{v.slot}-{shortLog(validator)}.ssz", v)