From 9d9c37c56164e507abe16a29cdc2d1c39782fedd Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 19 Jul 2021 11:58:30 +0000 Subject: [PATCH] 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 --- .../gossip_processing/block_processor.nim | 8 ++++---- beacon_chain/nimbus_beacon_node.nim | 2 +- beacon_chain/rpc/node_api.nim | 8 ++++---- beacon_chain/rpc/node_rest_api.nim | 8 ++++---- beacon_chain/spec/datatypes/altair.nim | 18 ++++++++++++++++-- beacon_chain/ssz/bitseqs.nim | 5 +++++ beacon_chain/ssz/sszdump.nim | 6 ++++++ 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 07d6e9a29..8a66c219f 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -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" diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 5f753cf70..052536fba 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -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, diff --git a/beacon_chain/rpc/node_api.nim b/beacon_chain/rpc/node_api.nim index 17d9f861a..1e1e9d4da 100644 --- a/beacon_chain/rpc/node_api.nim +++ b/beacon_chain/rpc/node_api.nim @@ -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 diff --git a/beacon_chain/rpc/node_rest_api.nim b/beacon_chain/rpc/node_rest_api.nim index 968b1fbdf..71be6aee1 100644 --- a/beacon_chain/rpc/node_rest_api.nim +++ b/beacon_chain/rpc/node_rest_api.nim @@ -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 diff --git a/beacon_chain/spec/datatypes/altair.nim b/beacon_chain/spec/datatypes/altair.nim index e24ad623f..e0c8c0727 100644 --- a/beacon_chain/spec/datatypes/altair.nim +++ b/beacon_chain/spec/datatypes/altair.nim @@ -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) diff --git a/beacon_chain/ssz/bitseqs.nim b/beacon_chain/ssz/bitseqs.nim index 13db25d1a..8c9aef795 100644 --- a/beacon_chain/ssz/bitseqs.nim +++ b/beacon_chain/ssz/bitseqs.nim @@ -311,3 +311,8 @@ iterator oneIndices*(a: BitArray): int = for i in 0..