Compare commits

...

2 Commits

Author SHA1 Message Date
terence tsao
398c616dfb Reduce val index cache 2025-07-15 16:24:28 -07:00
terence tsao
96370a359c fix(execution): skip genesis block retrieval when EIP-6110 is active 2025-07-14 15:04:28 -07:00
4 changed files with 39 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives" "github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v6/encoding/bytesutil" "github.com/OffchainLabs/prysm/v6/encoding/bytesutil"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
log "github.com/sirupsen/logrus"
) )
// ValidatorIndexMap builds a lookup map for quickly determining the index of // ValidatorIndexMap builds a lookup map for quickly determining the index of
@@ -21,8 +22,12 @@ func ValidatorIndexMap(validators []*ethpb.Validator) map[[fieldparams.BLSPubkey
if record == nil { if record == nil {
continue continue
} }
if record.EffectiveBalance == 0 {
continue
}
key := bytesutil.ToBytes48(record.PublicKey) key := bytesutil.ToBytes48(record.PublicKey)
m[key] = primitives.ValidatorIndex(idx) m[key] = primitives.ValidatorIndex(idx)
} }
log.Info("ValidatorIndexMap built with ", len(m), " entries")
return m return m
} }

View File

@@ -557,8 +557,8 @@ func (s *Service) initPOWService() {
} }
} }
// Handle edge case with embedded genesis state by fetching genesis header to determine // Handle edge case with embedded genesis state by fetching genesis header to determine
// its height. // its height only if the deposit requests have not started yet (Pre Pectra EIP-6110 behavior).
if s.chainStartData.Chainstarted && s.chainStartData.GenesisBlock == 0 { if s.chainStartData.Chainstarted && s.chainStartData.GenesisBlock == 0 && !s.depositRequestsStarted {
genHash := common.BytesToHash(s.chainStartData.Eth1Data.BlockHash) genHash := common.BytesToHash(s.chainStartData.Eth1Data.BlockHash)
genBlock := s.chainStartData.GenesisBlock genBlock := s.chainStartData.GenesisBlock
// In the event our provided chainstart data references a non-existent block hash, // In the event our provided chainstart data references a non-existent block hash,

View File

@@ -117,15 +117,40 @@ func (b *BeaconState) ValidatorIndexByPubkey(key [fieldparams.BLSPubkeyLength]by
return 0, false return 0, false
} }
b.lock.RLock() b.lock.RLock()
defer b.lock.RUnlock()
numOfVals := b.validatorsMultiValue.Len(b) numOfVals := b.validatorsMultiValue.Len(b)
// Try fast lookup via validator map first
idx, ok := b.valMapHandler.Get(key) idx, ok := b.valMapHandler.Get(key)
if ok && primitives.ValidatorIndex(numOfVals) <= idx { if ok && idx < primitives.ValidatorIndex(numOfVals) {
return primitives.ValidatorIndex(0), false b.lock.RUnlock()
return idx, true
} }
return idx, ok if ok {
b.lock.RUnlock()
return 0, false // Found in map but out of bounds
}
// Release lock before calling ReadFromEveryValidator to avoid recursive lock
b.lock.RUnlock()
// Fallback: search through all validators using ReadFromEveryValidator
var foundIdx primitives.ValidatorIndex
var found bool
err := b.ReadFromEveryValidator(func(i int, val state.ReadOnlyValidator) error {
if val.PublicKey() == key {
foundIdx = primitives.ValidatorIndex(i)
found = true
return ErrNilParticipation // Return error to break early
}
return nil
})
if err != nil && err != ErrNilParticipation {
return 0, false
}
return foundIdx, found
} }
// PubkeyAtIndex returns the pubkey at the given // PubkeyAtIndex returns the pubkey at the given

View File

@@ -0,0 +1,3 @@
### Fixed
- Skip genesis block retrieval when EIP-6110 deposit requests have started to prevent "pruned history unavailable" errors with execution clients that have pruned pre-merge data