Skip to content

Commit 687b704

Browse files
committed
fix stackoverflow in PTCDuties registration by using closure iterators
1 parent 8f92160 commit 687b704

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

beacon_chain/consensus_object_pools/spec_cache.nim

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,3 @@ func is_aggregator*(shufflingRef: ShufflingRef, slot: Slot,
325325
let
326326
committee_len = get_beacon_committee_len(shufflingRef, slot, index)
327327
return is_aggregator(committee_len, slot_signature)
328-
329-
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/gloas/validator.md#payload-timeliness-committee
330-
iterator get_ptc_assignment*(
331-
state: gloas.BeaconState, epoch: Epoch,
332-
validator_indices: HashSet[ValidatorIndex]):
333-
tuple[slot: Slot, validator_index: ValidatorIndex] =
334-
let next_epoch = state.get_current_epoch + 1
335-
doAssert epoch <= next_epoch
336-
337-
var cache = StateCache()
338-
339-
for slot in epoch.slots():
340-
for validator_index in get_ptc(state, slot, cache):
341-
if validator_index in validator_indices:
342-
yield(slot, validator_index)

beacon_chain/spec/beaconstate.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ func can_advance_slots*(
27642764

27652765
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.6/specs/gloas/beacon-chain.md#new-get_ptc
27662766
iterator get_ptc*(state: gloas.BeaconState, slot: Slot, cache: var StateCache):
2767-
ValidatorIndex =
2767+
ValidatorIndex {.closure.} =
27682768
## Get the payload timeliness committee for the given ``slot``
27692769
let epoch = slot.epoch()
27702770
var buffer {.noinit.}: array[40, byte]

beacon_chain/validators/beacon_validators.nim

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,15 +1290,17 @@ proc registerPTCDuties(node: BeaconNode, epoch: Epoch) =
12901290

12911291
withState(node.dag.headState):
12921292
when consensusFork >= ConsensusFork.Gloas:
1293-
for (slot, validator_index) in get_ptc_assignment(
1294-
forkyState.data, epoch, validatorIndices):
1295-
1296-
node.consensusManager[].actionTracker.registerPTCDuty(
1297-
slot, validator_index)
1298-
1299-
debug "PTC duty registered",
1300-
slot = slot,
1301-
epoch = epoch
1293+
var cache = new StateCache
1294+
1295+
for slot in epoch.slots():
1296+
for validator_index in get_ptc(forkyState.data, slot, cache[]):
1297+
if validator_index in validatorIndices:
1298+
node.consensusManager[].actionTracker.registerPTCDuty(
1299+
slot, validator_index)
1300+
1301+
debug "PTC duty registered",
1302+
slot = slot,
1303+
epoch = epoch
13021304

13031305
proc registerDuties*(node: BeaconNode, wallSlot: Slot) {.async: (raises: [CancelledError]).} =
13041306
## Register upcoming duties of attached validators with the duty tracker

0 commit comments

Comments
 (0)