Просмотр исходного кода

explorerd: add startup banner and refine log message lengths

This update adds a startup banner to explorerd that logs key details about the DarkFi Explorer Node when it starts successfully. The banner includes information such as the network, JSON-RPC endpoint, database path, configuration path, syncing details, and the connected DarkFi node, improving visibility and making debugging easier during startup. Additionally, longer log messages were shortened where possible to improve message length consistency.

Summary of Changes:
- Added the `log_started_banner` function to display the startup banner
- Updated the binary crate's main method to call `log_started_banner` after a successful startup
- Shortened some log messages to maintain a more consistent length where possible
kalm 1 год назад
Родитель
Сommit
315ef49038
2 измененных файлов с 46 добавлено и 22 удалено
  1. 35 10
      bin/explorer/explorerd/src/main.rs
  2. 11 12
      bin/explorer/explorerd/src/rpc_blocks.rs

+ 35 - 10
bin/explorer/explorerd/src/main.rs

@@ -16,16 +16,16 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+use lazy_static::lazy_static;
+use log::{debug, error, info};
+use sled_overlay::sled;
+use smol::{lock::Mutex, stream::StreamExt};
 use std::{
     collections::{HashMap, HashSet},
+    path::Path,
     str::FromStr,
     sync::Arc,
 };
-
-use lazy_static::lazy_static;
-use log::{debug, error, info};
-use sled_overlay::sled;
-use smol::{lock::Mutex, stream::StreamExt};
 use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 use url::Url;
 
@@ -190,7 +190,7 @@ impl ExplorerService {
 
             // Add source code into the `ContractMetaStore`
             self.db.contract_meta_store.insert_source(contract_id, &source_code)?;
-            info!(target: "explorerd: load_native_contract_sources", "Successfully loaded contract source for native contract {}", contract_id_str.to_string());
+            info!(target: "explorerd: load_native_contract_sources", "Loaded native contract source {}", contract_id_str.to_string());
         }
         Ok(())
     }
@@ -218,7 +218,7 @@ impl ExplorerService {
 
         // Load contract metadata into the `ContractMetaStore`
         self.db.contract_meta_store.insert_metadata(&contract_ids, &metadatas)?;
-        info!(target: "explorerd: load_native_contract_metadata", "Successfully loaded metadat for native contracts");
+        info!(target: "explorerd: load_native_contract_metadata", "Loaded metadata for native contracts");
 
         Ok(())
     }
@@ -237,18 +237,18 @@ impl ExplorerService {
             0 => {
                 self.reset_blocks()?;
                 self.reset_transactions()?;
-                debug!(target: "explorerd::reset_explorer_state", "Successfully reset explorer state to accept a new genesis block");
+                debug!(target: "explorerd::reset_explorer_state", "Reset explorer state to accept a new genesis block");
             }
             // Reset for all other heights
             _ => {
                 self.reset_to_height(height)?;
-                debug!(target: "explorerd::reset_explorer_state", "Successfully reset blocks to height: {height}");
+                debug!(target: "explorerd::reset_explorer_state", "Reset blocks to height: {height}");
             }
         }
 
         // Reset gas metrics to the specified height to reflect the updated blockchain state
         self.db.metrics_store.reset_gas_metrics(height)?;
-        debug!(target: "explorerd::reset_explorer_state", "Successfully reset metrics store to height: {height}");
+        debug!(target: "explorerd::reset_explorer_state", "Reset metrics store to height: {height}");
 
         Ok(())
     }
@@ -371,6 +371,9 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
         };
 
+    log_started_banner(explorer.clone(), &config, &args, &config_path);
+    info!(target: "explorerd::", "All is good. Waiting for block notifications...");
+
     // Signal handling for graceful termination.
     let (signals_handler, signals_task) = SignalHandler::new(ex)?;
     signals_handler.wait_termination(signals_task).await?;
@@ -390,3 +393,25 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 
     Ok(())
 }
+
+/// Logs a banner displaying the startup details of the DarkFi Explorer Node.
+fn log_started_banner(
+    explorer: Arc<Explorerd>,
+    config: &ExplorerNetworkConfig,
+    args: &Args,
+    config_path: &Path,
+) {
+    info!(target: "explorerd", "========================================================================================");
+    info!(target: "explorerd", "                   Started DarkFi Explorer Node                                        ");
+    info!(target: "explorerd", "========================================================================================");
+    info!(target: "explorerd", "  - Network: {}", args.network);
+    info!(target: "explorerd", "  - JSON-RPC Endpoint: {}", config.rpc.rpc_listen.to_string().trim_end_matches("/"));
+    info!(target: "explorerd", "  - Database: {}", config.database);
+    info!(target: "explorerd", "  - Configuration: {}", config_path.to_str().unwrap_or("Error: configuration path not found!"));
+    info!(target: "explorerd", "  - Reset Blocks: {}", if args.reset { "Yes" } else { "No" });
+    info!(target: "explorerd", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
+    info!(target: "explorerd", "  - Synced Blocks: {}", explorer.service.db.blockchain.len());
+    info!(target: "explorerd", "  - Synced Transactions: {}", explorer.service.db.blockchain.len());
+    info!(target: "explorerd", "  - Connected Darkfi Node: {}", config.endpoint.to_string().trim_end_matches("/"));
+    info!(target: "explorerd", "========================================================================================");
+}

+ 11 - 12
bin/explorer/explorerd/src/rpc_blocks.rs

@@ -84,8 +84,8 @@ impl Explorerd {
         // Declare a mutable variable to track the current sync height while processing blocks
         let mut current_height = last_synced_height;
 
-        info!(target: "explorerd::rpc_blocks::sync_blocks", "Requested to sync from block number: {current_height}");
-        info!(target: "explorerd::rpc_blocks::sync_blocks", "Last confirmed block number reported by darkfid: {last_darkfid_height} - {last_darkfid_hash}");
+        info!(target: "explorerd::rpc_blocks::sync_blocks", "Syncing from block number: {current_height}");
+        info!(target: "explorerd::rpc_blocks::sync_blocks", "Last confirmed darkfid block: {last_darkfid_height} - {last_darkfid_hash}");
 
         // A reorg is detected if the hash of the last synced block differs from the hash of the last confirmed block,
         // unless the reset flag is set or the current height is 0
@@ -96,7 +96,7 @@ impl Explorerd {
         if reset {
             self.service.reset_explorer_state(0)?;
             current_height = 0;
-            info!(target: "explorerd::rpc_blocks::sync_blocks", "Successfully reset explorer database based on set reset parameter");
+            info!(target: "explorerd::rpc_blocks::sync_blocks", "Reset explorer database based on set reset parameter");
         } else if reorg_detected {
             // Record the start time to measure the duration of potential reorg
             let start_reorg_time = Instant::now();
@@ -107,7 +107,7 @@ impl Explorerd {
 
             // Log only if a reorg occurred (i.e., the explorer wasn't merely catching up to Darkfi node blocks)
             if current_height != last_synced_height {
-                info!(target: "explorerd::rpc_blocks::sync_blocks", "Successfully completed reorg to height: {current_height} [{}]", fmt_duration(start_reorg_time.elapsed()));
+                info!(target: "explorerd::rpc_blocks::sync_blocks", "Completed reorg to height: {current_height} [{}]", fmt_duration(start_reorg_time.elapsed()));
             }
 
             // Prepare to sync the next block after reorg if not from genesis height
@@ -164,7 +164,7 @@ impl Explorerd {
 
         info!(
             target: "explorerd::rpc_blocks::sync_blocks",
-            "Successfully synced {} blocks: explorer blocks total {} [{}]",
+            "Synced {} blocks: explorer blocks total {} [{}]",
             blocks_synced,
             self.service.db.blockchain.blocks.len(),
             fmt_duration(sync_start_time.elapsed()),
@@ -213,7 +213,7 @@ impl Explorerd {
                             // If hashes match but the cur_height differs from the last synced height, reset the explorer state
                             if cur_height != last_synced_height {
                                 self.service.reset_explorer_state(cur_height)?;
-                                debug!(target: "explorerd::rpc_blocks::process_sync_blocks_reorg", "Successfully completed reorg to height: {cur_height}");
+                                debug!(target: "explorerd::rpc_blocks::process_sync_blocks_reorg", "Completed reorg to height: {cur_height}");
                             }
                             break;
                         } else {
@@ -461,7 +461,6 @@ pub async fn subscribe_blocks(
         ex.clone(),
     );
     info!(target: "explorerd::rpc_blocks::subscribe_blocks", "Detached subscription to background");
-    info!(target: "explorerd::rpc_blocks::subscribe_blocks", "All is good. Waiting for block notifications...");
 
     let listener_task = StoppableTask::new();
     listener_task.clone().start(
@@ -503,9 +502,9 @@ pub async fn subscribe_blocks(
                                     )))
                                 },
                             };
-                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "=======================================");
-                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "Block Notification: {}", darkfid_block.hash().to_string());
-                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "=======================================");
+                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "========================================================================================");
+                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "| Block Notification: {} |", darkfid_block.hash().to_string());
+                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "========================================================================================");
 
                             // Store darkfi node block height for later use
                             let darkfid_block_height = darkfid_block.header.height;
@@ -523,7 +522,7 @@ pub async fn subscribe_blocks(
 
                                 // Execute the reorg by resetting the explorer state to reset height
                                 explorer.service.reset_explorer_state(reset_height)?;
-                                info!(target: "explorerd::rpc_blocks::subscribe_blocks", "Successfully completed reorg to height: {reset_height} [{}]", fmt_duration(start_reorg_time.elapsed()));
+                                info!(target: "explorerd::rpc_blocks::subscribe_blocks", "Completed reorg to height: {reset_height} [{}]", fmt_duration(start_reorg_time.elapsed()));
                             }
 
 
@@ -536,7 +535,7 @@ pub async fn subscribe_blocks(
                                 )))
                             }
 
-                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "Successfully stored new block at height: {} [{}]", darkfid_block.header.height, fmt_duration(start_reorg_time.elapsed()));
+                            info!(target: "explorerd::rpc_blocks::subscribe_blocks", "Stored new block at height: {} [{}]", darkfid_block.header.height, fmt_duration(start_reorg_time.elapsed()));
 
                             // Process the next block
                             height = darkfid_block.header.height;