From 1585b656c3fbedd4caf2126f5d07e2c44cf88c59 Mon Sep 17 00:00:00 2001 From: Manu NALEPA Date: Thu, 1 Aug 2024 11:52:00 +0200 Subject: [PATCH] `RefreshPersistentSubnets`: Compare cache with both ENR & metadata. --- beacon-chain/p2p/discovery.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/beacon-chain/p2p/discovery.go b/beacon-chain/p2p/discovery.go index 990e2deb8429..50acd0b7dd29 100644 --- a/beacon-chain/p2p/discovery.go +++ b/beacon-chain/p2p/discovery.go @@ -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 } @@ -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 }