mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-23 13:00:34 +00:00
harden sync sub committee selection (#2965)
* harden sync sub committee selection also turn it into an iterator * fix test and warning
This commit is contained in:
parent
dfb87f1d5b
commit
fabec894dd
@ -1027,19 +1027,16 @@ proc pruneBlocksDAG(dag: ChainDAGRef) =
|
||||
prunedHeads = hlen - dag.heads.len,
|
||||
dagPruneDur = Moment.now() - startTick
|
||||
|
||||
func syncSubcommittee*(syncCommittee: openarray[ValidatorPubKey],
|
||||
committeeIdx: SyncCommitteeIndex): seq[ValidatorPubKey] =
|
||||
## TODO Return a view type
|
||||
## Unfortunately, this doesn't work as a template right now.
|
||||
if syncCommittee.len == 0:
|
||||
return @[]
|
||||
iterator syncSubcommittee*(
|
||||
syncCommittee: openarray[ValidatorPubKey],
|
||||
committeeIdx: SyncCommitteeIndex): ValidatorPubKey =
|
||||
var
|
||||
i = committeeIdx.asInt * SYNC_SUBCOMMITTEE_SIZE
|
||||
onePastEndIdx = min(syncCommittee.len, i + SYNC_SUBCOMMITTEE_SIZE)
|
||||
|
||||
let
|
||||
startIdx = committeeIdx.asInt * SYNC_SUBCOMMITTEE_SIZE
|
||||
onePastEndIdx = startIdx + SYNC_SUBCOMMITTEE_SIZE
|
||||
doAssert startIdx < syncCommittee.len
|
||||
|
||||
@(toOpenArray(syncCommittee, startIdx, onePastEndIdx - 1))
|
||||
while i < onePastEndIdx:
|
||||
yield syncCommittee[i]
|
||||
inc i
|
||||
|
||||
func syncCommitteeParticipants*(dagParam: ChainDAGRef,
|
||||
slotParam: Slot): seq[ValidatorPubKey] =
|
||||
@ -1081,7 +1078,7 @@ func getSubcommitteePositionsAux(
|
||||
return @[]
|
||||
let validatorPubKey = validatorKey.get().toPubKey
|
||||
|
||||
for pos, key in syncCommittee.syncSubcommittee(committeeIdx):
|
||||
for pos, key in toSeq(syncCommittee.syncSubcommittee(committeeIdx)):
|
||||
if validatorPubKey == key:
|
||||
result.add uint64(pos)
|
||||
|
||||
|
@ -68,7 +68,7 @@ type
|
||||
of BeaconBlockFork.Merge:
|
||||
mergeBlock*: merge.TrustedSignedBeaconBlock
|
||||
|
||||
ForkDigests* {.requiresInit.} = object
|
||||
ForkDigests* = object
|
||||
phase0*: ForkDigest
|
||||
altair*: ForkDigest
|
||||
merge*: ForkDigest
|
||||
|
@ -210,7 +210,7 @@ suite "Gossip validation - Extra": # Not based on preset config
|
||||
|
||||
syncCommitteeIdx = 0.SyncCommitteeIndex
|
||||
syncCommittee = @(dag.syncCommitteeParticipants(state[].data.slot))
|
||||
subcommittee = syncCommittee.syncSubcommittee(syncCommitteeIdx)
|
||||
subcommittee = toSeq(syncCommittee.syncSubcommittee(syncCommitteeIdx))
|
||||
|
||||
pubkey = subcommittee[0]
|
||||
expectedCount = subcommittee.count(pubkey)
|
||||
|
Loading…
x
Reference in New Issue
Block a user