handle discrepancy between subnet tracking/nextaction tracking (#3862)

* handle discrepancy between subnet tracking/nextaction tracking

* Update beacon_chain/nimbus_beacon_node.nim

Co-authored-by: Etan Kissling <etan@status.im>

* consistency

Co-authored-by: Etan Kissling <etan@status.im>
This commit is contained in:
tersec 2022-07-12 23:03:07 +00:00 committed by GitHub
parent e0e7af7aff
commit b164f6357b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 9 deletions

View File

@ -1029,7 +1029,15 @@ proc trackCurrentSyncCommitteeTopics(node: BeaconNode, slot: Slot) =
node.network.updateSyncnetsMetadata(currentSyncCommitteeSubnets)
func getNextSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
let epochToSyncPeriod = nearSyncCommitteePeriod(epoch)
let epochsToSyncPeriod = nearSyncCommitteePeriod(epoch)
# The end-slot tracker might call this when it's theoretically applicable,
# but more than SYNC_COMMITTEE_SUBNET_COUNT epochs from when the next sync
# committee period begins, in which case `epochsToNextSyncPeriod` is none.
if epochsToSyncPeriod.isNone or
node.dag.cfg.stateForkAtEpoch(epoch + epochsToSyncPeriod.get) <
BeaconStateFork.Altair:
return static(default(SyncnetBits))
let syncCommittee = withState(node.dag.headState):
when stateFork >= BeaconStateFork.Altair:
@ -1038,20 +1046,20 @@ func getNextSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
return static(default(SyncnetBits))
getSyncSubnets(
node.hasSyncPubKey(epoch + epochToSyncPeriod.get), syncCommittee)
node.hasSyncPubKey(epoch + epochsToSyncPeriod.get), syncCommittee)
proc trackNextSyncCommitteeTopics(node: BeaconNode, slot: Slot) =
let
epoch = slot.epoch
epochToSyncPeriod = nearSyncCommitteePeriod(epoch)
epochsToSyncPeriod = nearSyncCommitteePeriod(epoch)
if epochToSyncPeriod.isNone or
forkVersionAtEpoch(node.dag.cfg, epoch + epochToSyncPeriod.get) ==
node.dag.cfg.GENESIS_FORK_VERSION:
if epochsToSyncPeriod.isNone or
node.dag.cfg.stateForkAtEpoch(epoch + epochsToSyncPeriod.get) <
BeaconStateFork.Altair:
return
# No lookahead required
if epochToSyncPeriod.get == 0:
if epochsToSyncPeriod.get == 0:
node.trackCurrentSyncCommitteeTopics(slot)
return
@ -1065,7 +1073,7 @@ proc trackNextSyncCommitteeTopics(node: BeaconNode, slot: Slot) =
for subcommitteeIdx in SyncSubcommitteeIndex:
if (not node.network.metadata.syncnets[subcommitteeIdx]) and
nextSyncCommitteeSubnets[subcommitteeIdx] and
node.syncCommitteeMsgPool[].isEpochLeadTime(epochToSyncPeriod.get):
node.syncCommitteeMsgPool[].isEpochLeadTime(epochsToSyncPeriod.get):
for gossipFork in node.gossipState:
node.network.subscribe(getSyncCommitteeTopic(
forkDigests[gossipFork], subcommitteeIdx), basicParams)
@ -1075,7 +1083,7 @@ proc trackNextSyncCommitteeTopics(node: BeaconNode, slot: Slot) =
metadata_syncnets = node.network.metadata.syncnets,
nextSyncCommitteeSubnets,
gossipState = node.gossipState,
epochsToSyncPeriod = epochToSyncPeriod.get,
epochsToSyncPeriod = epochsToSyncPeriod.get,
newSubcommittees
node.network.updateSyncnetsMetadata(