Skip to content

feat: routing table improvements#36

Merged
jacderida merged 3 commits intoWithAutonomi:mainfrom
mickvandijke:feat/ip-diversity-simplification
Mar 30, 2026
Merged

feat: routing table improvements#36
jacderida merged 3 commits intoWithAutonomi:mainfrom
mickvandijke:feat/ip-diversity-simplification

Conversation

@mickvandijke
Copy link
Copy Markdown
Collaborator

Summary

  • IP diversity config simplified: Replace the old 12-field TestnetConfig (ASN limits, geolocation checks, geographic diversity) with saorsa-core's 2-field IPDiversityConfig model (max_per_ip, max_per_subnet)
  • Close group cache persistence: Add close_group_cache_dir to NodeConfig so nodes persist close group peers and trust scores across restarts (defaults to root_dir alongside node_identity.key)
  • Updated tests: Renamed and updated development mode test to verify permissive diversity config

Known issues

  • saorsa-core dependency currently points to a local path (../saorsa-core-refactor) — needs to be updated to a crates.io version or git ref before merging

Test plan

  • Update saorsa-core dependency to published version
  • Add test for Testnet mode branch in build_core_config
  • Verify testnet config values propagate correctly to core
  • Run full test suite (cargo test)
  • Verify CI passes

🤖 Generated with Claude Code

@mickvandijke mickvandijke changed the title feat: align with saorsa-core IP diversity simplification and close group cache feat: routing table improvements Mar 25, 2026
@mickvandijke mickvandijke force-pushed the feat/ip-diversity-simplification branch from 6a15bf3 to 49bb707 Compare March 30, 2026 18:55
@mickvandijke mickvandijke marked this pull request as ready for review March 30, 2026 19:58
Copilot AI review requested due to automatic review settings March 30, 2026 19:58
Copy link
Copy Markdown

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 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_subnet model and propagate those into core config.
  • Add close_group_cache_dir to NodeConfig and pass it through to saorsa-core (defaulting to root_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" }
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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>" }

Copilot uses AI. Check for mistakes.
Comment on lines 178 to +183
// 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,
});
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
mickvandijke and others added 3 commits March 30, 2026 22:45
…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>
Copilot AI review requested due to automatic review settings March 30, 2026 21:46
@jacderida jacderida force-pushed the feat/ip-diversity-simplification branch from 1fb5928 to 5be539f Compare March 30, 2026 21:46
Copy link
Copy Markdown

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 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.

Comment on lines +79 to 89
// 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)
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 283 to 295
/// 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()
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +190 to +197
// 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()),
);
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +873 to +874
assert_eq!(diversity.max_per_ip, Some(usize::MAX));
assert_eq!(diversity.max_per_subnet, Some(usize::MAX));
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
@jacderida jacderida merged commit c14ecb2 into WithAutonomi:main Mar 30, 2026
15 checks passed
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.

3 participants