Skip to content

fix: use ArcSwap for SyncStatus#7213

Merged
LesnyRumcajs merged 5 commits into
mainfrom
hm/arc-swap-for-sync-status
Jun 22, 2026
Merged

fix: use ArcSwap for SyncStatus#7213
LesnyRumcajs merged 5 commits 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
    • Updated how sync status is shared and read across sync components, daemon warmup behavior, garbage collection scheduling, RPC handlers, health probes, and offline/snapshot tooling to reduce locking and better reflect the latest state.
  • Tests
    • Updated healthcheck and RPC test scaffolding/fixtures to use the new sync-status access pattern, keeping readiness/liveness checks and syncing assertions consistent.

@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: 923a9bd4-61a2-40a4-8850-16ffe909cdb1

📥 Commits

Reviewing files that changed from the base of the PR and between b07705e and 828f0f7.

📒 Files selected for processing (1)
  • src/health/mod.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/health/mod.rs

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 callsites are updated to use load()/store() accordingly.

Changes

ArcSwap SyncStatus Migration

Layer / File(s) Summary
SyncStatus type alias and test helpers
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>>. Adds test-only builder methods with_status() and with_current_head_epoch() on SyncStatusReport.
ChainFollower initialization and periodic update
src/chain_sync/chain_follower.rs
Replaces RwLock import with ArcSwap; initializes sync_status via ArcSwap::from_pointee(SyncStatusReport::init()); 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>.
Health endpoint test scaffolding updated for ArcSwap
src/health/mod.rs
Replaces RwLock construction with ArcSwap::from_pointee in all health tests; replaces write()-based field mutation with store() calls using reconstructed SyncStatusReport values. Covers test_check_readyz, test_check_livez, test_check_healthz, and test_check_unknown_healthcheck_endpoint.
RPC sync test scaffolding and assertions
src/rpc/methods/sync.rs
Updates test RPCState.sync_status initialization from Arc<RwLock<...>> to Default::default() with ArcSwap backing; updates sync_status_test assertions to compare via load().clone() and mutate via store() with reconstructed SyncStatusReport values.

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
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.17% 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 accurately describes the main change: replacing RwLock-based SyncStatus with ArcSwap across the codebase for concurrent atomic reference swapping.
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 91.39785% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.41%. Comparing base (9aa6f70) to head (ddb176a).
✅ 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.85% 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 24.13% <100.00%> (+12.13%) ⬆️
src/health/mod.rs 95.76% <100.00%> (+0.81%) ⬆️
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.37% <92.85%> (+1.15%) ⬆️
...tool/subcommands/api_cmd/generate_test_snapshot.rs 7.00% <0.00%> (ø)
... and 1 more

... and 10 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 9aa6f70...ddb176a. 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.

Comment thread src/health/mod.rs
@hanabi1224 hanabi1224 enabled auto-merge June 22, 2026 10:03
@hanabi1224 hanabi1224 added this pull request to the merge queue Jun 22, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 22, 2026
@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Jun 22, 2026
Merged via the queue into main with commit 8c8e717 Jun 22, 2026
33 checks passed
@LesnyRumcajs LesnyRumcajs deleted the hm/arc-swap-for-sync-status branch June 22, 2026 11:06
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.

2 participants