Skip to content

fix: use ArcSwap for SyncStatus#7213

Open
hanabi1224 wants to merge 1 commit into
mainfrom
hm/arc-swap-for-sync-status
Open

fix: use ArcSwap for SyncStatus#7213
hanabi1224 wants to merge 1 commit into
mainfrom
hm/arc-swap-for-sync-status

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Refactor

    • Improved internal synchronization mechanism for node sync status tracking throughout the application, including chain synchronization, RPC method handlers, health check probes, daemon services, and command-line tools.
  • Tests

    • Updated test infrastructure, fixtures, and assertions to support the new synchronization mechanism used across health check and RPC test suites.

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0fd104f9-59a9-4659-a45f-e966daa1c758

📥 Commits

Reviewing files that changed from the base of the PR and between d1cb4f8 and 669cb11.

📒 Files selected for processing (11)
  • src/chain_sync/chain_follower.rs
  • src/chain_sync/sync_status.rs
  • src/daemon/mod.rs
  • src/db/gc/snapshot.rs
  • src/health/endpoints.rs
  • src/health/mod.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/sync.rs
  • src/tool/offline_server/server.rs
  • src/tool/subcommands/api_cmd/generate_test_snapshot.rs
  • src/tool/subcommands/api_cmd/test_snapshot.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Walkthrough

Replaces parking_lot::RwLock with arc_swap::ArcSwap as the synchronization mechanism for SyncStatus throughout the codebase. The SyncStatus type alias changes from Arc<RwLock<SyncStatusReport>> to Arc<ArcSwap<SyncStatusReport>>, and all read/write call sites are updated to use load()/store() accordingly.

Changes

ArcSwap SyncStatus Migration

Layer / File(s) Summary
SyncStatus type alias redefinition
src/chain_sync/sync_status.rs
Imports arc_swap::ArcSwap, drops parking_lot::RwLock, and changes the exported SyncStatus type alias from Arc<RwLock<SyncStatusReport>> to Arc<ArcSwap<SyncStatusReport>>.
ChainFollower initialization and update loop
src/chain_sync/chain_follower.rs
Replaces RwLock import with ArcSwap; initializes sync_status via ArcSwap::from_pointee; updates the periodic refresh loop to use load()/shallow_clone()/store() instead of read()/write()/clone_from().
Consumer read callsites across services
src/daemon/mod.rs, src/db/gc/snapshot.rs, src/health/endpoints.rs, src/rpc/methods/sync.rs, src/rpc/methods/eth.rs, src/tool/offline_server/server.rs, src/tool/subcommands/api_cmd/...
Replaces all .read() accesses on sync_status with .load() across the daemon cache warmup guard, GC scheduler, health endpoint checks (check_sync_status_synced, check_sync_status_not_error, check_epoch_up_to_date, check_f3_running), RPC sync/eth handlers, and offline server and snapshot tool initializations. Forest.SyncStatus RPC response type changes from SyncStatusReport to Arc<SyncStatusReport>.
Test scaffolding updated for ArcSwap
src/health/mod.rs, src/rpc/methods/sync.rs
Replaces RwLock construction with ArcSwap::from_pointee in all test setups; replaces write()-based field mutation with store() calls using reconstructed SyncStatusReport values; updates assertions to compare via load().clone().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • ChainSafe/forest#6165: Modifies GC scheduling logic in src/db/gc/snapshot.rs to gate on sync_status, the same file updated in this PR to switch from read() to load().

Suggested reviewers

  • akaladarshi
  • LesnyRumcajs
  • elmattic
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: use ArcSwap for SyncStatus' clearly and specifically describes the main change across all modified files, which uniformly replace RwLock-based sync_status with ArcSwap.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/arc-swap-for-sync-status
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/arc-swap-for-sync-status

Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 marked this pull request as ready for review June 22, 2026 02:25
@hanabi1224 hanabi1224 requested a review from a team as a code owner June 22, 2026 02:25
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team June 22, 2026 02:25
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.74359% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.40%. Comparing base (d1cb4f8) to head (669cb11).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/chain_sync/chain_follower.rs 33.33% 2 Missing ⚠️
src/daemon/mod.rs 0.00% 1 Missing ⚠️
src/db/gc/snapshot.rs 0.00% 1 Missing ⚠️
src/health/endpoints.rs 75.00% 1 Missing ⚠️
src/rpc/methods/eth.rs 0.00% 1 Missing ⚠️
src/rpc/methods/sync.rs 92.30% 1 Missing ⚠️
...tool/subcommands/api_cmd/generate_test_snapshot.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/chain_sync/sync_status.rs 12.00% <ø> (ø)
src/health/mod.rs 95.66% <100.00%> (+0.71%) ⬆️
src/tool/offline_server/server.rs 27.23% <100.00%> (ø)
src/tool/subcommands/api_cmd/test_snapshot.rs 82.09% <100.00%> (ø)
src/daemon/mod.rs 24.74% <0.00%> (ø)
src/db/gc/snapshot.rs 0.00% <0.00%> (ø)
src/health/endpoints.rs 89.47% <75.00%> (ø)
src/rpc/methods/eth.rs 65.11% <0.00%> (+0.02%) ⬆️
src/rpc/methods/sync.rs 73.21% <92.30%> (+0.99%) ⬆️
...tool/subcommands/api_cmd/generate_test_snapshot.rs 7.00% <0.00%> (ø)
... and 1 more

... and 15 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1cb4f8...669cb11. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant