feat: routing table improvements#36
Conversation
6a15bf3 to
49bb707
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates ant-node’s routing/peer-diversity configuration wiring to match the simplified saorsa-core IP diversity model and adds configuration to persist close-group cache data across restarts.
Changes:
- Replace the old testnet diversity knobs with saorsa-core’s
max_per_ip/max_per_subnetmodel and propagate those into core config. - Add
close_group_cache_dirtoNodeConfigand pass it through to saorsa-core (defaulting toroot_dir). - Update the development-mode unit test to assert permissive diversity limits via the new fields.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/node.rs | Updates build_core_config diversity wiring and sets close_group_cache_dir; adjusts a unit test for the new diversity model. |
| src/config.rs | Simplifies TestnetConfig fields and adds close_group_cache_dir to NodeConfig with defaults. |
| Cargo.toml | Switches saorsa-core dependency from crates.io to a git branch. |
| Cargo.lock | Updates lockfile to reflect the new saorsa-core source and resulting dependency graph changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Cargo.toml
Outdated
| [dependencies] | ||
| # Core (provides EVERYTHING: networking, DHT, security, trust, storage) | ||
| saorsa-core = "0.18.1" | ||
| saorsa-core = { git = "https://github.com/saorsa-labs/saorsa-core.git", branch = "refactor/simplify-ip-diversity" } |
There was a problem hiding this comment.
saorsa-core is pulled from a moving git branch. This makes builds non-reproducible (the branch can change under the same Cargo.toml) and will also block cargo publish if this crate is published. Prefer a crates.io version, or at least pin the git dependency to an immutable rev (or a tag) instead of branch.
| saorsa-core = { git = "https://github.com/saorsa-labs/saorsa-core.git", branch = "refactor/simplify-ip-diversity" } | |
| saorsa-core = { git = "https://github.com/saorsa-labs/saorsa-core.git", rev = "<pinned-commit-sha>" } |
| // Testnet allows loopback so nodes can be co-located on one machine. | ||
| core_config.allow_loopback = true; | ||
| let mut diversity = CoreDiversityConfig::testnet(); | ||
| diversity.max_nodes_per_asn = config.testnet.max_nodes_per_asn; | ||
| diversity.max_nodes_per_ipv6_64 = config.testnet.max_nodes_per_64; | ||
| diversity.enable_geolocation_check = config.testnet.enable_geo_checks; | ||
| diversity.min_geographic_diversity = if config.testnet.enable_geo_checks { | ||
| 3 | ||
| } else { | ||
| 1 | ||
| }; | ||
| core_config.diversity_config = Some(diversity); | ||
|
|
||
| if config.testnet.enforce_age_requirements { | ||
| warn!( | ||
| "testnet.enforce_age_requirements is set but saorsa-core does not yet \ | ||
| expose a knob; age checks may remain relaxed" | ||
| ); | ||
| } | ||
| core_config.diversity_config = Some(CoreDiversityConfig { | ||
| max_per_ip: config.testnet.max_per_ip, | ||
| max_per_subnet: config.testnet.max_per_subnet, | ||
| }); |
There was a problem hiding this comment.
There’s no unit test covering the NetworkMode::Testnet branch of build_core_config (e.g., that allow_loopback is enabled and max_per_ip/max_per_subnet are propagated). Adding a dedicated test would help prevent regressions in testnet behavior, especially after the diversity-config model change.
…oup cache Update to saorsa-core's simplified 2-field IPDiversityConfig (max_per_ip, max_per_subnet) replacing the old 12-field model (ASN limits, geolocation checks, geographic diversity). Add close_group_cache_dir to NodeConfig so nodes persist close group peers and trust scores across restarts, defaulting to root_dir alongside node_identity.key. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…aorsa-core integration adjustments Switch `saorsa-core` to Git-based dependency with updated branch `refactor/simplify-ip-diversity`. Updated multiple dependencies across the ecosystem for enhanced stability and feature set alignment.
Switch from git branch dependency to crates.io release. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1fb5928 to
5be539f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // These return `Option` because `serde(default = "...")` requires the function's | ||
| // return type to match the field type (`Option<usize>`). | ||
| #[allow(clippy::unnecessary_wraps)] | ||
| const fn default_testnet_max_per_ip() -> Option<usize> { | ||
| Some(usize::MAX) | ||
| } | ||
|
|
||
| const fn default_testnet_max_per_64() -> usize { | ||
| 100 | ||
| #[allow(clippy::unnecessary_wraps)] | ||
| const fn default_testnet_max_per_subnet() -> Option<usize> { | ||
| Some(usize::MAX) | ||
| } |
There was a problem hiding this comment.
usize::MAX as a default for TOML-serialized config values is not representable in TOML (integers are limited to signed 64-bit), so NodeConfig::to_file() / toml::to_string_pretty will error on 64-bit platforms. Prefer representing “unlimited” as None for these Option<usize> fields (or use a concrete value <= i64::MAX), and update the doc comments accordingly.
| /// Create a development configuration preset. | ||
| /// | ||
| /// This has minimal restrictions and is only suitable for local testing. | ||
| #[must_use] | ||
| pub fn development() -> Self { | ||
| Self { | ||
| network_mode: NetworkMode::Development, | ||
| testnet: TestnetConfig { | ||
| max_nodes_per_asn: usize::MAX, | ||
| max_nodes_per_64: usize::MAX, | ||
| enforce_age_requirements: false, | ||
| enable_geo_checks: false, | ||
| max_per_ip: Some(usize::MAX), | ||
| max_per_subnet: Some(usize::MAX), | ||
| }, | ||
| ..Self::default() | ||
| } |
There was a problem hiding this comment.
NodeConfig::development() sets testnet: TestnetConfig { ... }, but build_core_config() ignores config.testnet in NetworkMode::Development (it always uses CoreDiversityConfig::permissive()). This makes these values dead/unused and can confuse readers; consider removing the testnet override here or changing the development preset to configure the actual development-mode behavior.
| // Persist close group peers + trust scores across restarts. | ||
| // Default to root_dir (alongside node_identity.key) when not explicitly set. | ||
| core_config.close_group_cache_dir = Some( | ||
| config | ||
| .close_group_cache_dir | ||
| .clone() | ||
| .unwrap_or_else(|| config.root_dir.clone()), | ||
| ); |
There was a problem hiding this comment.
close_group_cache_dir can be set to a custom path, but only config.root_dir is create_dir_all’d before P2PNode::new(). If close_group_cache_dir points to a non-existent directory, saorsa-core may fail when trying to persist the cache. Consider ensuring the resolved close_group_cache_dir exists (create it) before initializing the core node.
| assert_eq!(diversity.max_per_ip, Some(usize::MAX)); | ||
| assert_eq!(diversity.max_per_subnet, Some(usize::MAX)); |
There was a problem hiding this comment.
The development-mode diversity test asserts specific internal field values (Some(usize::MAX)), which makes the test brittle against representation changes (e.g., permissive/unlimited might be expressed as None). It would be more robust to assert equivalence to CoreDiversityConfig::permissive() (or assert the semantic behavior the node relies on) instead of hard-coding sentinel values.
| assert_eq!(diversity.max_per_ip, Some(usize::MAX)); | |
| assert_eq!(diversity.max_per_subnet, Some(usize::MAX)); | |
| let expected = saorsa_core::config::CoreDiversityConfig::permissive(); | |
| assert_eq!(diversity, expected); |
Summary
TestnetConfig(ASN limits, geolocation checks, geographic diversity) with saorsa-core's 2-fieldIPDiversityConfigmodel (max_per_ip,max_per_subnet)close_group_cache_dirtoNodeConfigso nodes persist close group peers and trust scores across restarts (defaults toroot_diralongsidenode_identity.key)Known issues
saorsa-coredependency currently points to a local path (../saorsa-core-refactor) — needs to be updated to a crates.io version or git ref before mergingTest plan
saorsa-coredependency to published versionbuild_core_configcargo test)🤖 Generated with Claude Code