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:
parent
aebc606cb7
commit
9d9c37c561
|
@ -11,9 +11,8 @@ import
|
||||||
std/math,
|
std/math,
|
||||||
stew/results,
|
stew/results,
|
||||||
chronicles, chronos, metrics,
|
chronicles, chronos, metrics,
|
||||||
../spec/[
|
../spec/datatypes/[phase0, altair],
|
||||||
crypto, datatypes/phase0, datatypes/altair, digest,
|
../spec/[crypto, digest, forkedbeaconstate_helpers],
|
||||||
forkedbeaconstate_helpers],
|
|
||||||
../consensus_object_pools/[block_clearance, blockchain_dag, attestation_pool],
|
../consensus_object_pools/[block_clearance, blockchain_dag, attestation_pool],
|
||||||
./consensus_manager,
|
./consensus_manager,
|
||||||
".."/[beacon_clock, beacon_node_types],
|
".."/[beacon_clock, beacon_node_types],
|
||||||
|
@ -123,7 +122,8 @@ proc addBlock*(
|
||||||
# sanity check
|
# sanity check
|
||||||
try:
|
try:
|
||||||
self.blocksQueue.addLastNoWait(BlockEntry(
|
self.blocksQueue.addLastNoWait(BlockEntry(
|
||||||
blck: blck, resfut: resfut, queueTick: Moment.now(),
|
blck: blck,
|
||||||
|
resfut: resfut, queueTick: Moment.now(),
|
||||||
validationDur: validationDur))
|
validationDur: validationDur))
|
||||||
except AsyncQueueFullError:
|
except AsyncQueueFullError:
|
||||||
raiseAssert "unbounded queue"
|
raiseAssert "unbounded queue"
|
||||||
|
|
|
@ -1050,7 +1050,7 @@ proc startSyncManager(node: BeaconNode) =
|
||||||
true
|
true
|
||||||
|
|
||||||
proc onDeletePeer(peer: Peer) =
|
proc onDeletePeer(peer: Peer) =
|
||||||
if peer.connectionState notin {Disconnecting, Disconnected}:
|
if peer.connectionState notin {Disconnecting, ConnectionState.Disconnected}:
|
||||||
if peer.score < PeerScoreLowLimit:
|
if peer.score < PeerScoreLowLimit:
|
||||||
debug "Peer was removed from PeerPool due to low score", peer = peer,
|
debug "Peer was removed from PeerPool due to low score", peer = peer,
|
||||||
peer_score = peer.score, score_low_limit = PeerScoreLowLimit,
|
peer_score = peer.score, score_low_limit = PeerScoreLowLimit,
|
||||||
|
|
|
@ -207,13 +207,13 @@ proc installNodeApiHandlers*(rpcServer: RpcServer, node: BeaconNode) {.
|
||||||
var res: NodePeerCountTuple
|
var res: NodePeerCountTuple
|
||||||
for item in node.network.peers.values():
|
for item in node.network.peers.values():
|
||||||
case item.connectionState
|
case item.connectionState
|
||||||
of Connecting:
|
of ConnectionState.Connecting:
|
||||||
inc(res.connecting)
|
inc(res.connecting)
|
||||||
of Connected:
|
of ConnectionState.Connected:
|
||||||
inc(res.connected)
|
inc(res.connected)
|
||||||
of Disconnecting:
|
of ConnectionState.Disconnecting:
|
||||||
inc(res.disconnecting)
|
inc(res.disconnecting)
|
||||||
of Disconnected:
|
of ConnectionState.Disconnected:
|
||||||
inc(res.disconnected)
|
inc(res.disconnected)
|
||||||
of ConnectionState.None:
|
of ConnectionState.None:
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -203,13 +203,13 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
var res: RestNodePeerCount
|
var res: RestNodePeerCount
|
||||||
for item in node.network.peers.values():
|
for item in node.network.peers.values():
|
||||||
case item.connectionState
|
case item.connectionState
|
||||||
of Connecting:
|
of ConnectionState.Connecting:
|
||||||
inc(res.connecting)
|
inc(res.connecting)
|
||||||
of Connected:
|
of ConnectionState.Connected:
|
||||||
inc(res.connected)
|
inc(res.connected)
|
||||||
of Disconnecting:
|
of ConnectionState.Disconnecting:
|
||||||
inc(res.disconnecting)
|
inc(res.disconnecting)
|
||||||
of Disconnected:
|
of ConnectionState.Disconnected:
|
||||||
inc(res.disconnected)
|
inc(res.disconnected)
|
||||||
of ConnectionState.None:
|
of ConnectionState.None:
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -66,6 +66,8 @@ const
|
||||||
INACTIVITY_SCORE_BIAS* = 4
|
INACTIVITY_SCORE_BIAS* = 4
|
||||||
INACTIVITY_SCORE_RECOVERY_RATE* = 16
|
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."
|
# "Note: The sum of the weights equal WEIGHT_DENOMINATOR."
|
||||||
static: doAssert TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT +
|
static: doAssert TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT +
|
||||||
TIMELY_HEAD_WEIGHT + SYNC_REWARD_WEIGHT + PROPOSER_WEIGHT ==
|
TIMELY_HEAD_WEIGHT + SYNC_REWARD_WEIGHT + PROPOSER_WEIGHT ==
|
||||||
|
@ -103,6 +105,9 @@ type
|
||||||
## Signature by the validator over the block root of `slot`
|
## 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
|
# 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
|
SyncCommitteeContribution* = object
|
||||||
slot*: Slot ##\
|
slot*: Slot ##\
|
||||||
## Slot to which this contribution pertains
|
## Slot to which this contribution pertains
|
||||||
|
@ -114,8 +119,7 @@ type
|
||||||
## The subcommittee this contribution pertains to out of the broader sync
|
## The subcommittee this contribution pertains to out of the broader sync
|
||||||
## committee
|
## committee
|
||||||
|
|
||||||
aggregation_bits*:
|
aggregation_bits*: SyncCommitteeAggregationBits ##\
|
||||||
BitArray[SYNC_COMMITTEE_SIZE div SYNC_COMMITTEE_SUBNET_COUNT] ##\
|
|
||||||
## A bit is set if a signature from the validator at the corresponding
|
## A bit is set if a signature from the validator at the corresponding
|
||||||
## index in the subcommittee is present in the aggregate `signature`.
|
## index in the subcommittee is present in the aggregate `signature`.
|
||||||
|
|
||||||
|
@ -472,3 +476,13 @@ func shortLog*(v: SomeSignedBeaconBlock): auto =
|
||||||
blck: shortLog(v.message),
|
blck: shortLog(v.message),
|
||||||
signature: shortLog(v.signature)
|
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)
|
||||||
|
|
|
@ -311,3 +311,8 @@ iterator oneIndices*(a: BitArray): int =
|
||||||
for i in 0..<a.len:
|
for i in 0..<a.len:
|
||||||
if a[i]: yield i
|
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
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ import
|
||||||
../spec/[crypto, datatypes/base, datatypes/altair, datatypes/phase0, digest],
|
../spec/[crypto, datatypes/base, datatypes/altair, datatypes/phase0, digest],
|
||||||
../consensus_object_pools/block_pools_types
|
../consensus_object_pools/block_pools_types
|
||||||
|
|
||||||
|
from ../spec/datatypes/altair import SyncCommitteeMessage
|
||||||
|
|
||||||
# Dump errors are generally not fatal where used currently - the code calling
|
# Dump errors are generally not fatal where used currently - the code calling
|
||||||
# these functions, like most code, is not exception safe
|
# these functions, like most code, is not exception safe
|
||||||
template logErrors(body: untyped) =
|
template logErrors(body: untyped) =
|
||||||
|
@ -54,3 +56,7 @@ proc dump*(dir: string, v: SomeHashedBeaconState) =
|
||||||
SSZ.saveFile(
|
SSZ.saveFile(
|
||||||
dir / &"state-{v.data.slot}-{shortLog(v.root)}.ssz",
|
dir / &"state-{v.data.slot}-{shortLog(v.root)}.ssz",
|
||||||
v.data)
|
v.data)
|
||||||
|
|
||||||
|
proc dump*(dir: string, v: SyncCommitteeMessage, validator: ValidatorPubKey) =
|
||||||
|
logErrors:
|
||||||
|
SSZ.saveFile(dir / &"sync-committee-msg-{v.slot}-{shortLog(validator)}.ssz", v)
|
||||||
|
|
Loading…
Reference in New Issue