Commit 85c3d1e
authored
Move consesus service into separate library (#2)
* refactor consensus service structure
- Refactored the consensus service in `src/service.rs` to support generic storage and event bus types.
- Removed unused error variants and cleaned up the error handling in `src/error.rs`.
- Introduced new modules for better organization: `events`, `scope`, `session`, `stats`, and `storage`.
- Updated utility functions in `src/utils.rs` for improved vote validation and consensus calculations.
* Update dependencies and enhance consensus service functionality
- Refactored the consensus service in `src/service.rs` to improve proposal creation and voting mechanisms, including the introduction of `CreateProposalRequest` for better request handling.
- Enhanced error handling in `src/error.rs` by adding new error variants for better clarity in consensus operations.
- Improved vote validation logic in `src/utils.rs` and added new utility functions for generating unique IDs for proposals and votes.
- Added comprehensive tests for concurrency, validation, and consensus flow to ensure robustness and compliance with RFC standards.
* Add CI tests to GitHub Actions workflow
* fix round counter
* Update readme and docs
* Enhance project metadata and documentation
- Updated `Cargo.toml` to include a detailed description, license, repository URL, keywords, and readme reference for better project visibility.
- Expanded the `README.md` with new sections on configuring scopes, creating proposals, and handling votes, providing clearer guidance on using the library.
- Introduced a new `scope_config.rs` file to manage scope-level configurations, including network types and default settings for proposals.
- Added new modules for service statistics and consensus handling, improving the overall structure and functionality of the consensus service.
- Enhanced error handling in `error.rs` with additional variants for better clarity in consensus operations.
* Enhance scope configuration validation and clean up code
- Updated `ScopeConfig` validation to allow `max_rounds_override = Some(0)` for P2P networks while enforcing it to be greater than 0 for Gossipsub networks.
- Refactored code for better readability in `service_consensus.rs`, `storage.rs`, and `utils.rs` by consolidating function calls and improving formatting.
- Added unit tests to ensure correct behavior of the new validation logic for scope configurations.
* Update Cargo.toml
* Update README.md
* Fix formatting in README.md example function
* Update event bus documentation and parameter naming for clarity
* Refactor ScopeConfig conversion to ConsensusConfig
* Enhance error handling and validation in consensus logic
* - Simplified the `generate_id` function
- Updated the signature length constant for better maintainability.
- Enhanced vote validation by checking signature length and vote age against constants.
- Replaced `rev().find` with `rfind` for
* Remove hardcoded check as it legacy code
* Enhance vote validation by adding a check for timestamps older than creation time of proposal.
* Remove timestamp check for future votes in `validate_vote` function
* Rename expiration_time to expiration_timestamp
* Refactor proposal expiration handling and enhance error reporting. Updated `ConsensusError` to include `ProposalExpired` and replaced timestamp checks with a dedicated `validate_proposal_timestamp` function for improved clarity and maintainability.
* Refactor timeout handling across the codebase to use `Duration` instead of `u64`. Updated related functions and tests to ensure consistency and improved clarity in timeout management.
* Refactor ConsensusStorage to require Clone trait and update InMemoryConsensusStorage implementation. Simplify storage handling in DefaultConsensusService by removing Arc wrapper.
* Refactor `get_consensus_result` method to return `Result<bool, ConsensusError>` instead of `Option<bool>`, improving clarity on consensus outcomes. Update related tests to reflect these changes.
* Add ScopeNotFound error to ConsensusError and update get_active_proposals and get_reached_proposals methods to return Result<Option<T>, ConsensusError>. Update tests accordingly.
* Refactor `get_consensus_result` method to return a `JoinHandle<()>` for improved task management.
* Refactor storage.rs to use parking_lot for RwLock and simplify session management.
* Refactor consensus service to remove unused timeout task methods and streamline proposal handling. Introduce network gossip tests to validate consensus behavior across multiple peers, ensuring correct handling of proposals and votes.
* Remove async-trait dependency and refactor ConsensusStorage trait methods to return futures directly instead of using async functions.
* Added stream method to storage trait1 parent 8a43e5c commit 85c3d1e
File tree
27 files changed
+10125
-0
lines changed- .github/workflows
- src
- protos/messages/v1
- tests
27 files changed
+10125
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
0 commit comments