Skip to content

Commit

Permalink
Merge #1276
Browse files Browse the repository at this point in the history
1276: chore(misc): remove unused asyncs (clippy) r=joshuef a=b-zee

Upon removing async keywords from
sn_interface/src/network_knowledge/mod.rs a lot of removal propagated up
and removed most of it with help of Clippy. Clippy does not yet detect
unnecessary async in methods
(rust-lang/rust-clippy#9024), but will soon.

With the help of a new Clippy lint:
cargo clippy --all-targets --all-features -- -W clippy::unused_async
And automatically fixing code with:
cargo fix --broken-code --allow-dirty --all-targets --all-features

Results mostly from the single thread work of `@joshuef` in #1253 (and
ongoing efforts).

<!--
Thanks for contributing to the project! We recommend you check out our "Guide to contributing" page if you haven't already: https://github.com/maidsafe/QA/blob/master/CONTRIBUTING.md

Write your comment below this line: -->


Co-authored-by: Benno Zeeman <bzeeman@live.nl>
  • Loading branch information
bors[bot] and b-zee authored Jun 27, 2022
2 parents 6cfed7b + 51e3249 commit a73aa40
Show file tree
Hide file tree
Showing 37 changed files with 249 additions and 362 deletions.
4 changes: 2 additions & 2 deletions sn_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ pub async fn run() -> Result<()> {
let mut launcher = Box::new(SnLaunchToolNetworkLauncher::default());
node_commander(cmd, &mut get_config().await?, &mut launcher).await
}
SubCommands::Keys(cmd) => key_commander(cmd, output_fmt, &get_config().await?).await,
SubCommands::Keys(cmd) => key_commander(cmd, output_fmt, &get_config().await?),
SubCommands::Xorurl {
cmd,
location,
recursive,
follow_links,
} => {
if let Some(cmd) = cmd {
xorurl_commander(cmd, output_fmt, safe.xorurl_base).await
xorurl_commander(cmd, output_fmt, safe.xorurl_base)
} else {
xorurl_of_files(
location,
Expand Down
9 changes: 4 additions & 5 deletions sn_cli/src/subcommands/files_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ async fn files_map_get_files(
Path::new(&denormalize_slashes(details.getattr("symlink_target")?)),
&abspath,
details.getattr("symlink_target_type")?,
)
.await?;
)?;
continue;
}

Expand Down Expand Up @@ -553,7 +552,7 @@ async fn files_map_get_files(
}

#[cfg(unix)]
async fn create_symlink_worker(
fn create_symlink_worker(
target: &Path,
link: &Path,
_target_type: &str,
Expand Down Expand Up @@ -590,14 +589,14 @@ async fn create_symlink_worker(
)
}

async fn create_symlink(target: &Path, link: &Path, target_type: &str) -> ApiResult<()> {
fn create_symlink(target: &Path, link: &Path, target_type: &str) -> ApiResult<()> {
info!(
"creating symlink: {} --> {}",
link.display(),
target.display()
);

let result = create_symlink_worker(target, link, target_type).await;
let result = create_symlink_worker(target, link, target_type);
match result {
Ok(_) => {}
Err((msg, os_err)) => {
Expand Down
12 changes: 3 additions & 9 deletions sn_cli/src/subcommands/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ pub enum KeysSubCommands {
},
}

pub async fn key_commander(
cmd: KeysSubCommands,
output_fmt: OutputFmt,
config: &Config,
) -> Result<()> {
pub fn key_commander(cmd: KeysSubCommands, output_fmt: OutputFmt, config: &Config) -> Result<()> {
match cmd {
KeysSubCommands::Show { show_sk } => {
match read_credentials(config)? {
Expand Down Expand Up @@ -110,8 +106,7 @@ mod create_command {
KeysSubCommands::Create { for_cli: false },
OutputFmt::Pretty,
&config,
)
.await;
);

assert!(result.is_ok());
credentials_file.assert(predicate::path::missing());
Expand All @@ -134,8 +129,7 @@ mod create_command {
KeysSubCommands::Create { for_cli: true },
OutputFmt::Pretty,
&config,
)
.await;
);

assert!(result.is_ok());
credentials_file.assert(predicate::path::is_file());
Expand Down
2 changes: 1 addition & 1 deletion sn_cli/src/subcommands/xorurl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum XorurlSubCommands {
},
}

pub async fn xorurl_commander(
pub fn xorurl_commander(
cmd: XorurlSubCommands,
output_fmt: OutputFmt,
xorurl_base: XorUrlBase,
Expand Down
3 changes: 1 addition & 2 deletions sn_client/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ mod tests {
init_logger();
let dbc_owner = get_dbc_owner_from_secret_key_hex(
"81ebce8339cb2a6e5cbf8b748215ba928acff7f92557b3acfb09a5b25e920d20",
)
.await?;
)?;

let client = create_test_client_with(None, Some(dbc_owner.clone()), None, true).await?;
assert_eq!(dbc_owner, client.dbc_owner());
Expand Down
2 changes: 1 addition & 1 deletion sn_client/src/utils/test_utils/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub async fn create_test_client_with(
/// then be used as the basis for an `Owner`.
///
/// The conversion method was copied from the `mint-repl` example in `sn_dbc`.
pub async fn get_dbc_owner_from_secret_key_hex(secret_key_hex: &str) -> Result<Owner> {
pub fn get_dbc_owner_from_secret_key_hex(secret_key_hex: &str) -> Result<Owner> {
let mut decoded_bytes = hex::decode(secret_key_hex).map_err(|e| eyre!(e))?;
decoded_bytes.reverse(); // convert from big endian to little endian
let sk: SecretKey = bincode::deserialize(&decoded_bytes).map_err(|e| eyre!(e))?;
Expand Down
53 changes: 25 additions & 28 deletions sn_interface/src/network_knowledge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl NetworkKnowledge {
*self.signed_sap.borrow_mut() = new_network_nowledge.signed_sap();

let _updated = self
.merge_members(new_network_nowledge.section_signed_members().await)
.merge_members(new_network_nowledge.section_signed_members())
.await?;

Ok(())
Expand Down Expand Up @@ -312,7 +312,7 @@ impl NetworkKnowledge {
.await;

// Let's then update our current SAP and section chain
let our_prev_prefix = self.prefix().await;
let our_prev_prefix = self.prefix();
*self.signed_sap.borrow_mut() = signed_sap.clone();
*self.chain.borrow_mut() = section_chain;

Expand Down Expand Up @@ -412,7 +412,7 @@ impl NetworkKnowledge {
let mut we_have_a_share_of_this_key = false;

// lets find out if we should be an elder after the change
let we_are_an_adult = !self.is_elder(our_name).await;
let we_are_an_adult = !self.is_elder(our_name);

// check we should not be _becoming_ an elder
let we_should_become_an_elder = if we_are_an_adult {
Expand Down Expand Up @@ -454,7 +454,7 @@ impl NetworkKnowledge {
// the key share for the new SAP, making this node unable to sign section messages
// and possibly being kicked out of the group of Elders.
if switch_to_new_sap && provided_sap.prefix().matches(our_name) {
let our_prev_prefix = self.prefix().await;
let our_prev_prefix = self.prefix();
// Remove any peer which doesn't belong to our new section's prefix
self.section_peers.retain(&provided_sap.prefix());
info!(
Expand Down Expand Up @@ -501,7 +501,7 @@ impl NetworkKnowledge {
.collect();

if self.merge_members(peers).await? {
let prefix = self.prefix().await;
let prefix = self.prefix();
info!(
"Updated our section's members ({:?}): {:?}",
prefix, self.section_peers
Expand Down Expand Up @@ -534,7 +534,7 @@ impl NetworkKnowledge {
) -> Option<(SectionAuth<SectionAuthorityProvider>, SecuredLinkedList)> {
let closest_sap = self
.prefix_map
.closest_or_opposite(name, Some(&self.prefix().await));
.closest_or_opposite(name, Some(&self.prefix()));

if let Some(signed_sap) = closest_sap {
if let Ok(proof_chain) = self
Expand Down Expand Up @@ -576,7 +576,7 @@ impl NetworkKnowledge {
}
}

self.section_peers.retain(&self.prefix().await);
self.section_peers.retain(&self.prefix());

Ok(there_was_an_update)
}
Expand Down Expand Up @@ -631,48 +631,48 @@ impl NetworkKnowledge {
}

/// Return current section key
pub async fn section_key(&self) -> bls::PublicKey {
pub fn section_key(&self) -> bls::PublicKey {
self.signed_sap.borrow().section_key()
}

/// Return current section chain length
pub async fn chain_len(&self) -> u64 {
pub fn chain_len(&self) -> u64 {
self.chain.borrow().main_branch_len() as u64
}

/// Return weather current section chain has the provided key
pub async fn has_chain_key(&self, key: &bls::PublicKey) -> bool {
pub fn has_chain_key(&self, key: &bls::PublicKey) -> bool {
self.chain.borrow().has_key(key)
}

/// Return a copy of current SAP
pub async fn authority_provider(&self) -> SectionAuthorityProvider {
pub fn authority_provider(&self) -> SectionAuthorityProvider {
self.signed_sap.borrow().value.clone()
}

/// Return a copy of current SAP with corresponding section authority
pub async fn section_signed_authority_provider(&self) -> SectionAuth<SectionAuthorityProvider> {
pub fn section_signed_authority_provider(&self) -> SectionAuth<SectionAuthorityProvider> {
self.signed_sap.borrow().clone()
}

/// Prefix of our section.
pub async fn prefix(&self) -> Prefix {
pub fn prefix(&self) -> Prefix {
self.signed_sap.borrow().prefix()
}

/// Returns the elders of our section
pub async fn elders(&self) -> Vec<Peer> {
self.authority_provider().await.elders_vec()
pub fn elders(&self) -> Vec<Peer> {
self.authority_provider().elders_vec()
}

/// Return whether the name provided belongs to an Elder, by checking if
/// it is one of the current section's SAP member,
pub async fn is_elder(&self, name: &XorName) -> bool {
pub fn is_elder(&self, name: &XorName) -> bool {
self.signed_sap.borrow().contains_elder(name)
}

/// Returns members that are joined.
pub async fn section_members(&self) -> BTreeSet<NodeState> {
pub fn section_members(&self) -> BTreeSet<NodeState> {
self.section_peers
.members()
.into_iter()
Expand All @@ -681,46 +681,43 @@ impl NetworkKnowledge {
}

/// Returns current list of section signed members.
pub async fn section_signed_members(&self) -> BTreeSet<SectionAuth<NodeState>> {
pub fn section_signed_members(&self) -> BTreeSet<SectionAuth<NodeState>> {
self.section_peers.members()
}

/// Returns current section size, i.e. number of peers in the section.
pub async fn section_size(&self) -> usize {
pub fn section_size(&self) -> usize {
self.section_peers.num_of_members()
}

/// Returns live adults from our section.
pub async fn adults(&self) -> Vec<Peer> {
pub fn adults(&self) -> Vec<Peer> {
let mut live_adults = vec![];
for node_state in self.section_peers.members() {
if !self.is_elder(&node_state.name()).await {
if !self.is_elder(&node_state.name()) {
live_adults.push(*node_state.peer())
}
}
live_adults
}

/// Get info for the member with the given name.
pub async fn get_section_member(&self, name: &XorName) -> Option<NodeState> {
pub fn get_section_member(&self, name: &XorName) -> Option<NodeState> {
self.section_peers.get(name)
}

/// Get info for the member with the given name either from current members list,
/// or from the archive of left/relocated members
pub async fn is_either_member_or_archived(
&self,
name: &XorName,
) -> Option<SectionAuth<NodeState>> {
pub fn is_either_member_or_archived(&self, name: &XorName) -> Option<SectionAuth<NodeState>> {
self.section_peers.is_either_member_or_archived(name)
}

/// Get info for the member with the given name.
pub async fn is_section_member(&self, name: &XorName) -> bool {
pub fn is_section_member(&self, name: &XorName) -> bool {
self.section_peers.is_member(name)
}

pub async fn find_member_by_addr(&self, addr: &SocketAddr) -> Option<Peer> {
pub fn find_member_by_addr(&self, addr: &SocketAddr) -> Option<Peer> {
self.section_peers
.members()
.into_iter()
Expand Down
9 changes: 2 additions & 7 deletions sn_node/src/node/api/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Dispatcher {
Ok(vec![])
}
Cmd::SignOutgoingSystemMsg { msg, dst } => {
let src_section_pk = self.node.network_knowledge().section_key().await;
let src_section_pk = self.node.network_knowledge().section_key();
let wire_msg =
WireMsg::single_src(&*self.node.info.read().await, dst, msg, src_section_pk)?;

Expand Down Expand Up @@ -154,12 +154,7 @@ impl Dispatcher {
.await?,
]),
Cmd::TestConnectivity(name) => {
if let Some(member_info) = self
.node
.network_knowledge()
.get_section_member(&name)
.await
{
if let Some(member_info) = self.node.network_knowledge().get_section_member(&name) {
if self
.node
.comm
Expand Down
10 changes: 5 additions & 5 deletions sn_node/src/node/api/flow_ctrl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl FlowCtrl {

// Send a probe message if we are an elder
let node = &self.node;
if node.is_elder().await && !node.network_knowledge().prefix().await.is_empty() {
if node.is_elder().await && !node.network_knowledge().prefix().is_empty() {
match node.generate_probe_msg().await {
Ok(cmd) => {
info!("Sending probe msg");
Expand All @@ -145,7 +145,7 @@ impl FlowCtrl {

// Send a probe message to an elder
let node = &self.node;
if !node.network_knowledge().prefix().await.is_empty() {
if !node.network_knowledge().prefix().is_empty() {
match node.generate_section_probe_msg().await {
Ok(cmd) => {
info!("Sending section probe msg");
Expand Down Expand Up @@ -230,7 +230,7 @@ impl FlowCtrl {
node.pending_data_to_replicate_to_peers.remove(&address)
{
// get info for the WireMsg
let src_section_pk = node.network_knowledge().section_key().await;
let src_section_pk = node.network_knowledge().section_key();
let our_info = &*node.info.read().await;

let mut recipients = vec![];
Expand Down Expand Up @@ -357,8 +357,8 @@ impl FlowCtrl {
let our_info = node.info.read().await;
let our_name = our_info.name();

let members = node.network_knowledge().section_members().await;
let section_pk = node.network_knowledge().section_key().await;
let members = node.network_knowledge().section_members();
let section_pk = node.network_knowledge().section_key();

if let Some(load_report) = node.comm.tolerated_msgs_per_s().await {
trace!("New BackPressure report to disseminate: {:?}", load_report);
Expand Down
12 changes: 6 additions & 6 deletions sn_node/src/node/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ impl NodeApi {
let network_knowledge = node.network_knowledge();

let elders = Elders {
prefix: network_knowledge.prefix().await,
key: network_knowledge.section_key().await,
prefix: network_knowledge.prefix(),
key: network_knowledge.section_key(),
remaining: BTreeSet::new(),
added: network_knowledge.authority_provider().await.names(),
added: network_knowledge.authority_provider().names(),
removed: BTreeSet::new(),
};

Expand Down Expand Up @@ -304,7 +304,7 @@ impl NodeApi {

/// Prefix of our section
pub async fn our_prefix(&self) -> Prefix {
self.node.network_knowledge().prefix().await
self.node.network_knowledge().prefix()
}

/// Returns whether the node is Elder.
Expand All @@ -314,12 +314,12 @@ impl NodeApi {

/// Returns the information of all the current section elders.
pub async fn our_elders(&self) -> Vec<Peer> {
self.node.network_knowledge().elders().await
self.node.network_knowledge().elders()
}

/// Returns the information of all the current section adults.
pub async fn our_adults(&self) -> Vec<Peer> {
self.node.network_knowledge().adults().await
self.node.network_knowledge().adults()
}

/// Returns the info about the section matching the name.
Expand Down
Loading

0 comments on commit a73aa40

Please sign in to comment.