Explorar o código

[crypsinous:stakeholder/stakeholder] add hardlimit to background for testing

mohab metwally %!s(int64=3) %!d(string=hai) anos
pai
achega
18231e8ba5
Modificáronse 2 ficheiros con 12 adicións e 5 borrados
  1. 5 4
      example/crypsinous.rs
  2. 7 1
      src/stakeholder/stakeholder.rs

+ 5 - 4
example/crypsinous.rs

@@ -16,9 +16,9 @@ async fn main()
     let ticks=10;
     let reward=1;
     let epoch_consensus = EpochConsensus::new(Some(slots), Some(epochs), Some(ticks), Some(reward));
-    /// read n from the cmd
+    // read n from the cmd
     let n = 3;
-    /// initialize n stakeholders
+    // initialize n stakeholders
     let alice_settings = Settings {
         inbound: vec!(Url::parse("tls://127.0.0.1:12002").unwrap()),
         outbound_connections: 4,
@@ -49,7 +49,8 @@ async fn main()
         ].to_vec(),
         ..Default::default()
     };
-    let k : u32 = 13; //proof's number of rows
+    //proof's number of rows
+    let k : u32 = 13;
     let mut handles = vec!();
     let path = "/tmp/db";
     for i in 0..2 {
@@ -68,7 +69,7 @@ async fn main()
         ).unwrap();
 
         let handle = thread::spawn(move || {
-            block_on(stakeholder.background());
+            block_on(stakeholder.background(Some(10)));
         });
         handles.push(handle);
     }

+ 7 - 1
src/stakeholder/stakeholder.rs

@@ -305,9 +305,14 @@ impl Stakeholder
         }
     }
 
-    pub async fn background(&mut self) {
+    pub async fn background(&mut self, hardlimit: Option<u8>) {
         self.clock.sync().await;
+        let mut c : u8= 0;
+        let lim : u8 = hardlimit.unwrap_or(0);
         while self.playing {
+            if c>lim && lim>0 {
+                break;
+            }
             // clock ticks slot begins
             // initialize the epoch if it's the time
             // check for leadership
@@ -351,6 +356,7 @@ impl Stakeholder
                 }
             }
             thread::sleep(Duration::from_millis(1000));
+            c+=1;
         }
     }