Преглед изворни кода

darkfid2: log targets cleanup

aggstam пре 3 година
родитељ
комит
e62faa1b75
4 измењених фајлова са 31 додато и 31 уклоњено
  1. 9 9
      bin/darkfid2/src/main.rs
  2. 1 1
      bin/darkfid2/src/rpc.rs
  3. 6 6
      bin/darkfid2/src/rpc_blockchain.rs
  4. 15 15
      bin/darkfid2/src/rpc_tx.rs

+ 9 - 9
bin/darkfid2/src/main.rs

@@ -110,10 +110,10 @@ impl Darkfid {
 
 async_daemonize!(realmain);
 async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
-    info!("Initializing DarkFi node...");
+    info!(target: "darkfid", "Initializing DarkFi node...");
 
     if args.testing_mode {
-        info!("Node is configured to run in testing mode!");
+        info!(target: "darkfid", "Node is configured to run in testing mode!");
     }
 
     // Initialize syncing P2P network
@@ -151,10 +151,10 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     // Initialize node
     let darkfid = Darkfid::new(sync_p2p, consensus_p2p, validator).await;
     let darkfid = Arc::new(darkfid);
-    info!("Node initialized successfully!");
+    info!(target: "darkfid", "Node initialized successfully!");
 
     // JSON-RPC server
-    info!("Starting JSON-RPC server");
+    info!(target: "darkfid", "Starting JSON-RPC server");
     let _ex = ex.clone();
     ex.spawn(listen_and_serve(args.rpc_listen, darkfid.clone(), _ex)).detach();
 
@@ -164,19 +164,19 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     // Signal handling for graceful termination.
     let (signals_handler, signals_task) = SignalHandler::new()?;
     signals_handler.wait_termination(signals_task).await?;
-    info!("Caught termination signal, cleaning up and exiting...");
+    info!(target: "darkfid", "Caught termination signal, cleaning up and exiting...");
 
-    info!("Stopping syncing P2P network...");
+    info!(target: "darkfid", "Stopping syncing P2P network...");
     darkfid.sync_p2p.stop().await;
 
     if args.consensus {
-        info!("Stopping consensus P2P network...");
+        info!(target: "darkfid", "Stopping consensus P2P network...");
         darkfid.consensus_p2p.clone().unwrap().stop().await;
     }
 
-    info!("Flushing sled database...");
+    info!(target: "darkfid", "Flushing sled database...");
     let flushed_bytes = sled_db.flush_async().await?;
-    info!("Flushed {} bytes", flushed_bytes);
+    info!(target: "darkfid", "Flushed {} bytes", flushed_bytes);
 
     Ok(())
 }

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

@@ -40,7 +40,7 @@ impl RequestHandler for Darkfid {
 
         let params = req.params.as_array().unwrap();
 
-        debug!(target: "RPC", "--> {}", serde_json::to_string(&req).unwrap());
+        debug!(target: "darkfid::rpc", "--> {}", serde_json::to_string(&req).unwrap());
 
         match req.method.as_str() {
             // =====================

+ 6 - 6
bin/darkfid2/src/rpc_blockchain.rs

@@ -61,7 +61,7 @@ impl Darkfid {
                 v
             }
             Err(e) => {
-                error!("[RPC] blockchain.get_slot: Failed fetching block by slot: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_slot", "Failed fetching block by slot: {}", e);
                 return JsonError::new(InternalError, None, id).into()
             }
         };
@@ -111,7 +111,7 @@ impl Darkfid {
                 txs
             }
             Err(e) => {
-                error!("[RPC] blockchain.get_tx: Failed fetching tx by hash: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_tx", "Failed fetching tx by hash: {}", e);
                 return JsonError::new(InternalError, None, id).into()
             }
         };
@@ -169,7 +169,7 @@ impl Darkfid {
         let contract_id = match ContractId::from_str(params[0].as_str().unwrap()) {
             Ok(v) => v,
             Err(e) => {
-                error!("[RPC] blockchain.lookup_zkas: Error decoding string to ContractId: {}", e);
+                error!(target: "darkfid::rpc::blockchain_lookup_zkas", "Error decoding string to ContractId: {}", e);
                 return JsonError::new(InvalidParams, None, id).into()
             }
         };
@@ -182,7 +182,7 @@ impl Darkfid {
             SMART_CONTRACT_ZKAS_DB_NAME,
         ) else {
             error!(
-                "[RPC] blockchain.lookup_zkas: Did not find zkas db for ContractId: {}",
+                target: "darkfid::rpc::blockchain_lookup_zkas", "Did not find zkas db for ContractId: {}",
                 contract_id
             );
             return server_error(RpcError::ContractZkasDbNotFound, id, None)
@@ -191,9 +191,9 @@ impl Darkfid {
         let mut ret: Vec<(String, Vec<u8>)> = vec![];
 
         for i in zkas_db.iter() {
-            debug!("Iterating over zkas db");
+            debug!(target: "darkfid::rpc::blockchain_lookup_zkas", "Iterating over zkas db");
             let Ok((zkas_ns, zkas_bytes)) = i else {
-                error!("Internal sled error iterating db");
+                error!(target: "darkfid::rpc::blockchain_lookup_zkas", "Internal sled error iterating db");
                 return JsonError::new(InternalError, None, id).into()
             };
 

+ 15 - 15
bin/darkfid2/src/rpc_tx.rs

@@ -45,7 +45,7 @@ impl Darkfid {
         }
 
         if !(*self.synced.lock().await) {
-            error!("[RPC] tx.simulate: Blockchain is not synced");
+            error!(target: "darkfid::rpc::tx_simulate", "Blockchain is not synced");
             return server_error(RpcError::NotSynced, id, None)
         }
 
@@ -53,7 +53,7 @@ impl Darkfid {
         let tx_bytes = match bs58::decode(params[0].as_str().unwrap().trim()).into_vec() {
             Ok(v) => v,
             Err(e) => {
-                error!("[RPC] tx.simulate: Failed decoding base58 transaction: {}", e);
+                error!(target: "darkfid::rpc::tx_simulate", "Failed decoding base58 transaction: {}", e);
                 return server_error(RpcError::ParseError, id, None)
             }
         };
@@ -61,7 +61,7 @@ impl Darkfid {
         let tx: Transaction = match deserialize(&tx_bytes) {
             Ok(v) => v,
             Err(e) => {
-                error!("[RPC] tx.simulate: Failed deserializing bytes into Transaction: {}", e);
+                error!(target: "darkfid::rpc::tx_simulate", "Failed deserializing bytes into Transaction: {}", e);
                 return server_error(RpcError::ParseError, id, None)
             }
         };
@@ -72,7 +72,7 @@ impl Darkfid {
         let result = lock.add_transactions(&[tx], current_slot, false).await;
         if result.is_err() {
             error!(
-                "[RPC] tx.simulate: Failed to validate state transition: {}",
+                target: "darkfid::rpc::tx_simulate", "Failed to validate state transition: {}",
                 result.err().unwrap()
             );
             return server_error(RpcError::TxSimulationFail, id, None)
@@ -95,7 +95,7 @@ impl Darkfid {
         }
 
         if !(*self.synced.lock().await) {
-            error!("[RPC] tx.transfer: Blockchain is not synced");
+            error!(target: "darkfid::rpc::tx_broadcast", "Blockchain is not synced");
             return server_error(RpcError::NotSynced, id, None)
         }
 
@@ -103,7 +103,7 @@ impl Darkfid {
         let tx_bytes = match bs58::decode(params[0].as_str().unwrap().trim()).into_vec() {
             Ok(v) => v,
             Err(e) => {
-                error!("[RPC] tx.broadcast: Failed decoding base58 transaction: {}", e);
+                error!(target: "darkfid::rpc::tx_broadcast", "Failed decoding base58 transaction: {}", e);
                 return server_error(RpcError::ParseError, id, None)
             }
         };
@@ -111,7 +111,7 @@ impl Darkfid {
         let tx: Transaction = match deserialize(&tx_bytes) {
             Ok(v) => v,
             Err(e) => {
-                error!("[RPC] tx.broadcast: Failed deserializing bytes into Transaction: {}", e);
+                error!(target: "darkfid::rpc::tx_broadcast", "Failed deserializing bytes into Transaction: {}", e);
                 return server_error(RpcError::ParseError, id, None)
             }
         };
@@ -120,7 +120,7 @@ impl Darkfid {
             // Consider we're participating in consensus here?
             // The append_tx function performs a state transition check.
             if self.validator.write().await.append_tx(tx.clone()).await.is_err() {
-                error!("[RPC] tx.broadcast: Failed to append transaction to mempool");
+                error!(target: "darkfid::rpc::tx_broadcast", "Failed to append transaction to mempool");
                 return server_error(RpcError::TxSimulationFail, id, None)
             }
         } else {
@@ -130,7 +130,7 @@ impl Darkfid {
             let result = lock.add_transactions(&[tx.clone()], current_slot, false).await;
             if result.is_err() {
                 error!(
-                    "[RPC] tx.simulate: Failed to validate state transition: {}",
+                    target: "darkfid::rpc::tx_broadcast", "Failed to validate state transition: {}",
                     result.err().unwrap()
                 );
                 return server_error(RpcError::TxSimulationFail, id, None)
@@ -139,7 +139,7 @@ impl Darkfid {
 
         self.sync_p2p.broadcast(&tx).await;
         if self.sync_p2p.channels().lock().await.is_empty() {
-            error!("[RPC] tx.broadcast: Failed broadcasting tx, no connected channels");
+            error!(target: "darkfid::rpc::tx_broadcast", "Failed broadcasting tx, no connected channels");
             return server_error(RpcError::TxBroadcastFail, id, None)
         }
 
@@ -159,7 +159,7 @@ impl Darkfid {
         }
 
         if !(*self.synced.lock().await) {
-            error!("[RPC] tx.transfer: Blockchain is not synced");
+            error!(target: "darkfid::rpc::tx_pending", "Blockchain is not synced");
             return server_error(RpcError::NotSynced, id, None)
         }
 
@@ -170,7 +170,7 @@ impl Darkfid {
                 v
             }
             Err(e) => {
-                error!("[RPC] blockchain.get_pending_txs: Failed fetching pending txs: {}", e);
+                error!(target: "darkfid::rpc::tx_pending", "Failed fetching pending txs: {}", e);
                 return JsonError::new(InternalError, None, id).into()
             }
         };
@@ -190,7 +190,7 @@ impl Darkfid {
         }
 
         if !(*self.synced.lock().await) {
-            error!("[RPC] tx.transfer: Blockchain is not synced");
+            error!(target: "darkfid::rpc::tx_clean_pending", "Blockchain is not synced");
             return server_error(RpcError::NotSynced, id, None)
         }
 
@@ -198,7 +198,7 @@ impl Darkfid {
         let pending_txs = match validator.blockchain.get_pending_txs() {
             Ok(v) => v,
             Err(e) => {
-                error!("[RPC] blockchain.get_pending_txs: Failed fetching pending txs: {}", e);
+                error!(target: "darkfid::rpc::tx_clean_pending", "Failed fetching pending txs: {}", e);
                 return JsonError::new(InternalError, None, id).into()
             }
         };
@@ -206,7 +206,7 @@ impl Darkfid {
         match validator.blockchain.remove_pending_txs(&pending_txs) {
             Ok(()) => drop(validator),
             Err(e) => {
-                error!("[RPC] blockchain.get_pending_txs: Failed fetching pending txs: {}", e);
+                error!(target: "darkfid::rpc::tx_clean_pending", "Failed fetching pending txs: {}", e);
                 return JsonError::new(InternalError, None, id).into()
             }
         };