Avoid devnet cold starts#783
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce “cold start” behavior on fresh/local devnets by allowing the relay to accept validator registrations earlier and by making proposer-duty refresh triggers more eager during startup.
Changes:
- Adds
--known-validators/InitialKnownValidatorsto optionally seed the in-memory known-validators cache at startup. - Tweaks proposer-duty refresh gating in both the API and housekeeper to allow earlier/extra refresh attempts at startup.
- Adjusts API proposer-duty gating slot advancement to retry when Redis has not been populated yet.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
services/housekeeper/housekeeper.go |
Refresh gate tweak so proposer duties can update immediately on startup. |
services/api/service.go |
Adds startup seeding path + tweaks proposer-duty refresh gating/slot advancement. |
datastore/datastore.go |
Introduces SetInitialKnownValidators to seed known-validators cache. |
cmd/api.go |
Adds the --known-validators CLI flag and wires it into API options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (ds *Datastore) SetInitialKnownValidators(pubkeys []string, slot uint64) error { | ||
| byPubkey := make(map[common.PubkeyHex]uint64, len(pubkeys)) | ||
| byIndex := make(map[uint64]common.PubkeyHex, len(pubkeys)) | ||
| for i, p := range pubkeys { | ||
| pk := common.NewPubkeyHex(strings.TrimSpace(p)) | ||
| if len(pk.String()) != 98 { | ||
| return fmt.Errorf("invalid pubkey at index %d: %q", i, p) | ||
| } | ||
| idx := uint64(i) | ||
| byPubkey[pk] = idx | ||
| byIndex[idx] = pk | ||
| } | ||
| ds.knownValidatorsLock.Lock() | ||
| ds.knownValidatorsByPubkey = byPubkey | ||
| ds.knownValidatorsByIndex = byIndex | ||
| ds.knownValidatorsLock.Unlock() | ||
| ds.knownValidatorsLastSlot.Store(slot) | ||
| ds.KnownValidatorsWasUpdated.Store(true) | ||
| return nil | ||
| } |
| // SetInitialKnownValidators seeds the known-validators cache directly from a | ||
| // caller-provided list of pubkeys. Intended for devnets to skip the multi-minute | ||
| // cold start while the api waits for the first natural RefreshKnownValidators | ||
| // trigger. Assigns synthetic incrementing indices since the real validator | ||
| // indices are only known after the first beacon query. | ||
| func (ds *Datastore) SetInitialKnownValidators(pubkeys []string, slot uint64) error { |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #783 +/- ##
==========================================
- Coverage 30.47% 29.74% -0.73%
==========================================
Files 42 42
Lines 7236 8118 +882
==========================================
+ Hits 2205 2415 +210
- Misses 4752 5417 +665
- Partials 279 286 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
📝 Summary
--known-validatorsto seed the cache with at startup⛱ Motivation and Context
These changes enable faster initialization in local devnets (i.e. instead of waiting for N slots).
The difference is only at startup. After the first periodical reload happens, no side effect persists.