Skip to content

Avoid devnet cold starts#783

Open
canercidam wants to merge 4 commits into
mainfrom
caner/devnet-cold-starts
Open

Avoid devnet cold starts#783
canercidam wants to merge 4 commits into
mainfrom
caner/devnet-cold-starts

Conversation

@canercidam

Copy link
Copy Markdown
Member

📝 Summary

  • New flag --known-validators to seed the cache with at startup
  • Minor logic tweaks to trigger reloads more often in the beginning

⛱ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / InitialKnownValidators to 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.

Comment thread datastore/datastore.go
Comment on lines +165 to +184
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
}
Comment thread datastore/datastore.go
Comment on lines +160 to +165
// 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-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 5.08475% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 29.74%. Comparing base (c71fc35) to head (6b6ae1e).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
services/api/service.go 8.57% 29 Missing and 3 partials ⚠️
datastore/datastore.go 0.00% 18 Missing ⚠️
cmd/api.go 0.00% 5 Missing ⚠️
services/housekeeper/housekeeper.go 0.00% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 29.74% <5.08%> (-0.73%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants