use `allSyncCommittees` everywhere (#2917)

There are still a few cases with manual loops through sync subcommittees
even though an `allSyncCommittees` iterator exists. Adjusted the few
remaining instances to also use the iterator instead.
This commit is contained in:
Etan Kissling 2021-09-28 20:02:01 +02:00 committed by GitHub
parent a0e7463732
commit c510ffb16a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 9 deletions

View File

@ -171,13 +171,13 @@ proc produceSyncAggregateAux(
initialized = false initialized = false
startTime = Moment.now startTime = Moment.now
for subnetId in 0 ..< SYNC_COMMITTEE_SUBNET_COUNT: for subnetId in allSyncCommittees():
if bestContributions.subnets[subnetId].totalParticipants == 0: if bestContributions.subnets[subnetId].totalParticipants == 0:
continue continue
for pos, value in bestContributions.subnets[subnetId].participationBits: for pos, value in bestContributions.subnets[subnetId].participationBits:
if value: if value:
let globalPos = subnetId * SYNC_SUBCOMMITTEE_SIZE + pos let globalPos = subnetId.asInt * SYNC_SUBCOMMITTEE_SIZE + pos
result.sync_committee_bits.setBit globalPos result.sync_committee_bits.setBit globalPos
if not initialized: if not initialized:

View File

@ -941,7 +941,7 @@ proc queryRandom*(
peer = n.record.toURI(), exception = e.name, msg = e.msg peer = n.record.toURI(), exception = e.name, msg = e.msg
continue continue
for i in 0..<SYNC_COMMITTEE_SUBNET_COUNT: for i in allSyncCommittees():
if wantedSyncnets[i] and syncnetsNode[i]: if wantedSyncnets[i] and syncnetsNode[i]:
score += 10 # connecting to the right syncnet is urgent score += 10 # connecting to the right syncnet is urgent

View File

@ -437,8 +437,8 @@ proc init*(T: type BeaconNode,
topics &= getAttestationTopic(network.forkDigests.phase0, SubnetId(subnet_id)) topics &= getAttestationTopic(network.forkDigests.phase0, SubnetId(subnet_id))
topics &= getAttestationTopic(network.forkDigests.altair, SubnetId(subnet_id)) topics &= getAttestationTopic(network.forkDigests.altair, SubnetId(subnet_id))
if not config.verifyFinalization: if not config.verifyFinalization:
for subnet_id in 0'u64 ..< SYNC_COMMITTEE_SUBNET_COUNT: for subnet_id in allSyncCommittees():
topics &= getSyncCommitteeTopic(network.forkDigests.altair, SyncCommitteeIndex(subnet_id)) topics &= getSyncCommitteeTopic(network.forkDigests.altair, subnet_id)
topics) topics)
if node.config.inProcessValidators: if node.config.inProcessValidators:

View File

@ -468,8 +468,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, return RestApiResponse.jsonError(Http400,
InvalidSubCommitteeIndexValueError, InvalidSubCommitteeIndexValueError,
$res.error()) $res.error())
let value = res.get() let value = res.get().validateSyncCommitteeIndexOr:
if value >= SYNC_COMMITTEE_SUBNET_COUNT:
return RestApiResponse.jsonError(Http400, return RestApiResponse.jsonError(Http400,
InvalidSubCommitteeIndexValueError, InvalidSubCommitteeIndexValueError,
"subcommittee_index exceeds " & "subcommittee_index exceeds " &
@ -494,7 +493,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
var contribution = SyncCommitteeContribution() var contribution = SyncCommitteeContribution()
let res = node.syncCommitteeMsgPool[].produceContribution( let res = node.syncCommitteeMsgPool[].produceContribution(
qslot, qroot, SyncCommitteeIndex(qindex), contribution) qslot, qroot, qindex, contribution)
if not(res): if not(res):
return RestApiResponse.jsonError(Http400, ProduceContributionError) return RestApiResponse.jsonError(Http400, ProduceContributionError)
return RestApiResponse.jsonResponse(contribution) return RestApiResponse.jsonResponse(contribution)

View File

@ -426,6 +426,8 @@ template asInt*(x: SyncCommitteeIndex): int = int(x)
template asUInt8*(x: SyncCommitteeIndex): uint8 = uint8(x) template asUInt8*(x: SyncCommitteeIndex): uint8 = uint8(x)
template asUInt64*(x: SyncCommitteeIndex): uint64 = uint64(x) template asUInt64*(x: SyncCommitteeIndex): uint64 = uint64(x)
template `[]`*(a: auto; i: SyncCommitteeIndex): auto = a[i.asInt]
template `==`*(x, y: SyncCommitteeIndex): bool = template `==`*(x, y: SyncCommitteeIndex): bool =
distinctBase(x) == distinctBase(y) distinctBase(x) == distinctBase(y)
@ -433,7 +435,9 @@ iterator allSyncCommittees*: SyncCommitteeIndex =
for committeeIdx in 0 ..< SYNC_COMMITTEE_SUBNET_COUNT: for committeeIdx in 0 ..< SYNC_COMMITTEE_SUBNET_COUNT:
yield SyncCommitteeIndex(committeeIdx) yield SyncCommitteeIndex(committeeIdx)
template validateSyncCommitteeIndexOr*(networkValParam: uint64, elseBody: untyped) = template validateSyncCommitteeIndexOr*(
networkValParam: uint64,
elseBody: untyped): SyncCommitteeIndex =
let networkVal = networkValParam let networkVal = networkValParam
if networkVal < SYNC_COMMITTEE_SUBNET_COUNT: if networkVal < SYNC_COMMITTEE_SUBNET_COUNT:
SyncCommitteeIndex(networkVal) SyncCommitteeIndex(networkVal)