skoupidi 3 месяцев назад
Родитель
Сommit
9074aef176

+ 2 - 8
bin/darkfid/src/lib.rs

@@ -142,14 +142,8 @@ impl Darkfid {
 
         // Grab blockchain network configured transactions batch size for garbage collection
         let txs_batch_size = match txs_batch_size {
-            Some(b) => {
-                if *b > 0 {
-                    *b
-                } else {
-                    50
-                }
-            }
-            None => 50,
+            Some(b) if *b > 0 => *b,
+            _ => 50,
         };
 
         // Here we initialize various subscribers that can export live blockchain/consensus data.

+ 1 - 1
bin/darkirc/src/irc/server.rs

@@ -178,7 +178,7 @@ impl IrcServer {
         // Construct SMT from static DAG
         let mut identity_tree = darkirc.event_graph.rln_identity_tree.write().await;
         let mut events = darkirc.event_graph.static_fetch_all().await?;
-        events.sort_by(|a, b| a.header.timestamp.cmp(&b.header.timestamp));
+        events.sort_by_key(|a| a.header.timestamp);
 
         for event in events.iter() {
             // info!("event: {}", event.id());

+ 2 - 3
src/blockchain/tx_store.rs

@@ -162,7 +162,7 @@ impl TxStore {
     pub fn insert_batch_pending_order(&self, tx_hashes: &[TransactionHash]) -> Result<sled::Batch> {
         let mut batch = sled::Batch::default();
 
-        let mut next_index = match self.pending_order.last()? {
+        let next_index = match self.pending_order.last()? {
             Some(n) => {
                 let prev_bytes: [u8; 8] = n.0.as_ref().try_into().unwrap();
                 let prev = u64::from_be_bytes(prev_bytes);
@@ -171,9 +171,8 @@ impl TxStore {
             None => 0,
         };
 
-        for tx_hash in tx_hashes {
+        for (next_index, tx_hash) in (next_index..).zip(tx_hashes.iter()) {
             batch.insert(&next_index.to_be_bytes(), tx_hash.inner());
-            next_index += 1;
         }
 
         Ok(batch)

+ 5 - 5
src/event_graph/mod.rs

@@ -631,7 +631,7 @@ impl EventGraph {
                     header_sorted.push(val);
                 }
             }
-            header_sorted.sort_by(|x, y| x.layer.cmp(&y.layer));
+            header_sorted.sort_by_key(|x| x.layer);
 
             info!(target: "event_graph::dag_sync", "[EVENTGRAPH] Retrieving {} Events", header_sorted.len());
             // Implement parallel download of events with a batch size
@@ -945,7 +945,7 @@ impl EventGraph {
         let mut overlay = SledTreeOverlay::new(&header_dag);
 
         let mut hdrs = headers;
-        hdrs.sort_by(|x, y| x.layer.cmp(&y.layer));
+        hdrs.sort_by_key(|x| x.layer);
 
         // Iterate over given events to validate them and
         // write them to the overlay
@@ -1127,7 +1127,7 @@ impl EventGraph {
 
         let mut ord_events_vec = ordered_events.make_contiguous().to_vec();
         // Order events by timestamp.
-        ord_events_vec.sort_unstable_by(|a, b| a.1.header.timestamp.cmp(&b.1.header.timestamp));
+        ord_events_vec.sort_unstable_by_key(|a| a.1.header.timestamp);
 
         ord_events_vec.iter().map(|a| a.1.clone()).collect::<Vec<Event>>()
     }
@@ -1248,7 +1248,7 @@ impl EventGraph {
             }
         }
 
-        result.sort_unstable_by(|a, b| a.layer.cmp(&b.layer));
+        result.sort_unstable_by_key(|a| a.layer);
 
         Ok(result)
     }
@@ -1311,7 +1311,7 @@ impl EventGraph {
             }
         }
 
-        result.sort_by(|a, b| a.header.layer.cmp(&b.header.layer));
+        result.sort_by_key(|a| a.header.layer);
 
         Ok(result)
     }

+ 4 - 4
src/event_graph/rln.rs

@@ -280,7 +280,7 @@ pub fn sss_recover(shares: &[(pallas::Base, pallas::Base)]) -> pallas::Base {
 }
 
 /// Helper function to read or build register verifying key
-pub(super) fn build_register_vk(sled_db: &sled::Db) -> Result<()> {
+pub(super) fn _build_register_vk(sled_db: &sled::Db) -> Result<()> {
     // sanity check
     if sled_db.get("rlnv2-diff-register-vk")?.is_some() {
         return Ok(())
@@ -311,7 +311,7 @@ pub(super) fn read_register_vk(sled_db: &sled::Db) -> Result<VerifyingKey> {
 }
 
 /// Helper function to build signal verifying key
-pub(super) fn build_signal_vk(sled_db: &sled::Db) -> Result<()> {
+pub(super) fn _build_signal_vk(sled_db: &sled::Db) -> Result<()> {
     // sanity check
     if sled_db.get("rlnv2-diff-signal-vk")?.is_some() {
         return Ok(())
@@ -342,7 +342,7 @@ pub(super) fn read_signal_vk(sled_db: &sled::Db) -> Result<VerifyingKey> {
 }
 
 /// Helper function to build slash proving key
-pub(super) fn build_slash_pk(sled_db: &sled::Db) -> Result<()> {
+pub(super) fn _build_slash_pk(sled_db: &sled::Db) -> Result<()> {
     // sanity check
     if sled_db.get("rlnv2-diff-slash-pk")?.is_some() {
         return Ok(())
@@ -372,7 +372,7 @@ pub(super) fn read_slash_pk(sled_db: &sled::Db) -> Result<ProvingKey> {
 }
 
 /// Helper function to build slash verifying key
-pub(super) fn build_slash_vk(sled_db: &sled::Db) -> Result<()> {
+pub(super) fn _build_slash_vk(sled_db: &sled::Db) -> Result<()> {
     // sanity check
     if sled_db.get("rlnv2-diff-slash-vk")?.is_some() {
         return Ok(())

+ 16 - 12
src/event_graph/util.rs

@@ -116,21 +116,25 @@ pub fn millis_until_next_rotation(next_rotation: u64) -> u64 {
 
 /// Generate a deterministic genesis event corresponding to the DAG's configuration.
 pub fn generate_genesis(hours_rotation: u64) -> Event {
+    let parents = [NULL_ID; N_EVENT_PARENTS];
+    let layer = 0;
+    let content = GENESIS_CONTENTS.to_vec();
+
     // Hours rotation is u64 except zero
-    let timestamp = if hours_rotation == 0 {
-        INITIAL_GENESIS
-    } else {
-        // First check how many hours passed since initial genesis.
-        let hours_passed = hours_since(INITIAL_GENESIS);
+    if hours_rotation == 0 {
+        return Event { header: Header { timestamp: INITIAL_GENESIS, parents, layer }, content }
+    }
 
-        // Calculate the number of hours_rotation intervals since INITIAL_GENESIS
-        let rotations_since_genesis = hours_passed / hours_rotation;
+    // First check how many hours passed since initial genesis.
+    let hours_passed = hours_since(INITIAL_GENESIS);
 
-        // Calculate the timestamp of the most recent event
-        INITIAL_GENESIS + (rotations_since_genesis * hours_rotation * HOUR as u64)
-    };
-    let header = Header { timestamp, parents: [NULL_ID; N_EVENT_PARENTS], layer: 0 };
-    Event { header, content: GENESIS_CONTENTS.to_vec() }
+    // Calculate the number of hours_rotation intervals since INITIAL_GENESIS
+    let rotations_since_genesis = hours_passed / hours_rotation;
+
+    // Calculate the timestamp of the most recent event
+    let timestamp = INITIAL_GENESIS + (rotations_since_genesis * hours_rotation * HOUR as u64);
+
+    Event { header: Header { timestamp, parents, layer }, content }
 }
 
 pub(super) fn replayer_log(datastore: &Path, cmd: String, value: Vec<u8>) -> Result<()> {

+ 3 - 4
src/sdk/src/monotree/utils.rs

@@ -87,14 +87,13 @@ where
     T: Clone + cmp::Ord,
 {
     let mut t: Vec<_> = slice.iter().enumerate().collect();
+    t.sort_unstable_by_key(|(_, a)| *a);
 
     if reverse {
-        t.sort_unstable_by(|(_, a), (_, b)| b.cmp(a));
+        t.iter().rev().map(|(i, _)| *i).collect()
     } else {
-        t.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));
+        t.iter().map(|(i, _)| *i).collect()
     }
-
-    t.iter().map(|(i, _)| *i).collect()
 }
 
 /// Get length of the longest common prefix bits for the given two slices.

+ 5 - 10
src/validator/consensus.rs

@@ -164,18 +164,13 @@ impl Consensus {
         // If a fork index was found, replace fork with the mutated
         // one, otherwise try to push the new fork.
         match index {
-            Some(i) => {
+            Some(i)
                 if i < self.forks.len() &&
-                    self.forks[i].proposals == fork.proposals[..fork.proposals.len() - 1]
-                {
-                    self.forks[i] = fork;
-                } else {
-                    self.push_fork(fork);
-                }
-            }
-            None => {
-                self.push_fork(fork);
+                    self.forks[i].proposals == fork.proposals[..fork.proposals.len() - 1] =>
+            {
+                self.forks[i] = fork
             }
+            _ => self.push_fork(fork),
         }
 
         info!(target: "validator::consensus::append_proposal", "Appended proposal {} - {}", proposal.hash, proposal.block.header.height);

+ 1 - 1
src/zk/gadget/smt.rs

@@ -132,7 +132,7 @@ impl PathChip {
 
                 let mut witness_bits = vec![];
                 let mut witness_path = vec![];
-                for (i, (bit, sibling)) in bits.into_iter().zip(path.into_iter()).enumerate() {
+                for (i, (bit, sibling)) in bits.into_iter().zip(path).enumerate() {
                     let bit = region.assign_advice(
                         || "witness pos bit",
                         self.config.advices[0],