-
Notifications
You must be signed in to change notification settings - Fork 992
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
Add sync_status in status Node API #2966
Add sync_status in status Node API #2966
Conversation
I might implement a specific
|
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.
I think we should decouple the status itself from the value in the json completely.
Just have an explicit mapping of status -> api representation. Its more work now but I think it insulates us from breaking changes in the future.
Some sync statuses are purely internal and I think we want to be able to rework these without needing to care about clients of the api.
API clients only really care about syncing/synced or whatever we decide to call them.
api/src/handlers/server_api.rs
Outdated
} | ||
|
||
impl StatusHandler { | ||
fn get_status(&self) -> Result<Status, Error> { | ||
let head = w(&self.chain)? | ||
.head() | ||
.map_err(|e| ErrorKind::Internal(format!("can't get head: {}", e)))?; | ||
let sync_status = w(&self.sync_state)?.status(); | ||
let sync_status = match w(&self.sync_state)?.status() { | ||
SyncStatus::NoSync => "no_sync".to_owned(), |
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.
Might be worth getting some feedback around no_sync
to see if this makes sense to people.
Maybe it should just be running
or something as this is going to be the most common state people see (presumably).
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.
Yeah agree, to be fair the last commit was just that I wanted to save my work before testing the new master :). Will ask for feedback.
@@ -78,15 +78,22 @@ pub struct Status { | |||
pub connections: u32, | |||
// The state of the current fork Tip | |||
pub tip: Tip, | |||
// The current sync status | |||
pub sync_status: String, |
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.
If this is sync
vs synced
then maybe this is just status
and not sync_status
?
I'm not sure if we are exposing the actual "sync status" here or exposing a "status" that we are using our internal sync_status to derive from.
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.
The reason I'm being pedantic here is from the original issue raised about this.
"Expose the Basic Status > Current Status: Running
field in the Node API"
I'd argue nobody actually cares about the sync status itself - they just care about when the node is finally "running".
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.
Changed to status
with two possible status: syncing or running.
I'm thinking something like this:
I think it makes sense to make the |
What has frustrated me using the API is there is no way for me to determine how much has been synced. I think the status should reveal to the client the sync task, but in addition to that the current network height. That way the client knows that it X% of the blockchain has been processed. Currently there is no way to know this. Another area I would expect to see this is in the peer API. The listing of connected peers should be able to list that peers network height just like it does when you run the grin server TUI. |
The complexity here is Grin/MW is not a straightforward block-based sync. We don't start syncing from height 1 and then sync all blocks in increasing height. The sync process is something more like -
Given all this its not trivial to say we are 50% sync'd, for example. Note: The order and internal impl of these steps is also subject to change. We have some ideas around improving performance of the large "full state sync" middle step. So any assumptions about what constitutes say 75% sync'd may be subject to change over time. |
@nijynot @antiochp given the fact that API user wants to see the progress of header sync or txhashset download and have a "stable" structure to parse here is an idea: adding an additional field For example during
and no sync (the
Downside is that the sync_info is not a fixed struct but a variable struct which change during "txhashset_download" (for example). |
Not sure if this is the best way, but what I do in Grin++ is just have the status API always return header_height, block_height, network_height, state_process_status (percentage of txhashset processed), and sync_status (eg. no_sync, header_sync, waiting_for_peers, etc). That's granular enough for the front-end to calculate and display just about anything it needs, and there's no extra parsing based on what the sync_status is - the structure is always the same. |
@DavidBurkett this could do. Not a big fan of having a |
@quentinlesceller Yea, I struggled with it as well. Not quite as consistent and useful as the other fields, but it's a messy world we live in :) |
👍 on including both |
@antiochp I'm good with that, just want to point out that you can add to the sync_info, but you can't really add a new sync_status in a backward compatible way. |
api/src/handlers/server_api.rs
Outdated
@@ -83,3 +86,43 @@ impl Handler for StatusHandler { | |||
result_to_response(self.get_status()) | |||
} | |||
} | |||
|
|||
/// Convert a SyncStatus to correspond sync_status API string | |||
fn sync_status_to_api_string(sync_status: SyncStatus) -> String { |
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.
Does it make sense to implement Display
trait on SyncStatus
to make it more reusable?
Okay here is the latest version: Awaiting peers:
Header sync:
Txhashset download:
Txhashset validation:
Body sync:
No sync:
Only minor disadvantage that I see is that uint64 are serialised as number and not a string with can be problematic for javascript implementations. However with the current number (blocks, rproof, etc...) we should be fine. |
I've removed the internal state from the mapping. Ready for review. |
Fix #2946.
Looks like this:
Awaiting peers:
HeaderSync:
BodySync:
NoSync:
Not very pretty. Suggestions welcome.