feat: add eth2wrap/valcache#122
Conversation
- 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
|
Coverage (base → head): |
- 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
| std::fs::remove_file("src/mod.rs")?; | ||
|
|
||
| // Ensure all structs have both Serialize and Deserialize derives | ||
| ensure_serde_derives("src/types.rs")?; |
There was a problem hiding this comment.
We need to have both Serialize and Deserialize in order to mock Beacon client responses.
There was a problem hiding this comment.
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
valcachemodule with caching for validator information from beacon nodes - Added helper types and extensions in
eth2apimodule for working with validator data - Modified
eth2apibuild script to automatically addSerializederives alongsideDeserializefor test mocking - Changed
PubKey::TryFromimplementation fromStringto&strfor 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.
- Hold lock across awaits - Match the original Go implementation - Simplify internals
There was a problem hiding this comment.
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.
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
wiremockbut I'm open to suggestions on alternative testing approaches.Note that by exercising the actual network requests I found out that some
GETendpoints cannot be used sincereqwest(the underlying HTTP client forEthBeaconNodeApiClient) has troubles building URLs with query parameters.