Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move sync logic out of Client #12841

Merged
merged 7 commits into from
Jan 31, 2025
Merged

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented Jan 30, 2025

Reducing number of fields in Client from 41 to 36 and number of lines in client_actor.rs from 2280 to 1974.
There are couple fields clearly related to sync, so I move them to SyncHandler. Its main purpose is to hide sync implementation details and execute handle_sync_needed which is called, well, when sync is needed.

Small caveat was that sometimes an action is needed on Client side - like, request some blocks for state sync. I add SyncHandlerRequest for that, hiding sync logic still seems much better.

Later it should be possible to hide catchup_state_syncs and related fields as well. We can also hide all fields inside SyncHandler if needed.

Diff of movement of the largest functions for convenience: 12841.txt

@Longarithm Longarithm changed the title wip: sync manager refactor: move sync logic out of Client Jan 30, 2025
@Longarithm Longarithm marked this pull request as ready for review January 30, 2025 21:15
@Longarithm Longarithm requested a review from a team as a code owner January 30, 2025 21:15
) -> Result<Vec<(CryptoHash, PeerId)>, near_chain::Error> {
let now = self.clock.now_utc();

let mut have_all = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this used to be returned so the caller can return from handle_sync_needed(), but now it's just logged at the bottom, so could just get rid of that and log whatever you want, maybe blocks_to_request.len() or something

);
let state_sync_result = unwrap_and_report_state_sync_result!(state_sync_result);
match state_sync_result {
StateSyncResult::InProgress => return None,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe just if == (might have to add Eq, PartialEq) instead of the old code's match

@Longarithm Longarithm enabled auto-merge January 31, 2025 08:17
@Longarithm Longarithm disabled auto-merge January 31, 2025 08:20
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 81.12094% with 64 lines in your changes missing coverage. Please review.

Project coverage is 70.39%. Comparing base (6cd375e) to head (4a7a107).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
chain/client/src/sync/handler.rs 83.33% 19 Missing and 19 partials ⚠️
chain/client/src/client_actor.rs 67.56% 10 Missing and 2 partials ⚠️
chain/chain/src/state_sync/utils.rs 77.55% 6 Missing and 5 partials ⚠️
chain/client/src/client.rs 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12841      +/-   ##
==========================================
- Coverage   70.39%   70.39%   -0.01%     
==========================================
  Files         848      851       +3     
  Lines      174091   174195     +104     
  Branches   174091   174195     +104     
==========================================
+ Hits       122548   122617      +69     
- Misses      46296    46334      +38     
+ Partials     5247     5244       -3     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.41% <0.00%> (-0.01%) ⬇️
linux 70.07% <81.12%> (+0.01%) ⬆️
linux-nightly 70.03% <81.12%> (-0.01%) ⬇️
pytests 1.71% <0.00%> (-0.01%) ⬇️
sanity-checks 1.52% <0.00%> (-0.01%) ⬇️
unittests 70.22% <81.12%> (-0.01%) ⬇️
upgradability 0.20% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Longarithm Longarithm enabled auto-merge January 31, 2025 08:34
@Longarithm Longarithm added this pull request to the merge queue Jan 31, 2025
Merged via the queue into near:master with commit cb4c02f Jan 31, 2025
28 of 29 checks passed
@Longarithm Longarithm deleted the sync-manager branch January 31, 2025 09:15
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.

2 participants