Skip to content

feat: add eth2wrap/valcache#122

Merged
emlautarom1 merged 38 commits into
mainfrom
emlautarom1/eth2wrap/valcache
Jan 21, 2026
Merged

feat: add eth2wrap/valcache#122
emlautarom1 merged 38 commits into
mainfrom
emlautarom1/eth2wrap/valcache

Conversation

@emlautarom1
Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 commented Jan 14, 2026

Solves #152
Requires #121


There are some small differences to reduce the amount of time spent with a mutex being held.

For testing I've decided to use wiremock but I'm open to suggestions on alternative testing approaches.

Note that by exercising the actual network requests I found out that some GET endpoints cannot be used since reqwest (the underlying HTTP client for EthBeaconNodeApiClient) has troubles building URLs with query parameters.

- Avoids parsing on each request
- Prevents VSCode from rebuilding everything during tests
- Makes it easier to use `String` and `str` at the same time
- Redices boilerplate when dealing with the `eth2api` lib
- Use `eth2api` types in `valcache`
- Remove redundant code
- Use `From` for `PoisonError`
- Code cleanup
- Prefer `GetStateValidatorsResponseResponseDatum` over custom `Validator`
- Make them closer to the original implementation
@github-actions
Copy link
Copy Markdown
Contributor

Coverage (base → head): 35.44% → 35.43% ⬇️ 0.01 pp
Only posts when PR coverage is lower than the base branch's latest push (or freshly computed base).

- Useful for mocking requests/responses in tests
- Use `POST` endpoint since reqwest cannot deal with complex query params
- Use `wiremock` to fake an HTTP server
- Beacon should be called once
- Superseded by Go tests
@emlautarom1 emlautarom1 marked this pull request as ready for review January 15, 2026 16:45
Copilot AI review requested due to automatic review settings January 15, 2026 16:45
Comment thread crates/eth2api/build.rs
std::fs::remove_file("src/mod.rs")?;

// Ensure all structs have both Serialize and Deserialize derives
ensure_serde_derives("src/types.rs")?;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We need to have both Serialize and Deserialize in order to mock Beacon client responses.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements the eth2wrap/valcache module as part of the broader eth2wrap implementation (issue #60). The PR adds a validator cache that stores active and complete validator information for the current epoch, with the ability to refresh by head or by slot with fallback functionality.

Changes:

  • Added valcache module with caching for validator information from beacon nodes
  • Added helper types and extensions in eth2api module for working with validator data
  • Modified eth2api build script to automatically add Serialize derives alongside Deserialize for test mocking
  • Changed PubKey::TryFrom implementation from String to &str for better ergonomics

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
flake.nix Added RUSTC_BOOTSTRAP = "1" environment variable for Nix dev shell
crates/eth2api/build.rs Added regex-based post-processing to ensure Serialize derives are present
crates/eth2api/Cargo.toml Added regex as build dependency
crates/charon/src/lib.rs Added eth2wrap module with documentation
crates/charon/src/eth2wrap/version.rs Beacon node version validation implementation
crates/charon/src/eth2wrap/valcache.rs Validator cache implementation with comprehensive tests using wiremock
crates/charon/src/eth2wrap/mod.rs Module declarations for eth2wrap components
crates/charon/src/eth2wrap/eth2api.rs Helper types and trait extensions for eth2api
crates/charon/Cargo.toml Added dependencies for eth2api, anyhow, regex, and wiremock
crates/charon-core/src/types.rs Changed PubKey TryFrom implementation from String to &str
Cargo.toml Added wiremock dev dependency and moved regex to appropriate position

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/charon/src/eth2wrap/valcache.rs
Comment thread crates/charon/src/eth2wrap/eth2api.rs Outdated
Comment thread crates/charon/src/eth2wrap/eth2api.rs Outdated
Comment thread crates/eth2api/Cargo.toml
Comment thread crates/charon/src/eth2wrap/mod.rs Outdated
Comment thread crates/charon/src/eth2wrap/valcache.rs
Comment thread crates/charon/src/eth2wrap/version.rs
Comment thread flake.nix
- Hold lock across awaits
- Match the original Go implementation
- Simplify internals
Copilot AI review requested due to automatic review settings January 15, 2026 19:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/charon/src/eth2wrap/valcache.rs
Comment thread crates/charon/src/eth2wrap/valcache.rs Outdated
Comment thread crates/charon/src/eth2wrap/valcache.rs
Copy link
Copy Markdown
Collaborator

@varex83 varex83 left a comment

Choose a reason for hiding this comment

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

LGTM

@emlautarom1 emlautarom1 merged commit cc0a62e into main Jan 21, 2026
7 checks passed
@emlautarom1 emlautarom1 deleted the emlautarom1/eth2wrap/valcache branch January 21, 2026 23:49
@emlautarom1 emlautarom1 linked an issue Jan 28, 2026 that may be closed by this pull request
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.

Implement eth2wrap/valcache

4 participants