skoupidi 1 год назад
Родитель
Сommit
b6a6cb3e22

+ 7 - 7
bin/darkfid/src/lib.rs

@@ -192,7 +192,7 @@ impl Darkfid {
         // Pinging minerd daemon to verify it listens
         if self.node.rpc_client.is_some() {
             if let Err(e) = self.node.ping_miner_daemon().await {
-                warn!(target: "darkfid::Darkfid::start", "Failed to ping miner daemon: {}", e);
+                warn!(target: "darkfid::Darkfid::start", "Failed to ping miner daemon: {e}");
             }
         }
 
@@ -205,14 +205,14 @@ impl Darkfid {
                 let dnet_sub = p2p_.dnet_subscribe().await;
                 loop {
                     let event = dnet_sub.receive().await;
-                    debug!(target: "darkfid::Darkfid::dnet_task", "Got dnet event: {:?}", event);
+                    debug!(target: "darkfid::Darkfid::dnet_task", "Got dnet event: {event:?}");
                     dnet_sub_.notify(vec![event.into()].into()).await;
                 }
             },
             |res| async {
                 match res {
                     Ok(()) | Err(Error::DetachedTaskStopped) => { /* Do nothing */ }
-                    Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting dnet subs task: {}", e),
+                    Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting dnet subs task: {e}"),
                 }
             },
             Error::DetachedTaskStopped,
@@ -227,7 +227,7 @@ impl Darkfid {
             |res| async move {
                 match res {
                     Ok(()) | Err(Error::RpcServerStopped) => <DarkfiNode as RequestHandler<DefaultRpcHandler>>::stop_connections(&node_).await,
-                    Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting JSON-RPC server: {}", e),
+                    Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting JSON-RPC server: {e}"),
                 }
             },
             Error::RpcServerStopped,
@@ -243,7 +243,7 @@ impl Darkfid {
                 |res| async move {
                     match res {
                         Ok(()) | Err(Error::RpcServerStopped) => <DarkfiNode as RequestHandler<MmRpcHandler>>::stop_connections(&node_).await,
-                        Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting HTTP JSON-RPC server: {}", e),
+                        Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting HTTP JSON-RPC server: {e}"),
                     }
                 },
                 Error::RpcServerStopped,
@@ -278,7 +278,7 @@ impl Darkfid {
             |res| async move {
                 match res {
                     Ok(()) | Err(Error::ConsensusTaskStopped) | Err(Error::MinerTaskStopped) => { /* Do nothing */ }
-                    Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting consensus initialization task: {}", e),
+                    Err(e) => error!(target: "darkfid::Darkfid::start", "Failed starting consensus initialization task: {e}"),
                 }
             },
             Error::ConsensusTaskStopped,
@@ -316,7 +316,7 @@ impl Darkfid {
         // Flush sled database data
         info!(target: "darkfid::Darkfid::stop", "Flushing sled database...");
         let flushed_bytes = self.node.validator.blockchain.sled_db.flush_async().await?;
-        info!(target: "darkfid::Darkfid::stop", "Flushed {} bytes", flushed_bytes);
+        info!(target: "darkfid::Darkfid::stop", "Flushed {flushed_bytes} bytes");
 
         // Close the JSON-RPC client, if it was initialized
         if let Some(ref rpc_client) = self.node.rpc_client {

+ 6 - 6
bin/darkfid/src/main.rs

@@ -198,7 +198,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 
     // Initialize validator configuration
     let pow_fixed_difficulty = if let Some(diff) = blockchain_config.pow_fixed_difficulty {
-        info!(target: "darkfid", "Node is configured to run with fixed PoW difficulty: {}", diff);
+        info!(target: "darkfid", "Node is configured to run with fixed PoW difficulty: {diff}");
         Some(diff.into())
     } else {
         None
@@ -214,7 +214,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 
     // Check if reset was requested
     if let Some(height) = args.reset {
-        info!(target: "darkfid", "Node will reset validator state to height: {}", height);
+        info!(target: "darkfid", "Node will reset validator state to height: {height}");
         let validator = Validator::new(&sled_db, &config).await?;
         validator.reset_to_height(height).await?;
         info!(target: "darkfid", "Validator state reset successfully!");
@@ -301,14 +301,14 @@ pub async fn parse_blockchain_config(
 ) -> Result<BlockchainNetwork> {
     // Grab config path
     let config_path = get_config_path(config, CONFIG_FILE)?;
-    debug!(target: "darkfid", "Parsing configuration file: {:?}", config_path);
+    debug!(target: "darkfid", "Parsing configuration file: {config_path:?}");
 
     // Parse TOML file contents
     let contents = read_to_string(&config_path).await?;
     let contents: toml::Value = match toml::from_str(&contents) {
         Ok(v) => v,
         Err(e) => {
-            error!(target: "darkfid", "Failed parsing TOML config: {}", e);
+            error!(target: "darkfid", "Failed parsing TOML config: {e}");
             return Err(Error::ParseFailed("Failed parsing TOML config"))
         }
     };
@@ -329,11 +329,11 @@ pub async fn parse_blockchain_config(
         match BlockchainNetwork::from_iter_with_toml::<Vec<String>>(&network_config, vec![]) {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid", "Failed parsing requested network configuration: {}", e);
+                error!(target: "darkfid", "Failed parsing requested network configuration: {e}");
                 return Err(Error::ParseFailed("Failed parsing requested network configuration"))
             }
         };
-    debug!(target: "darkfid", "Parsed network configuration: {:?}", network_config);
+    debug!(target: "darkfid", "Parsed network configuration: {network_config:?}");
 
     Ok(network_config)
 }

+ 12 - 24
bin/darkfid/src/proto/protocol_sync.rs

@@ -565,8 +565,7 @@ async fn handle_receive_header_request(
             Err(e) => {
                 error!(
                     target: "darkfid::proto::protocol_sync::handle_receive_header_request",
-                    "get_headers_before fail: {}",
-                    e
+                    "get_headers_before fail: {e}"
                 );
                 handler.send_action(channel, ProtocolGenericAction::Skip).await;
                 continue
@@ -627,8 +626,7 @@ async fn handle_receive_request(
             Err(e) => {
                 error!(
                     target: "darkfid::proto::protocol_sync::handle_receive_request",
-                    "get_blocks_after fail: {}",
-                    e
+                    "get_blocks_after fail: {e}"
                 );
                 handler.send_action(channel, ProtocolGenericAction::Skip).await;
                 continue
@@ -683,8 +681,7 @@ async fn handle_receive_fork_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_request",
-                    "Getting fork proposals failed: {}",
-                    e
+                    "Getting fork proposals failed: {e}"
                 );
                 handler.send_action(channel, ProtocolGenericAction::Skip).await;
                 continue
@@ -739,8 +736,7 @@ async fn handle_receive_fork_header_hash_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_header_hash_request",
-                    "Getting fork header hash failed: {}",
-                    e
+                    "Getting fork header hash failed: {e}"
                 );
                 handler.send_action(channel, ProtocolGenericAction::Skip).await;
                 continue
@@ -762,8 +758,7 @@ async fn handle_receive_fork_header_hash_request(
         if let Err(e) = validator.blockchain.headers.get(&[request.fork_header], true) {
             debug!(
                 target: "darkfid::proto::protocol_sync::handle_receive_fork_header_hash_request",
-                "Getting fork header hash failed: {}",
-                e
+                "Getting fork header hash failed: {e}"
             );
             handler.send_action(channel, ProtocolGenericAction::Skip).await;
             continue
@@ -774,8 +769,7 @@ async fn handle_receive_fork_header_hash_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_header_hash_request",
-                    "Getting fork header hash failed: {}",
-                    e
+                    "Getting fork header hash failed: {e}"
                 );
                 ProtocolGenericAction::Skip
             }
@@ -837,8 +831,7 @@ async fn handle_receive_fork_headers_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_headers_request",
-                    "Getting fork headers failed: {}",
-                    e
+                    "Getting fork headers failed: {e}"
                 );
                 handler.send_action(channel, ProtocolGenericAction::Skip).await;
                 continue
@@ -860,8 +853,7 @@ async fn handle_receive_fork_headers_request(
         if let Err(e) = validator.blockchain.headers.get(&[request.fork_header], true) {
             debug!(
                 target: "darkfid::proto::protocol_sync::handle_receive_fork_headers_request",
-                "Getting fork header hash failed: {}",
-                e
+                "Getting fork header hash failed: {e}"
             );
             handler.send_action(channel, ProtocolGenericAction::Skip).await;
             continue
@@ -874,8 +866,7 @@ async fn handle_receive_fork_headers_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_headers_request",
-                    "Getting fork headers failed: {}",
-                    e
+                    "Getting fork headers failed: {e}"
                 );
                 ProtocolGenericAction::Skip
             }
@@ -937,8 +928,7 @@ async fn handle_receive_fork_proposals_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_proposals_request",
-                    "Getting fork proposals failed: {}",
-                    e
+                    "Getting fork proposals failed: {e}"
                 );
                 handler.send_action(channel, ProtocolGenericAction::Skip).await;
                 continue
@@ -960,8 +950,7 @@ async fn handle_receive_fork_proposals_request(
         if let Err(e) = validator.blockchain.headers.get(&[request.fork_header], true) {
             debug!(
                 target: "darkfid::proto::protocol_sync::handle_receive_fork_proposals_request",
-                "Getting fork header hash failed: {}",
-                e
+                "Getting fork header hash failed: {e}"
             );
             handler.send_action(channel, ProtocolGenericAction::Skip).await;
             continue
@@ -978,8 +967,7 @@ async fn handle_receive_fork_proposals_request(
             Err(e) => {
                 debug!(
                     target: "darkfid::proto::protocol_sync::handle_receive_fork_proposals_request",
-                    "Getting fork proposals failed: {}",
-                    e
+                    "Getting fork proposals failed: {e}"
                 );
                 ProtocolGenericAction::Skip
             }

+ 5 - 5
bin/darkfid/src/rpc.rs

@@ -211,7 +211,7 @@ impl DarkfiNode {
     // <-- {"jsonrpc": "2.0", "result": "true", "id": 1}
     async fn ping_miner(&self, id: u16, _params: JsonValue) -> JsonResult {
         if let Err(e) = self.ping_miner_daemon().await {
-            error!(target: "darkfid::rpc::ping_miner", "Failed to ping miner daemon: {}", e);
+            error!(target: "darkfid::rpc::ping_miner", "Failed to ping miner daemon: {e}");
             return server_error(RpcError::PingFailed, id, None)
         }
         JsonResponse::new(JsonValue::Boolean(true), id).into()
@@ -231,7 +231,7 @@ impl DarkfiNode {
         params: &JsonValue,
     ) -> Result<JsonValue> {
         let Some(ref rpc_client) = self.rpc_client else { return Err(Error::RpcClientStopped) };
-        debug!(target: "darkfid::rpc::miner_daemon_request", "Executing request {} with params: {:?}", method, params);
+        debug!(target: "darkfid::rpc::miner_daemon_request", "Executing request {method} with params: {params:?}");
         let latency = Instant::now();
         let req = JsonRequest::new(method, params.clone());
         let lock = rpc_client.lock().await;
@@ -239,8 +239,8 @@ impl DarkfiNode {
         let rep = client.request(req).await?;
         drop(lock);
         let latency = latency.elapsed();
-        debug!(target: "darkfid::rpc::miner_daemon_request", "Got reply: {:?}", rep);
-        debug!(target: "darkfid::rpc::miner_daemon_request", "Latency: {:?}", latency);
+        debug!(target: "darkfid::rpc::miner_daemon_request", "Got reply: {rep:?}");
+        debug!(target: "darkfid::rpc::miner_daemon_request", "Latency: {latency:?}");
         Ok(rep)
     }
 
@@ -256,7 +256,7 @@ impl DarkfiNode {
             match self.miner_daemon_request(method, params).await {
                 Ok(v) => return v,
                 Err(e) => {
-                    error!(target: "darkfid::rpc::miner_daemon_request_with_retry", "Failed to execute miner daemon request: {}", e);
+                    error!(target: "darkfid::rpc::miner_daemon_request_with_retry", "Failed to execute miner daemon request: {e}");
                 }
             }
             loop {

+ 8 - 11
bin/darkfid/src/rpc_blockchain.rs

@@ -64,7 +64,7 @@ impl DarkfiNode {
         let blocks = match self.validator.blockchain.get_blocks_by_heights(&[block_height]) {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::blockchain_get_block", "Failed fetching block by height: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_block", "Failed fetching block by height: {e}");
                 return JsonError::new(InternalError, None, id).into()
             }
         };
@@ -105,7 +105,7 @@ impl DarkfiNode {
         let txs = match self.validator.blockchain.transactions.get(&[tx_hash], true) {
             Ok(txs) => txs,
             Err(e) => {
-                error!(target: "darkfid::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()
             }
         };
@@ -271,7 +271,7 @@ impl DarkfiNode {
         let contract_id = match ContractId::from_str(contract_id) {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::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()
             }
         };
@@ -281,10 +281,7 @@ impl DarkfiNode {
             &contract_id,
             SMART_CONTRACT_ZKAS_DB_NAME,
         ) else {
-            error!(
-                target: "darkfid::rpc::blockchain_lookup_zkas", "Did not find zkas db for ContractId: {}",
-                contract_id
-            );
+            error!(target: "darkfid::rpc::blockchain_lookup_zkas", "Did not find zkas db for ContractId: {contract_id}");
             return server_error(RpcError::ContractZkasDbNotFound, id, None)
         };
 
@@ -339,7 +336,7 @@ impl DarkfiNode {
         let contract_id = match ContractId::from_str(contract_id) {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::blockchain_get_contract_state", "Error decoding string to ContractId: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_contract_state", "Error decoding string to ContractId: {e}");
                 return JsonError::new(InvalidParams, None, id).into()
             }
         };
@@ -357,7 +354,7 @@ impl DarkfiNode {
             )
             .into(),
             Err(e) => {
-                error!(target: "darkfid::rpc::blockchain_get_contract_state", "Failed fetching contract state records: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_contract_state", "Failed fetching contract state records: {e}");
                 server_error(RpcError::ContractStateNotFound, id, None)
             }
         }
@@ -395,7 +392,7 @@ impl DarkfiNode {
         let contract_id = match ContractId::from_str(contract_id) {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::blockchain_get_contract_state_key", "Error decoding string to ContractId: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_contract_state_key", "Error decoding string to ContractId: {e}");
                 return JsonError::new(InvalidParams, None, id).into()
             }
         };
@@ -416,7 +413,7 @@ impl DarkfiNode {
         ) {
             Ok(value) => JsonResponse::new(JsonValue::String(base64::encode(&value)), id).into(),
             Err(e) => {
-                error!(target: "darkfid::rpc::blockchain_get_contract_state_key", "Failed fetching contract state key value: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_contract_state_key", "Failed fetching contract state key value: {e}");
                 server_error(RpcError::ContractStateKeyNotFound, id, None)
             }
         }

+ 7 - 7
bin/darkfid/src/rpc_tx.rs

@@ -64,7 +64,7 @@ impl DarkfiNode {
         let tx: Transaction = match deserialize_async(&tx_bytes).await {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::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)
             }
         };
@@ -114,7 +114,7 @@ impl DarkfiNode {
         let tx: Transaction = match deserialize_async(&tx_bytes).await {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::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)
             }
         };
@@ -129,7 +129,7 @@ impl DarkfiNode {
         };
         // We'll perform the state transition check here.
         if let Err(e) = self.validator.append_tx(&tx, self.rpc_client.is_some()).await {
-            error!(target: "darkfid::rpc::tx_broadcast", "{}: {}", error_message, e);
+            error!(target: "darkfid::rpc::tx_broadcast", "{error_message}: {e}");
             return server_error(RpcError::TxSimulationFail, id, None)
         };
 
@@ -162,7 +162,7 @@ impl DarkfiNode {
         let pending_txs = match self.validator.blockchain.get_pending_txs() {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::tx_pending", "Failed fetching pending txs: {}", e);
+                error!(target: "darkfid::rpc::tx_pending", "Failed fetching pending txs: {e}");
                 return JsonError::new(InternalError, None, id).into()
             }
         };
@@ -193,13 +193,13 @@ impl DarkfiNode {
         let pending_txs = match self.validator.blockchain.get_pending_txs() {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::tx_clean_pending", "Failed fetching pending txs: {}", e);
+                error!(target: "darkfid::rpc::tx_clean_pending", "Failed fetching pending txs: {e}");
                 return JsonError::new(InternalError, None, id).into()
             }
         };
 
         if let Err(e) = self.validator.blockchain.remove_pending_txs(&pending_txs) {
-            error!(target: "darkfid::rpc::tx_clean_pending", "Failed fetching pending txs: {}", e);
+            error!(target: "darkfid::rpc::tx_clean_pending", "Failed fetching pending txs: {e}");
             return JsonError::new(InternalError, None, id).into()
         };
 
@@ -240,7 +240,7 @@ impl DarkfiNode {
         let tx: Transaction = match deserialize_async(&tx_bytes).await {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::tx_calculate_fee", "Failed deserializing bytes into Transaction: {}", e);
+                error!(target: "darkfid::rpc::tx_calculate_fee", "Failed deserializing bytes into Transaction: {e}");
                 return server_error(RpcError::ParseError, id, None)
             }
         };

+ 1 - 1
bin/darkfid/src/rpc_xmr.rs

@@ -40,7 +40,7 @@ impl DarkfiNode {
             Err(e) => {
                 error!(
                     target: "darkfid::rpc::xmr_merge_mining_get_chain_id",
-                    "[RPC] Error fetching genesis block hash: {}", e,
+                    "[RPC] Error fetching genesis block hash: {e}"
                 );
                 return JsonError::new(ErrorCode::InternalError, None, id).into()
             }

+ 1 - 1
bin/darkfid/src/task/consensus.rs

@@ -239,7 +239,7 @@ async fn consensus_task(
                 match res {
                     Ok(()) | Err(Error::GarbageCollectionTaskStopped) => { /* Do nothing */ }
                     Err(e) => {
-                        error!(target: "darkfid", "Failed starting garbage collection task: {}", e)
+                        error!(target: "darkfid", "Failed starting garbage collection task: {e}")
                     }
                 }
             },

+ 2 - 2
bin/darkfid/src/task/miner.rs

@@ -225,7 +225,7 @@ pub async fn miner_task(
                 match res {
                     Ok(()) | Err(Error::GarbageCollectionTaskStopped) => { /* Do nothing */ }
                     Err(e) => {
-                        error!(target: "darkfid", "Failed starting garbage collection task: {}", e)
+                        error!(target: "darkfid", "Failed starting garbage collection task: {e}")
                     }
                 }
             },
@@ -264,7 +264,7 @@ async fn listen_to_network(
     // Signal miner to abort mining
     sender.send(()).await?;
     if let Err(e) = node.miner_daemon_request("abort", &JsonValue::Array(vec![])).await {
-        error!(target: "darkfid::task::miner::listen_to_network", "Failed to execute miner daemon abort request: {}", e);
+        error!(target: "darkfid::task::miner::listen_to_network", "Failed to execute miner daemon abort request: {e}");
     }
 
     Ok(())

+ 4 - 4
bin/darkfid/src/task/sync.rs

@@ -340,7 +340,7 @@ async fn retrieve_headers(
             // Store the headers
             node.validator.blockchain.headers.insert_sync(&response_headers)?;
             last_tip_height = response_headers[0].height;
-            info!(target: "darkfid::task::sync::retrieve_headers", "Headers received: {}/{}", node.validator.blockchain.headers.len_sync(), total);
+            info!(target: "darkfid::task::sync::retrieve_headers", "Headers received: {}/{total}", node.validator.blockchain.headers.len_sync());
         }
     }
 
@@ -372,7 +372,7 @@ async fn retrieve_headers(
         }
         verified_headers += 1;
     }
-    info!(target: "darkfid::task::sync::retrieve_headers", "Headers verified: {}/{}", verified_headers, total);
+    info!(target: "darkfid::task::sync::retrieve_headers", "Headers verified: {verified_headers}/{total}");
 
     // Now we verify the rest sequences
     let mut last_checked = headers.last().unwrap().clone();
@@ -396,7 +396,7 @@ async fn retrieve_headers(
         }
         last_checked = headers.last().unwrap().clone();
         headers = node.validator.blockchain.headers.get_after_sync(last_checked.height, BATCH)?;
-        info!(target: "darkfid::task::sync::retrieve_headers", "Headers verified: {}/{}", verified_headers, total);
+        info!(target: "darkfid::task::sync::retrieve_headers", "Headers verified: {verified_headers}/{total}");
     }
 
     info!(target: "darkfid::task::sync::retrieve_headers", "Headers sequence verified!");
@@ -528,7 +528,7 @@ async fn retrieve_blocks(
                 }
             }
 
-            info!(target: "darkfid::task::sync::retrieve_blocks", "Blocks received: {}/{}", received_blocks, total);
+            info!(target: "darkfid::task::sync::retrieve_blocks", "Blocks received: {received_blocks}/{total}");
         }
     }