-
Notifications
You must be signed in to change notification settings - Fork 40
Fix waitsync operation and performance #2008
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
Changes from all commits
63b1b83
eadc26e
f7394f5
67242b3
cfc1890
b6c8e3b
95618da
a30f651
d6667be
7345917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,8 @@ const VERIFY_BLOCK_RANGE_SIZE: u32 = 10; | |
| pub struct SyncStatus { | ||
| pub scan_ranges: Vec<ScanRange>, | ||
| pub sync_start_height: BlockHeight, | ||
| pub total_blocks: u32, | ||
| pub total_outputs: u32, | ||
| pub session_blocks_scanned: u32, | ||
| pub total_blocks_scanned: u32, | ||
| pub percentage_session_blocks_scanned: f32, | ||
|
|
@@ -98,6 +100,11 @@ impl From<SyncStatus> for json::JsonValue { | |
| }) | ||
| .collect(); | ||
|
|
||
| // Derive a simple boolean completeness flag from integer counts | ||
| let sync_complete = value.total_blocks_scanned >= value.total_blocks | ||
| && (value.total_sapling_outputs_scanned + value.total_orchard_outputs_scanned) | ||
| >= value.total_outputs; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this sync completeness is equivalent to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh sorry, it is actually equivalent to the sync poll returning a sync complete. is there an issue with sync poll you are experiencing? if you could write up a detailed issue we can discuss the solution if thats ok |
||
| json::object! { | ||
| "scan_ranges" => scan_ranges, | ||
| "sync_start_height" => u32::from(value.sync_start_height), | ||
|
|
@@ -111,6 +118,7 @@ impl From<SyncStatus> for json::JsonValue { | |
| "total_orchard_outputs_scanned" => value.total_orchard_outputs_scanned, | ||
| "percentage_session_outputs_scanned" => value.percentage_session_outputs_scanned, | ||
| "percentage_total_outputs_scanned" => value.percentage_total_outputs_scanned, | ||
| "sync_complete" => sync_complete, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -598,6 +606,8 @@ where | |
| return Ok(SyncStatus { | ||
| scan_ranges: sync_state.scan_ranges.clone(), | ||
| sync_start_height: 0.into(), | ||
| total_blocks: 0, | ||
| total_outputs: 0, | ||
| session_blocks_scanned: 0, | ||
| total_blocks_scanned: 0, | ||
| percentage_session_blocks_scanned: 0.0, | ||
|
|
@@ -671,6 +681,8 @@ where | |
| Ok(SyncStatus { | ||
| scan_ranges: sync_state.scan_ranges.clone(), | ||
| sync_start_height: sync_state.initial_sync_state.sync_start_height, | ||
| total_blocks, | ||
| total_outputs, | ||
| session_blocks_scanned, | ||
| total_blocks_scanned, | ||
| percentage_session_blocks_scanned, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -516,37 +516,44 @@ fn dispatch_command_or_start_interactive(cli_config: &ConfigTemplate) { | |
| if cli_config.command.is_none() { | ||
| start_interactive(command_transmitter, resp_receiver); | ||
| } else { | ||
| // Optionally wait for background sync to finish before executing command | ||
| // Optionally wait for background sync to finish before executing command. | ||
| // Retry requesting status until the channel closes or the percentage field | ||
| // indicates completion. | ||
| if cli_config.sync && cli_config.waitsync { | ||
| use std::{thread, time::Duration}; | ||
|
|
||
| loop { | ||
| // Poll sync task status | ||
| // Request machine-readable sync status. | ||
| command_transmitter | ||
| .send(("sync".to_string(), vec!["poll".to_string()])) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sync poll cannot be replaced by sync status. sync poll is polling the sync handle and it the only way to return the actual errors from the sync task. |
||
| .send(("sync".to_string(), vec!["status".to_string()])) | ||
| .unwrap(); | ||
|
|
||
| match resp_receiver.recv() { | ||
| Ok(resp) => { | ||
| if resp.starts_with("Error:") { | ||
| eprintln!( | ||
| "Sync error while waiting: {resp}\nProceeding to execute the command." | ||
| ); | ||
| break; | ||
| } else if resp.starts_with("Sync completed succesfully:") { | ||
| // Sync finished; proceed | ||
| break; | ||
| } else if resp == "Sync task has not been launched." { | ||
| // Try to launch sync and continue waiting | ||
| command_transmitter | ||
| .send(("sync".to_string(), vec!["run".to_string()])) | ||
| .unwrap(); | ||
| let _ = resp_receiver.recv(); | ||
| thread::sleep(Duration::from_millis(500)); | ||
| } else { | ||
| // Not ready yet | ||
| thread::sleep(Duration::from_millis(500)); | ||
| // Parse JSON and inspect the numeric completion field. | ||
| match serde_json::from_str::<serde_json::Value>(&resp) { | ||
| Ok(json_val) => { | ||
| // if sync is complete, stop waiting | ||
| if let Some(true) = | ||
| json_val.get("sync_complete").and_then(|v| v.as_bool()) | ||
| { | ||
| break; | ||
| } | ||
|
|
||
| // Not complete yet; wait a short interval before re-checking. | ||
| thread::sleep(Duration::from_millis(500)); | ||
| continue; | ||
| } | ||
| Err(_) => { | ||
| // Parse error | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| Err(_) => break, | ||
| Err(_) => { | ||
| // Channel closed; stop waiting. | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment below