diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index 48ce290c1..7cc7148b6 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -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) diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index e93ea58e0..4a735e48c 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -68,7 +68,7 @@ type of BeaconBlockFork.Merge: mergeBlock*: merge.TrustedSignedBeaconBlock - ForkDigests* {.requiresInit.} = object + ForkDigests* = object phase0*: ForkDigest altair*: ForkDigest merge*: ForkDigest diff --git a/tests/test_gossip_validation.nim b/tests/test_gossip_validation.nim index 9ecfdf056..8963cd011 100644 --- a/tests/test_gossip_validation.nim +++ b/tests/test_gossip_validation.nim @@ -178,13 +178,13 @@ suite "Gossip validation " & preset(): suite "Gossip validation - Extra": # Not based on preset config test "validateSyncCommitteeMessage": const num_validators = SLOTS_PER_EPOCH - let + let cfg = block: var cfg = defaultRuntimeConfig cfg.ALTAIR_FORK_EPOCH = (GENESIS_EPOCH + 1).Epoch cfg dag = block: - let + let dag = ChainDAGRef.init(cfg, makeTestDB(num_validators), {}) taskpool = Taskpool.new() quarantine = QuarantineRef.init(keys.newRng(), taskpool) @@ -192,7 +192,7 @@ suite "Gossip validation - Extra": # Not based on preset config for blck in makeTestBlocks( dag.headState.data, dag.head.root, cache, int(SLOTS_PER_EPOCH), false, cfg = cfg): - let added = + let added = case blck.kind of BeaconBlockFork.Phase0: const nilCallback = OnPhase0BlockAdded(nil) @@ -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) @@ -225,7 +225,7 @@ suite "Gossip validation - Extra": # Not based on preset config syncCommitteeMsgPool = newClone(SyncCommitteeMsgPool.init()) res = validateSyncCommitteeMessage( - dag, syncCommitteeMsgPool, msg, syncCommitteeIdx, + dag, syncCommitteeMsgPool, msg, syncCommitteeIdx, state[].data.slot.toBeaconTime(), true) contribution = block: var contribution: SyncCommitteeContribution