فهرست منبع

darkirc: fix broken replay mode and datastore

dasman 2 سال پیش
والد
کامیت
94eac02ab8
3فایلهای تغییر یافته به همراه33 افزوده شده و 4 حذف شده
  1. 3 0
      bin/darkirc/darkirc_config.toml
  2. 29 3
      bin/darkirc/src/main.rs
  3. 1 1
      bin/darkirc/src/rpc.rs

+ 3 - 0
bin/darkirc/darkirc_config.toml

@@ -16,6 +16,9 @@
 ## Sets Datastore Path
 #datastore = "~/.local/darkfi/darkirc_db"
 
+## Sets DB logs replay datastore path
+#datastore = "~/.local/darkfi/replayed_darkirc_db"
+
 ## List of channels to autojoin for new client connections
 autojoin = [
     "#dev",

+ 29 - 3
bin/darkirc/src/main.rs

@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-use std::{collections::HashSet, sync::Arc};
+use std::{collections::HashSet, path::PathBuf, sync::Arc};
 
 use darkfi::{
     async_daemonize, cli_desc,
@@ -88,6 +88,10 @@ struct Args {
     /// Datastore (DB) path
     datastore: String,
 
+    #[structopt(short, long, default_value = "~/.local/darkfi/replayed_darkirc_db")]
+    /// Replay logs (DB) path
+    replay_datastore: String,
+
     /// Generate a new NaCl keypair and exit
     #[structopt(long)]
     gen_chacha_keypair: bool,
@@ -116,6 +120,10 @@ struct Args {
     #[structopt(long)]
     pub password: Option<String>,
 
+    /// replay_mode
+    #[structopt(long)]
+    replay_mode: bool,
+
     /// P2P network settings
     #[structopt(flatten)]
     net: SettingsOpt,
@@ -134,6 +142,8 @@ pub struct DarkIrc {
     dnet_sub: JsonSubscriber,
     /// deg JSON-RPC subscriber
     deg_sub: JsonSubscriber,
+    /// Replay logs (DB) path
+    replay_datastore: PathBuf,
 }
 
 impl DarkIrc {
@@ -143,6 +153,7 @@ impl DarkIrc {
         event_graph: EventGraphPtr,
         dnet_sub: JsonSubscriber,
         deg_sub: JsonSubscriber,
+        replay_datastore: PathBuf,
     ) -> Self {
         Self {
             p2p,
@@ -151,6 +162,7 @@ impl DarkIrc {
             rpc_connections: Mutex::new(HashSet::new()),
             dnet_sub,
             deg_sub,
+            replay_datastore,
         }
     }
 }
@@ -197,19 +209,32 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
         return Ok(())
     }
 
+    let replay_mode = args.replay_mode;
+
     info!("Initializing DarkIRC node");
 
     // Create datastore path if not there already.
     let datastore = expand_path(&args.datastore)?;
     fs::create_dir_all(&datastore).await?;
 
+    let replay_datastore = expand_path(&args.replay_datastore)?;
+    fs::create_dir_all(&replay_datastore).await?;
+
     info!("Instantiating event DAG");
     let sled_db = sled::open(datastore)?;
     let mut p2p_settings: darkfi::net::Settings = args.net.into();
     p2p_settings.app_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
     let p2p = P2p::new(p2p_settings, ex.clone()).await;
-    let event_graph =
-        EventGraph::new(p2p.clone(), sled_db.clone(), "darkirc_dag", 1, ex.clone()).await?;
+    let event_graph = EventGraph::new(
+        p2p.clone(),
+        sled_db.clone(),
+        replay_datastore.clone(),
+        replay_mode,
+        "darkirc_dag",
+        1,
+        ex.clone(),
+    )
+    .await?;
 
     info!("Registering EventGraph P2P protocol");
     let event_graph_ = Arc::clone(&event_graph);
@@ -276,6 +301,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
         event_graph.clone(),
         dnet_sub,
         deg_sub,
+        replay_datastore.clone(),
     ));
     let darkirc_ = Arc::clone(&darkirc);
     let rpc_task = StoppableTask::new();

+ 1 - 1
bin/darkirc/src/rpc.rs

@@ -166,7 +166,7 @@ impl DarkIrc {
             return JsonError::new(ErrorCode::InvalidParams, None, id).into()
         }
 
-        recreate_from_replayer_log().await
+        recreate_from_replayer_log(&self.replay_datastore).await
     }
 }