Преглед на файлове

WIP:script/research/nodes-tool: dummy tool to extract validatord state from sled to a json like file

aggstam преди 4 години
родител
ревизия
ab7eb937ad
променени са 3 файла, в които са добавени 37 реда и са изтрити 0 реда
  1. 3 0
      script/research/nodes-tool/.gitignore
  2. 14 0
      script/research/nodes-tool/Cargo.toml
  3. 20 0
      script/research/nodes-tool/src/main.rs

+ 3 - 0
script/research/nodes-tool/.gitignore

@@ -0,0 +1,3 @@
+/target
+Cargo.lock
+validatord_state_*

+ 14 - 0
script/research/nodes-tool/Cargo.toml

@@ -0,0 +1,14 @@
+[package]
+name = "nodes-tool"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies.darkfi]
+path = "../../../"
+features = ["blockchain"]
+
+[dependencies]
+
+sled = "0.34.7"
+
+[workspace]

+ 20 - 0
script/research/nodes-tool/src/main.rs

@@ -0,0 +1,20 @@
+use std::{fs::File, io::Write};
+
+use darkfi::{consensus::state::State, util::expand_path, Result};
+
+fn main() -> Result<()> {
+    let genesis = 1648383795;
+    for i in 0..4 {
+        let path = format!("~/.config/darkfi/validatord_db_{:?}", i);
+        let database_path = expand_path(&path).unwrap();
+        println!("Export state from sled database: {:?}", database_path);
+        let database = sled::open(database_path).unwrap();
+        let state = State::load_current_state(genesis, i, &database).unwrap();
+        let state_string = format!("{:#?}", state.read().unwrap());
+        let path = format!("validatord_state_{:?}", i);
+        let mut file = File::create(path)?;
+        file.write(state_string.as_bytes())?;
+    }
+
+    Ok(())
+}