Skip to content

Commit

Permalink
RefreshPersistentSubnets: Compare cache with both ENR & metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Aug 1, 2024
1 parent 3ce7340 commit 1585b65
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions beacon-chain/p2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ func (s *Service) RefreshPersistentSubnets() {
return
}

// Get the attestation subnet bitfield in our metadata.
inMetadataBitV := s.Metadata().AttnetsBitfield()

// Is our attestation bitvector record up to date?
isOurBitVRecordUpToDate := bytes.Equal(bitV, inRecordBitV)
isBitVUpToDate := bytes.Equal(bitV, inRecordBitV) && bytes.Equal(bitV, inMetadataBitV)

// Compare current epoch with our fork epochs
altairForkEpoch := params.BeaconConfig().AltairForkEpoch

if currentEpoch < altairForkEpoch {
// Phase 0 behaviour.
if isOurBitVRecordUpToDate {
if isBitVUpToDate {
// Return early if bitfield hasn't changed.
return
}
Expand All @@ -134,9 +137,12 @@ func (s *Service) RefreshPersistentSubnets() {
return
}

isOurBitSRecordUpToDate := bytes.Equal(bitS, currentBitS)
// Get the sync subnet bitfield in our metadata.
currentBitSInMetadata := s.Metadata().SyncnetsBitfield()

isBitSUpToDate := bytes.Equal(bitS, currentBitS) && bytes.Equal(bitS, currentBitSInMetadata)

if metadataVersion == version.Altair && isOurBitVRecordUpToDate && isOurBitSRecordUpToDate {
if metadataVersion == version.Altair && isBitVUpToDate && isBitSUpToDate {
// Nothing to do, return early.
return
}
Expand Down

0 comments on commit 1585b65

Please sign in to comment.