refactor: split network maintenance loop into smaller functions#430
refactor: split network maintenance loop into smaller functions#430xdustinface wants to merge 1 commit intov0.42-devfrom
Conversation
📝 WalkthroughWalkthroughThe peer maintenance loop in the network manager is refactored by extracting per-tick maintenance logic and DNS fallback discovery into separate private methods ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9e299da to
f20068c
Compare
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
17eaa24 to
1d9fe8e
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
dash-spv/src/network/manager.rs (1)
861-885:⚠️ Potential issue | 🔴 CriticalReplace
time::sleepwithtime::intervalto prevent maintenance task starvation.
time::sleep(MAINTENANCE_INTERVAL)creates a fresh future on eachtokio::select!loop iteration. Sincetime::interval().tick()fires immediately on the first poll, the DNS branch completes first and the maintenance sleep is dropped before awaiting. WithMAINTENANCE_INTERVALandDNS_DISCOVERY_DELAYboth at 10 seconds,maintenance_tickwill never execute in non-exclusive mode.Use
time::intervalfor both timers to maintain independent periodic cadences:Proposed fix
async fn start_maintenance_loop(&self) { let this = self.clone(); let mut tasks = self.tasks.lock().await; tasks.spawn(async move { + let mut maintenance_interval = time::interval(MAINTENANCE_INTERVAL); let mut dns_interval = time::interval(DNS_DISCOVERY_DELAY); while !this.shutdown_token.is_cancelled() { tokio::select! { - _ = time::sleep(MAINTENANCE_INTERVAL) => { + _ = maintenance_interval.tick() => { log::debug!("Maintenance interval elapsed"); this.maintenance_tick().await; } _ = dns_interval.tick(), if !this.exclusive_mode => { this.dns_fallback_tick().await; } _ = this.shutdown_token.cancelled() => { log::info!("Maintenance loop shutting down"); break; } } } }); }Note: Both
time::intervalinstances tick immediately on first poll. Useinterval.tick().awaitbefore the loop ortime::interval_at()to skip the initial tick if needed.
Make it better readable and maintainable.
Based on:
start_maintenance_looptask #426Summary by CodeRabbit