Kaynağa Gözat

added crypsinous sim

mohab metwally 4 yıl önce
ebeveyn
işleme
2b37f8316f

+ 17 - 0
Cargo.lock

@@ -1019,6 +1019,17 @@ version = "0.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
 
+[[package]]
+name = "crypsinous"
+version = "0.1.0"
+dependencies = [
+ "async-std",
+ "darkfi",
+ "futures",
+ "thread",
+ "url",
+]
+
 [[package]]
 name = "crypto-common"
 version = "0.1.3"
@@ -4110,6 +4121,12 @@ dependencies = [
  "syn",
 ]
 
+[[package]]
+name = "thread"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "afe9c0e959dd1e7b871071b51bc674380d1889cd4fed9f4b3b1f5c1772d9f796"
+
 [[package]]
 name = "time"
 version = "0.1.44"

+ 1 - 1
Cargo.toml

@@ -31,7 +31,7 @@ members = [
 	"bin/tau/taud",
 	"bin/tau/tau-cli",
 	"bin/vanityaddr",
-
+        "bin/crypsinous",
 	"src/sdk",
 	"src/util/derive",
 	"src/util/derive-internal",

+ 15 - 0
bin/crypsinous/Cargo.toml

@@ -0,0 +1,15 @@
+[package]
+name = "crypsinous"
+version = "0.1.0"
+description = "crypsinous blockchain simulation"
+authors = ["mohab-metwally@riseup.net"]
+license = "AGPL-3.0-only"
+edition = "2021"
+
+[dependencies]
+async-std = {version = "1.11.0", features = ["attributes"]}
+darkfi = {path = "../../", features = ["node", "tx"]}
+url = "2.2.2"
+thread = "0.1.0"
+futures = "0.3.21"
+#url = {version = "2.2.2", features = ["serde"], optional = true}

+ 11 - 9
bin/crypsinous/src/main.rs

@@ -1,9 +1,11 @@
-use darkfi::{
+use  ::darkfi::{
     stakeholder::Stakeholder,
     blockchain::{EpochConsensus,},
     net::{Settings,},
 };
 
+use futures::executor::block_on;
+use url::Url;
 use std::thread;
 
 fn main()
@@ -12,11 +14,11 @@ fn main()
     let epochs=3;
     let ticks=22;
     let reward=1;
-    let epoch_consensus = EpochConsensus::new(Some(slots), Some(epochs), Some(ticks), reward);
+    let epoch_consensus = EpochConsensus::new(Some(slots), Some(epochs), Some(ticks), Some(reward));
     /// read n from the cmd
     let n = 3;
     /// initialize n stakeholders
-    let stakeholders = vec!(n);
+    //let mut stakeholders = vec!();
     let settings = Settings{
         inbound: Some(Url::parse("tls://127.0.0.1:12002").unwrap()),
         outbound_connections: 4,
@@ -32,13 +34,13 @@ fn main()
         ].to_vec(),
     };
     let k : u32 = 13; //proof's number of rows
-    let handles = vec!(0);
-    for i in n {
-        let stakeholder = Stakeholder::new(epoch_consensus, settings, Some(k));
-        stakeholders.push(stakeholder);
-        let handle = thread.spawn(|| {
-            stakeholders.background();
+    let mut handles = vec!();
+    for i in 0..n {
+        let mut stakeholder = block_on(Stakeholder::new(epoch_consensus.clone(), settings.clone(), Some(k))).unwrap();
+        let handle = thread::spawn(move || {
+            block_on(stakeholder.background());
         });
+        //stakeholders.push(stakeholder);
         handles.push(handle);
     }
     for handle in handles {

+ 3 - 1
src/stakeholder/stakeholder.rs

@@ -117,8 +117,10 @@ impl Stakeholder
 {
     pub async fn new(consensus: EpochConsensus, settings: Settings, k: Option<u32>) -> Result<Self>
     {
-        let path = "/tmp";
+        let path = "tmp";
+        println!("opening db");
         let db = sled::open(path).unwrap();
+        println!("opened db");
         let ts = Timestamp::current_time();
         let genesis_hash = blake3::hash(b"");
         //TODO lisen and add transactions