From 191278f0d92418639867aaa13b437945d4162b6b Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 17 May 2024 20:22:34 +0200 Subject: [PATCH] cli: Use current local tip in `rad sync status` In the case of an out-of-sync local node, we were showing the wrong tip. Additionally, mark your tip as unannounced if it isn't announced. This isn't fool-proof, but can be useful to debug certain issues. --- radicle-cli/examples/rad-sync.md | 5 +++-- radicle-cli/src/commands/sync.rs | 26 +++++++++++++++++++------- radicle-node/src/service.rs | 7 +++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/radicle-cli/examples/rad-sync.md b/radicle-cli/examples/rad-sync.md index af3fc925..b1540f86 100644 --- a/radicle-cli/examples/rad-sync.md +++ b/radicle-cli/examples/rad-sync.md @@ -7,14 +7,15 @@ For instance let's create an issue and sync it with the network: $ rad issue open --title "Test `rad sync`" --description "Check that the command works" -q --no-announce ``` -If we check the sync status, we see that our peers are out of sync. +If we check the sync status, we see that our peers are out of sync, and our +change has not yet been announced. ``` $ rad sync status --sort-by alias ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ ● Node Address Status Tip Timestamp │ ├──────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● alice (you) alice.radicle.example:8776 f209c9f [ ... ] │ +│ ● alice (you) alice.radicle.example:8776 unannounced a9ce0d1 [ ... ] │ │ ● bob z6Mkt67…v4N1tRk bob.radicle.example:8776 out-of-sync f209c9f [ ... ] │ │ ● eve z6Mkux1…nVhib7Z eve.radicle.example:8776 out-of-sync f209c9f [ ... ] │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ diff --git a/radicle-cli/src/commands/sync.rs b/radicle-cli/src/commands/sync.rs index 2b3de7ba..37fa76f8 100644 --- a/radicle-cli/src/commands/sync.rs +++ b/radicle-cli/src/commands/sync.rs @@ -317,7 +317,7 @@ fn sync_status( ) -> anyhow::Result<()> { let mut table = Table::<7, term::Label>::new(TableOptions::bordered()); let mut seeds: Vec<_> = node.seeds(rid)?.into(); - let local = node.nid()?; + let local_nid = node.nid()?; let aliases = profile.aliases(); table.push([ @@ -331,20 +331,32 @@ fn sync_status( ]); table.divider(); - sort_seeds_by(local, &mut seeds, &aliases, &options.sort_by); + sort_seeds_by(local_nid, &mut seeds, &aliases, &options.sort_by); for seed in seeds { let (icon, status, head, time) = match seed.sync { Some(SyncStatus::Synced { at }) => ( term::format::positive("●"), - term::format::positive(if seed.nid != local { "synced" } else { "" }), + term::format::positive(if seed.nid != local_nid { "synced" } else { "" }), term::format::oid(at.oid), term::format::timestamp(at.timestamp), ), - Some(SyncStatus::OutOfSync { remote, .. }) => ( - term::format::negative("●"), - term::format::negative(if seed.nid != local { "out-of-sync" } else { "" }), - term::format::oid(remote.oid), + Some(SyncStatus::OutOfSync { remote, local, .. }) => ( + if seed.nid != local_nid { + term::format::negative("●") + } else { + term::format::yellow("●") + }, + if seed.nid != local_nid { + term::format::negative("out-of-sync") + } else { + term::format::yellow("unannounced") + }, + term::format::oid(if seed.nid != local_nid { + remote.oid + } else { + local.oid + }), term::format::timestamp(remote.timestamp), ), None if options.verbose => ( diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index 8dbbaf0b..eccf405a 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -641,7 +641,6 @@ where let Some(updated_at) = repo.synced_at else { continue; }; - // Skip this repo if the sync status matches what we have in storage. if let Some(announced) = announced.get(&rid) { if updated_at.oid == announced.oid { @@ -657,7 +656,6 @@ where )? { debug!(target: "service", "Saved local sync status for {rid}.."); } - // If we got here, it likely means a repo was updated while the node was stopped. // Therefore, we pre-load a refs announcement for this repo, so that it is included in // the historical gossip messages when a node connects and subscribes to this repo. @@ -1989,20 +1987,21 @@ where // Update our sync status for our own refs. This is useful for determining if refs were // updated while the node was stopped. - // TODO: Move to `announce_own_refs`. if let Some(refs) = refs.iter().find(|r| r.remote == ann.node) { info!( target: "service", "Announcing own refs for {rid} to peers ({}) (t={timestamp})..", refs.at ); - + // Update our local node's sync status to mark the refs as announced. if let Err(e) = self .db .seeds_mut() .synced(&rid, &ann.node, refs.at, timestamp) { error!(target: "service", "Error updating sync status for local node: {e}"); + } else { + debug!(target: "service", "Saved local sync status for {rid}.."); } }