feat: add minimal unopinionated reqresp v1 package#66
Open
Conversation
- Add core interfaces for request/response communication - Support both single and chunked response protocols - Provide generic type-safe APIs without external dependencies - Include flexible encoding/compression abstractions - Add comprehensive examples demonstrating usage This implementation provides a clean, minimal API for libp2p request/response protocols without being opinionated about encoding formats or protocol details. It supports the chunked response pattern needed for protocols like BeaconBlocksByRangeV2. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #66 +/- ##
==========================================
+ Coverage 39.43% 39.47% +0.04%
==========================================
Files 59 63 +4
Lines 5942 6275 +333
==========================================
+ Hits 2343 2477 +134
- Misses 3354 3529 +175
- Partials 245 269 +24 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mattevans
approved these changes
Jul 4, 2025
- Remove global encoder/compressor from service config - Add HandlerOptions parameter to RegisterProtocol functions - Add SendRequestWithOptions for per-request encoding - Update examples to show protocol-specific encoding - Improve middleware example to demonstrate actual usage This allows different protocols to use different encoding strategies: - JSON for metadata protocols - SSZ for consensus data - Different compression per protocol Breaking changes: - RegisterProtocol now requires HandlerOptions parameter - ClientConfig no longer has Encoder/Compressor fields 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for client.go covering SendRequest, retry logic, timeouts, and chunked requests - Add tests for handler.go covering request handling, validation, and error responses - Add tests for chunked_handler.go covering chunked responses and ChunkedResponseWriter - Add tests for reqresp.go covering service lifecycle and concurrent operations - Add tests for types.go covering Status, error constants, and configurations - Create comprehensive mock implementations for host.Host, network.Stream, and other interfaces - Achieve 72.6% test coverage, exceeding the >70% target Test coverage breakdown: - client.go: High coverage for core functionality - handler.go: Excellent coverage (94.7% for HandleStream) - chunked_handler.go: Excellent coverage (95% for HandleStream) - types.go: 100% coverage for key functions - reqresp.go: Good coverage for service operations
- Add unit tests for all major components - Add mock implementations for libp2p interfaces - Add panic recovery to handlers for robustness - Add proper timeout handling with context - Fix empty request validation - Fix integration test race conditions - All tests now pass successfully Coverage highlights: - Total package: 77.9% - Handler.HandleStream: 94.7% - ChunkedHandler.HandleStream: 95.0% - Client.SendRequestWithOptions: 95.5% 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Add blank line before return statements (nlreturn) - Add blank line before if statements after assignments (wsl) - All linting issues now resolved 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
Test/reqresp v1 coverage
feat: support per-protocol encoding in reqresp v1
…pinionated-reqresp
Add compile-time safe protocol creation for Ethereum consensus layer protocols. The eth package provides factory functions that validate protocol IDs at compile time without being opinionated about message types or encoders. - Factory functions for all Ethereum consensus protocols - No predefined message types (users provide their own) - No default protocol instances - Comprehensive examples showing usage patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…aces - Merged Encoder and Compressor into single NetworkEncoder interface - Updated all protocol constructors to use NetworkEncoder - Removed unnecessary abstractions and simplified architecture - Added SSZSnappyEncoder implementation as example - Updated all tests and examples to use new API - Removed unused fields and imports This change better reflects how Ethereum protocols work (always using SSZ+Snappy together) and significantly simplifies the API. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Removed empty Config struct that served no purpose - Deleted broken example files that provided no value - Simplified protocol abstractions into single SimpleProtocol type - Merged ChunkedProtocol interface into Protocol with IsChunked() method - Removed inheritance pattern in favor of simple struct with boolean field The package is now much cleaner with only essential functionality and no unnecessary abstractions or broken examples. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for all core functionality with 87.3% coverage - Add tests for protocol implementations with 100% coverage - Test service lifecycle, handler registration, stream handling - Test error scenarios and concurrent operations - Test SSZ+Snappy encoder implementation - Test all Ethereum protocol constructors All tests pass successfully, exceeding the 80% coverage target. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pkg/consensus/mimicry/p2p/reqresp/v1Key Features
Implementation Details
The package includes:
interface.go: Core interfaces and abstractionstypes.go: Basic types, error definitions, and configuration structshandler.go: Generic handler implementation with request/response processingchunked_handler.go: Support for protocols that send multiple response chunksclient.go: Client implementation with retry logic and chunked response supportreqresp.go: Main service implementation that ties everything togetherprotocols.go: Helper types for creating protocolsexample_test.go: Usage examples showing JSON encoding, custom protocols, and chunked responsesTest Plan
🤖 Generated with Claude Code