Procházet zdrojové kódy

event_graph: chore clippy

skoupidi před 1 rokem
rodič
revize
941d7a0666
4 změnil soubory, kde provedl 44 přidání a 51 odebrání
  1. 20 24
      src/event_graph/mod.rs
  2. 15 15
      src/event_graph/proto.rs
  3. 8 11
      src/event_graph/tests.rs
  4. 1 1
      src/event_graph/util.rs

+ 20 - 24
src/event_graph/mod.rs

@@ -220,7 +220,7 @@ impl EventGraph {
         let mut communicated_peers = channels.len();
         info!(
             target: "event_graph::dag_sync()",
-            "[EVENTGRAPH] Syncing DAG from {} peers...", communicated_peers,
+            "[EVENTGRAPH] Syncing DAG from {communicated_peers} peers..."
         );
 
         // Here we keep track of the tips, their layers and how many time we've seen them.
@@ -236,8 +236,7 @@ impl EventGraph {
                 Err(e) => {
                     error!(
                         target: "event_graph::dag_sync()",
-                        "[EVENTGRAPH] Sync: Couldn't subscribe TipReq for peer {}, skipping ({})",
-                        url, e,
+                        "[EVENTGRAPH] Sync: Couldn't subscribe TipReq for peer {url}, skipping ({e})"
                     );
                     communicated_peers -= 1;
                     continue
@@ -247,7 +246,7 @@ impl EventGraph {
             if let Err(e) = channel.send(&TipReq {}).await {
                 error!(
                     target: "event_graph::dag_sync()",
-                    "[EVENTGRAPH] Sync: Couldn't contact peer {}, skipping ({})", url, e,
+                    "[EVENTGRAPH] Sync: Couldn't contact peer {url}, skipping ({e})"
                 );
                 communicated_peers -= 1;
                 continue
@@ -260,7 +259,7 @@ impl EventGraph {
             else {
                 error!(
                     target: "event_graph::dag_sync()",
-                    "[EVENTGRAPH] Sync: Peer {} didn't reply with tips in time, skipping", url,
+                    "[EVENTGRAPH] Sync: Peer {url} didn't reply with tips in time, skipping"
                 );
                 communicated_peers -= 1;
                 continue
@@ -329,7 +328,7 @@ impl EventGraph {
 
                 debug!(
                     target: "event_graph::dag_sync()",
-                    "Requesting {:?} from {}...", missing_parents, url,
+                    "Requesting {missing_parents:?} from {url}..."
                 );
 
                 let ev_rep_sub = match channel.subscribe_msg::<EventRep>().await {
@@ -337,8 +336,7 @@ impl EventGraph {
                     Err(e) => {
                         error!(
                             target: "event_graph::dag_sync()",
-                            "[EVENTGRAPH] Sync: Couldn't subscribe EventRep for peer {}, skipping ({})",
-                            url, e,
+                            "[EVENTGRAPH] Sync: Couldn't subscribe EventRep for peer {url}, skipping ({e})"
                         );
                         continue
                     }
@@ -348,8 +346,7 @@ impl EventGraph {
                 if let Err(e) = channel.send(&EventReq(request_missing_events)).await {
                     error!(
                         target: "event_graph::dag_sync()",
-                        "[EVENTGRAPH] Sync: Failed communicating EventReq({:?}) to {}: {}",
-                        missing_parents, url, e,
+                        "[EVENTGRAPH] Sync: Failed communicating EventReq({missing_parents:?}) to {url}: {e}"
                     );
                     continue
                 }
@@ -361,8 +358,7 @@ impl EventGraph {
                 else {
                     error!(
                         target: "event_graph::dag_sync()",
-                        "[EVENTGRAPH] Sync: Timeout waiting for parents {:?} from {}",
-                        missing_parents, url,
+                        "[EVENTGRAPH] Sync: Timeout waiting for parents {missing_parents:?} from {url}"
                     );
                     continue
                 };
@@ -374,15 +370,15 @@ impl EventGraph {
                     if !missing_parents.contains(&parent_id) {
                         error!(
                             target: "event_graph::dag_sync()",
-                            "[EVENTGRAPH] Sync: Peer {} replied with a wrong event: {}",
-                            url, parent.id(),
+                            "[EVENTGRAPH] Sync: Peer {url} replied with a wrong event: {}",
+                            parent.id()
                         );
                         continue
                     }
 
                     debug!(
                         target: "event_graph::dag_sync()",
-                        "Got correct parent event {}", parent_id,
+                        "Got correct parent event {parent_id}"
                     );
 
                     if let Some(layer_events) = received_events.get_mut(&parent.layer) {
@@ -408,7 +404,7 @@ impl EventGraph {
                         {
                             debug!(
                                 target: "event_graph::dag_sync()",
-                                "Found upper missing parent event {}", upper_parent,
+                                "Found upper missing parent event {upper_parent}"
                             );
                             missing_parents.insert(*upper_parent);
                         }
@@ -465,7 +461,7 @@ impl EventGraph {
 
         debug!(target: "event_graph::dag_prune()", "Applying batch...");
         if let Err(e) = self.dag.apply_batch(batch) {
-            panic!("Failed pruning DAG, sled apply_batch error: {}", e);
+            panic!("Failed pruning DAG, sled apply_batch error: {e}");
         }
 
         // Clear unreferenced tips and bcast ids
@@ -504,7 +500,7 @@ impl EventGraph {
             // Sleep until it's time to rotate.
             let s = millis_until_next_rotation(next_rotation);
 
-            debug!(target: "event_graph::dag_prune_task()", "Sleeping {}ms until next DAG prune", s);
+            debug!(target: "event_graph::dag_prune_task()", "Sleeping {s}ms until next DAG prune");
             msleep(s).await;
             debug!(target: "event_graph::dag_prune_task()", "Rotation period reached");
 
@@ -548,14 +544,14 @@ impl EventGraph {
             let event_id = event.id();
             debug!(
                 target: "event_graph::dag_insert()",
-                "Inserting event {} into the DAG", event_id,
+                "Inserting event {event_id} into the DAG"
             );
 
             if !event
                 .validate(&self.dag, genesis_timestamp, self.days_rotation, Some(&overlay))
                 .await?
             {
-                error!(target: "event_graph::dag_insert()", "Event {} is invalid!", event_id);
+                error!(target: "event_graph::dag_insert()", "Event {event_id} is invalid!");
                 return Err(Error::EventIsInvalid)
             }
 
@@ -577,7 +573,7 @@ impl EventGraph {
         // Atomically apply the batch.
         // Panic if something is corrupted.
         if let Err(e) = self.dag.apply_batch(batch) {
-            panic!("Failed applying dag_insert batch to sled: {}", e);
+            panic!("Failed applying dag_insert batch to sled: {e}");
         }
 
         // Iterate over given events to update references and
@@ -588,13 +584,13 @@ impl EventGraph {
             // Update the unreferenced DAG tips set
             debug!(
                 target: "event_graph::dag_insert()",
-                "Event {} parents {:#?}", event_id, event.parents,
+                "Event {event_id} parents {:#?}", event.parents,
             );
             for parent_id in event.parents.iter() {
                 if parent_id != &NULL_ID {
                     debug!(
                         target: "event_graph::dag_insert()",
-                        "Removing {} from unreferenced_tips", parent_id,
+                        "Removing {parent_id} from unreferenced_tips"
                     );
 
                     // Iterate over unreferenced tips in previous layers
@@ -614,7 +610,7 @@ impl EventGraph {
             unreferenced_tips.retain(|_, tips| !tips.is_empty());
             debug!(
                 target: "event_graph::dag_insert()",
-                "Adding {} to unreferenced tips", event_id,
+                "Adding {event_id} to unreferenced tips"
             );
 
             if let Some(layer_tips) = unreferenced_tips.get_mut(&event.layer) {

+ 15 - 15
src/event_graph/proto.rs

@@ -73,7 +73,7 @@ impl MovingWindow {
     fn clean(&mut self) {
         while let Some(ts) = self.times.front() {
             let Ok(elapsed) = ts.elapsed() else {
-                debug!(target: "event_graph::protocol::MovingWindow::clean()", "Timestamp [{}] is in future. Removing...", ts);
+                debug!(target: "event_graph::protocol::MovingWindow::clean()", "Timestamp [{ts}] is in future. Removing...");
                 let _ = self.times.pop_front();
                 continue
             };
@@ -247,7 +247,7 @@ impl ProtocolEventGraph {
             if self.event_graph.dag.contains_key(event_id.as_bytes()).unwrap() {
                 debug!(
                     target: "event_graph::protocol::handle_event_put()",
-                    "Event {} is already known", event_id,
+                    "Event {event_id} is already known"
                 );
                 continue
             }
@@ -277,8 +277,8 @@ impl ProtocolEventGraph {
             if event.timestamp < genesis_timestamp {
                 debug!(
                     target: "event_graph::protocol::handle_event_put()",
-                    "Event {} is older than genesis. Event timestamp: `{}`. Genesis timestamp: `{}`",
-                event.id(), event.timestamp, genesis_timestamp
+                    "Event {} is older than genesis. Event timestamp: `{}`. Genesis timestamp: `{genesis_timestamp}`",
+                event.id(), event.timestamp
                 );
             }
 
@@ -294,7 +294,7 @@ impl ProtocolEventGraph {
             // have all of its parents.
             debug!(
                 target: "event_graph::protocol::handle_event_put()",
-                "Event {} is new", event_id,
+                "Event {event_id} is new"
             );
 
             let mut missing_parents = HashSet::new();
@@ -331,7 +331,7 @@ impl ProtocolEventGraph {
                     // for parent_id in missing_parents.clone().iter() {
                     debug!(
                         target: "event_graph::protocol::handle_event_put()",
-                        "Requesting {:?}...", missing_parents,
+                        "Requesting {missing_parents:?}..."
                     );
 
                     self.channel
@@ -348,8 +348,8 @@ impl ProtocolEventGraph {
                     else {
                         error!(
                             target: "event_graph::protocol::handle_event_put()",
-                            "[EVENTGRAPH] Timeout while waiting for parents {:?} from {}",
-                            missing_parents, self.channel.address(),
+                            "[EVENTGRAPH] Timeout while waiting for parents {missing_parents:?} from {}",
+                            self.channel.address(),
                         );
                         self.channel.stop().await;
                         return Err(Error::ChannelStopped)
@@ -400,7 +400,7 @@ impl ProtocolEventGraph {
                             {
                                 debug!(
                                     target: "event_graph::protocol::handle_event_put()",
-                                    "Found upper missing parent event {}", upper_parent,
+                                    "Found upper missing parent event {upper_parent}"
                                 );
                                 missing_parents.insert(*upper_parent);
                             }
@@ -448,7 +448,7 @@ impl ProtocolEventGraph {
             };
             trace!(
                 target: "event_graph::protocol::handle_event_req()",
-                "Got EventReq: {:?} [{}]", event_ids, self.channel.address(),
+                "Got EventReq: {event_ids:?} [{}]", self.channel.address(),
             );
 
             // Check if node has finished syncing its DAG
@@ -487,8 +487,8 @@ impl ProtocolEventGraph {
 
                     warn!(
                         target: "event_graph::protocol::handle_event_req()",
-                        "[EVENTGRAPH] Peer {} requested an unexpected event {:?}",
-                        self.channel.address(), event_id,
+                        "[EVENTGRAPH] Peer {} requested an unexpected event {event_id:?}",
+                        self.channel.address()
                     );
                     continue
                 }
@@ -497,7 +497,7 @@ impl ProtocolEventGraph {
                 // This code panics if this is not the case.
                 debug!(
                     target: "event_graph::protocol::handle_event_req()",
-                    "Fetching event {:?} from DAG", event_id,
+                    "Fetching event {event_id:?} from DAG"
                 );
                 events.push(self.event_graph.dag_get(event_id).await.unwrap().unwrap());
             }
@@ -513,8 +513,8 @@ impl ProtocolEventGraph {
                     error!(
                         target: "event_graph::protocol::handle_event_req()",
                         "Requested event by peer {} is older than previous rotation period. It should have been pruned.
-                    Event timestamp: `{}`. Genesis timestamp: `{}`",
-                    event.id(), event.timestamp, genesis_timestamp
+                    Event timestamp: `{}`. Genesis timestamp: `{genesis_timestamp}`",
+                    event.id(), event.timestamp
                     );
                 }
 

+ 8 - 11
src/event_graph/tests.rs

@@ -130,7 +130,7 @@ async fn bootstrap_nodes(
         let mut peers = vec![];
         for peer_index in peer_indexes_to_connect {
             let port = starting_port + peer_index;
-            peers.push(Url::parse(&format!("tcp://127.0.0.1:{}", port)).unwrap());
+            peers.push(Url::parse(&format!("tcp://127.0.0.1:{port}")).unwrap());
         }
 
         let event_graph = spawn_node(
@@ -163,15 +163,12 @@ async fn assert_dags(eg_instances: &[Arc<EventGraph>], expected_len: usize, rng:
             eg.unreferenced_tips.read().await.last_key_value().unwrap().1.clone();
         assert!(
             eg.dag.len() == expected_len,
-            "Node {}, expected {} events, have {}",
-            i,
-            expected_len,
+            "Node {i}, expected {expected_len} events, have {}",
             eg.dag.len()
         );
         assert_eq!(
             node_last_layer_tips, last_layer_tips,
-            "Node {} contains malformed unreferenced tips",
-            i
+            "Node {i} contains malformed unreferenced tips"
         );
     }
 }
@@ -231,7 +228,7 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     assert_eq!(tips_layers.len(), 1);
     assert!(tips_layers.last_key_value().unwrap().1.get(&event_id).is_some());
     drop(tips_layers);
-    info!("Broadcasting event {}", event_id);
+    info!("Broadcasting event {event_id}");
     random_node.p2p.broadcast(&EventPut(event)).await;
     info!("Waiting 5s for event propagation");
     sleep(5).await;
@@ -263,8 +260,8 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
     let event_chain =
         vec![(event0_id, event0.parents), (event1_id, event1.parents), (event2_id, event2.parents)];
 
-    info!("Broadcasting event {}", event2_id);
-    info!("Event chain: {:#?}", event_chain);
+    info!("Broadcasting event {event2_id}");
+    info!("Event chain: {event_chain:#?}");
     random_node.p2p.broadcast(&EventPut(event2)).await;
     info!("Waiting 5s for event propagation");
     sleep(5).await;
@@ -344,7 +341,7 @@ async fn eventgraph_propagation_real(ex: Arc<Executor<'static>>) {
         let mut peers = vec![];
         for peer_index in peer_indexes_to_connect {
             let port = 13200 + peer_index;
-            peers.push(Url::parse(&format!("tcp://127.0.0.1:{}", port)).unwrap());
+            peers.push(Url::parse(&format!("tcp://127.0.0.1:{port}")).unwrap());
         }
 
         let event_graph = spawn_node(
@@ -422,7 +419,7 @@ async fn eventgraph_chaotic_propagation_real(ex: Arc<Executor<'static>>) {
         let mut peers = vec![];
         for peer_index in peer_indexes_to_connect {
             let port = 14200 + peer_index;
-            peers.push(Url::parse(&format!("tcp://127.0.0.1:{}", port)).unwrap());
+            peers.push(Url::parse(&format!("tcp://127.0.0.1:{port}")).unwrap());
         }
 
         let event_graph = spawn_node(

+ 1 - 1
src/event_graph/util.rs

@@ -143,7 +143,7 @@ pub(super) fn replayer_log(datastore: &Path, cmd: String, value: Vec<u8>) -> Res
     let mut file = OpenOptions::new().append(true).open(&datastore)?;
     let v = base64::encode(&value);
     let f = format!("{cmd} {v}");
-    writeln!(file, "{}", f)?;
+    writeln!(file, "{f}")?;
 
     Ok(())
 }