diff --git a/Cargo.lock b/Cargo.lock index 86a805b..17b6a5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "android-tzdata" @@ -174,7 +174,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror", + "thiserror 1.0.69", "time 0.3.36", ] @@ -466,9 +466,9 @@ checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad" [[package]] name = "cc" -version = "1.1.37" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "shlex", ] @@ -604,9 +604,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -913,7 +913,7 @@ dependencies = [ [[package]] name = "dkn-compute" -version = "0.2.20" +version = "0.2.21" dependencies = [ "async-trait", "base64 0.22.1", @@ -945,7 +945,7 @@ dependencies = [ [[package]] name = "dkn-p2p" -version = "0.2.20" +version = "0.2.21" dependencies = [ "env_logger 0.11.5", "eyre", @@ -957,7 +957,7 @@ dependencies = [ [[package]] name = "dkn-workflows" -version = "0.2.20" +version = "0.2.21" dependencies = [ "dotenvy", "env_logger 0.11.5", @@ -1632,7 +1632,7 @@ dependencies = [ "once_cell", "rand 0.8.5", "socket2 0.5.7", - "thiserror", + "thiserror 1.0.69", "tinyvec", "tokio 1.41.1", "tracing", @@ -1655,7 +1655,7 @@ dependencies = [ "rand 0.8.5", "resolv-conf", "smallvec", - "thiserror", + "thiserror 1.0.69", "tokio 1.41.1", "tracing", ] @@ -1719,7 +1719,7 @@ dependencies = [ "html5ever 0.27.0", "markup5ever 0.12.1", "tendril", - "thiserror", + "thiserror 1.0.69", "unicode-width", ] @@ -2346,9 +2346,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "libp2p" @@ -2383,7 +2383,7 @@ dependencies = [ "multiaddr", "pin-project", "rw-stream-sink", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -2417,7 +2417,7 @@ dependencies = [ "quick-protobuf-codec", "rand 0.8.5", "rand_core 0.6.4", - "thiserror", + "thiserror 1.0.69", "tracing", "void", "web-time", @@ -2454,7 +2454,7 @@ dependencies = [ "rand 0.8.5", "rw-stream-sink", "smallvec", - "thiserror", + "thiserror 1.0.69", "tracing", "unsigned-varint", "void", @@ -2477,7 +2477,7 @@ dependencies = [ "lru", "quick-protobuf", "quick-protobuf-codec", - "thiserror", + "thiserror 1.0.69", "tracing", "void", "web-time", @@ -2546,7 +2546,7 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "smallvec", - "thiserror", + "thiserror 1.0.69", "tracing", "void", ] @@ -2566,7 +2566,7 @@ dependencies = [ "quick-protobuf", "rand 0.8.5", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", "tracing", "zeroize", ] @@ -2592,7 +2592,7 @@ dependencies = [ "rand 0.8.5", "sha2 0.10.8", "smallvec", - "thiserror", + "thiserror 1.0.69", "tracing", "uint", "void", @@ -2658,7 +2658,7 @@ dependencies = [ "sha2 0.10.8", "snow", "static_assertions", - "thiserror", + "thiserror 1.0.69", "tracing", "x25519-dalek", "zeroize", @@ -2699,7 +2699,7 @@ dependencies = [ "ring 0.17.8", "rustls", "socket2 0.5.7", - "thiserror", + "thiserror 1.0.69", "tokio 1.41.1", "tracing", ] @@ -2722,7 +2722,7 @@ dependencies = [ "quick-protobuf-codec", "rand 0.8.5", "static_assertions", - "thiserror", + "thiserror 1.0.69", "tracing", "void", "web-time", @@ -2810,7 +2810,7 @@ dependencies = [ "ring 0.17.8", "rustls", "rustls-webpki 0.101.7", - "thiserror", + "thiserror 1.0.69", "x509-parser", "yasna", ] @@ -2838,7 +2838,7 @@ dependencies = [ "either", "futures", "libp2p-core", - "thiserror", + "thiserror 1.0.69", "tracing", "yamux 0.12.1", "yamux 0.13.3", @@ -3204,7 +3204,7 @@ dependencies = [ "anyhow", "byteorder", "paste", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -3218,7 +3218,7 @@ dependencies = [ "log", "netlink-packet-core", "netlink-sys", - "thiserror", + "thiserror 1.0.69", "tokio 1.41.1", ] @@ -3356,7 +3356,7 @@ dependencies = [ [[package]] name = "ollama-workflows" version = "0.1.0" -source = "git+https://github.com/andthattoo/ollama-workflows#7dde4dc1c82484ede4f01b14c8e77d1f898c8219" +source = "git+https://github.com/andthattoo/ollama-workflows#75ead48d237d1f408a82f20eef2cd350f217e592" dependencies = [ "async-trait", "base64 0.22.1", @@ -3443,9 +3443,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.4.0+3.4.0" +version = "300.4.1+3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a709e02f2b4aca747929cca5ed248880847c650233cf8b8cdc48f40aaf4898a6" +checksum = "faa4eac4138c62414b5622d1b31c5c304f34b406b013c079c2bbc652fdd6678c" dependencies = [ "cc", ] @@ -3848,15 +3848,15 @@ dependencies = [ "asynchronous-codec", "bytes 1.8.0", "quick-protobuf", - "thiserror", + "thiserror 1.0.69", "unsigned-varint", ] [[package]] name = "quinn" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" dependencies = [ "bytes 1.8.0", "futures-io", @@ -3866,26 +3866,29 @@ dependencies = [ "rustc-hash", "rustls", "socket2 0.5.7", - "thiserror", + "thiserror 2.0.3", "tokio 1.41.1", "tracing", ] [[package]] name = "quinn-proto" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" dependencies = [ "bytes 1.8.0", + "getrandom 0.2.15", "rand 0.8.5", "ring 0.17.8", "rustc-hash", "rustls", + "rustls-pki-types", "slab", - "thiserror", + "thiserror 2.0.3", "tinyvec", "tracing", + "web-time", ] [[package]] @@ -4027,9 +4030,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -4196,7 +4199,7 @@ dependencies = [ "netlink-packet-route", "netlink-proto", "nix", - "thiserror", + "thiserror 1.0.69", "tokio 1.41.1", ] @@ -4232,9 +4235,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.39" +version = "0.38.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags 2.6.0", "errno", @@ -4245,9 +4248,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" dependencies = [ "once_cell", "ring 0.17.8", @@ -4271,6 +4274,9 @@ name = "rustls-pki-types" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +dependencies = [ + "web-time", +] [[package]] name = "rustls-webpki" @@ -4371,7 +4377,7 @@ dependencies = [ "reqwest 0.10.10", "scraper 0.12.0", "select", - "thiserror", + "thiserror 1.0.69", "tokio 0.2.25", ] @@ -4390,9 +4396,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -4456,18 +4462,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -4880,7 +4886,7 @@ dependencies = [ "once_cell", "regex", "strum", - "thiserror", + "thiserror 1.0.69", "unicode-segmentation", ] @@ -4892,18 +4898,38 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] name = "thiserror-impl" -version = "1.0.68" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", @@ -5749,7 +5775,7 @@ dependencies = [ "nom", "oid-registry", "rusticata-macros", - "thiserror", + "thiserror 1.0.69", "time 0.3.36", ] diff --git a/Cargo.toml b/Cargo.toml index a56e33e..feb46d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ default-members = ["compute"] [workspace.package] edition = "2021" -version = "0.2.20" +version = "0.2.21" license = "Apache-2.0" readme = "README.md" diff --git a/compute/src/handlers/workflow.rs b/compute/src/handlers/workflow.rs index 5941b8e..e688c6c 100644 --- a/compute/src/handlers/workflow.rs +++ b/compute/src/handlers/workflow.rs @@ -1,3 +1,5 @@ +use std::time::Instant; + use async_trait::async_trait; use dkn_p2p::libp2p::gossipsub::MessageAcceptance; use dkn_workflows::{Entry, Executor, ModelProvider, ProgramMemory, Workflow}; @@ -5,7 +7,7 @@ use eyre::{eyre, Context, Result}; use libsecp256k1::PublicKey; use serde::Deserialize; -use crate::payloads::{TaskErrorPayload, TaskRequestPayload, TaskResponsePayload}; +use crate::payloads::{TaskErrorPayload, TaskRequestPayload, TaskResponsePayload, TaskStats}; use crate::utils::{get_current_time_nanos, DKNMessage}; use crate::DriaComputeNode; @@ -38,6 +40,7 @@ impl ComputeHandler for WorkflowHandler { let task = message .parse_payload::>(true) .wrap_err("Could not parse workflow task")?; + let mut task_stats = TaskStats::default().record_received_at(); // check if deadline is past or not let current_time = get_current_time_nanos(); @@ -90,6 +93,7 @@ impl ComputeHandler for WorkflowHandler { // execute workflow with cancellation let exec_result: Result; + let exec_started_at = Instant::now(); tokio::select! { _ = node.cancellation.cancelled() => { log::info!("Received cancellation, quitting all tasks."); @@ -99,10 +103,10 @@ impl ComputeHandler for WorkflowHandler { exec_result = exec_result_inner.map_err(|e| eyre!("Execution error: {}", e.to_string())); } } + task_stats = task_stats.record_execution_time(exec_started_at); - let (publish_result, acceptance) = match exec_result { + let (message, acceptance) = match exec_result { Ok(result) => { - log::warn!("Task {} result:", result); // obtain public key from the payload let task_public_key_bytes = hex::decode(&task.public_key).wrap_err("Could not decode public key")?; @@ -115,14 +119,20 @@ impl ComputeHandler for WorkflowHandler { &task_public_key, &node.config.secret_key, model_name, + task_stats.record_published_at(), )?; let payload_str = serde_json::to_string(&payload) .wrap_err("Could not serialize response payload")?; - // publish the result - // accept so that if there are others included in filter they can do the task + // prepare signed message + log::debug!( + "Publishing result for task {}\n{}", + task.task_id, + payload_str + ); let message = DKNMessage::new(payload_str, Self::RESPONSE_TOPIC); - (node.publish(message), MessageAcceptance::Accept) + // accept so that if there are others included in filter they can do the task + (message, MessageAcceptance::Accept) } Err(err) => { // use pretty display string for error logging with causes @@ -130,29 +140,35 @@ impl ComputeHandler for WorkflowHandler { log::error!("Task {} failed: {}", task.task_id, err_string); // prepare error payload - let error_payload = - TaskErrorPayload::new(task.task_id.clone(), err_string, model_name); + let error_payload = TaskErrorPayload { + task_id: task.task_id.clone(), + error: err_string, + model: model_name, + stats: task_stats.record_published_at(), + }; let error_payload_str = serde_json::to_string(&error_payload) .wrap_err("Could not serialize error payload")?; - // publish the error result for diagnostics - // ignore just in case, workflow may be bugged + // prepare signed message let message = DKNMessage::new_signed( error_payload_str, Self::RESPONSE_TOPIC, &node.config.secret_key, ); - (node.publish(message), MessageAcceptance::Ignore) + // ignore just in case, workflow may be bugged + (message, MessageAcceptance::Ignore) } }; - // if for some reason we couldnt publish the result, publish the error itself so that RPC doesnt hang - if let Err(publish_err) = publish_result { + // try publishing the result + + if let Err(publish_err) = node.publish(message) { let err_msg = format!("Could not publish result: {:?}", publish_err); log::error!("{}", err_msg); + let payload = serde_json::json!({ "taskId": task.task_id, - "error": err_msg + "error": err_msg, }); let message = DKNMessage::new_signed( payload.to_string(), diff --git a/compute/src/node.rs b/compute/src/node.rs index 1726fe5..a2ff518 100644 --- a/compute/src/node.rs +++ b/compute/src/node.rs @@ -232,7 +232,7 @@ impl DriaComputeNode { } else if std::matches!(topic_str, PingpongHandler::RESPONSE_TOPIC | WorkflowHandler::RESPONSE_TOPIC) { // since we are responding to these topics, we might receive messages from other compute nodes // we can gracefully ignore them and propagate it to to others - log::debug!("Ignoring message for topic: {}", topic_str); + log::trace!("Ignoring message for topic: {}", topic_str); self.p2p.validate_message(&message_id, &peer_id, gossipsub::MessageAcceptance::Accept)?; } else { // reject this message as its from a foreign topic diff --git a/compute/src/payloads/error.rs b/compute/src/payloads/error.rs index 1b4bfa1..30155c3 100644 --- a/compute/src/payloads/error.rs +++ b/compute/src/payloads/error.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use super::TaskStats; + /// A task error response. /// Returning this as the payload helps to debug the errors received at client side. #[derive(Debug, Clone, Serialize, Deserialize)] @@ -11,14 +13,6 @@ pub struct TaskErrorPayload { pub error: String, /// Name of the model that caused the error. pub model: String, -} - -impl TaskErrorPayload { - pub fn new(task_id: String, error: String, model: String) -> Self { - Self { - task_id, - error, - model, - } - } + /// Task statistics. + pub stats: TaskStats, } diff --git a/compute/src/payloads/mod.rs b/compute/src/payloads/mod.rs index e05948d..15a056e 100644 --- a/compute/src/payloads/mod.rs +++ b/compute/src/payloads/mod.rs @@ -6,3 +6,6 @@ pub use request::TaskRequestPayload; mod response; pub use response::TaskResponsePayload; + +mod stats; +pub use stats::TaskStats; diff --git a/compute/src/payloads/response.rs b/compute/src/payloads/response.rs index 907596d..d023c64 100644 --- a/compute/src/payloads/response.rs +++ b/compute/src/payloads/response.rs @@ -3,6 +3,8 @@ use eyre::Result; use libsecp256k1::{PublicKey, SecretKey}; use serde::{Deserialize, Serialize}; +use super::TaskStats; + /// A computation task is the task of computing a result from a given input. The result is encrypted with the public key of the requester. /// Plain result is signed by the compute node's private key, and a commitment is computed from the signature and plain result. /// @@ -19,6 +21,8 @@ pub struct TaskResponsePayload { pub ciphertext: String, /// Name of the model used for this task. pub model: String, + /// Stats about the task execution. + pub stats: TaskStats, } impl TaskResponsePayload { @@ -32,6 +36,7 @@ impl TaskResponsePayload { encrypting_public_key: &PublicKey, signing_secret_key: &SecretKey, model: String, + stats: TaskStats, ) -> Result { // create the message `task_id || payload` let mut preimage = Vec::new(); @@ -47,6 +52,7 @@ impl TaskResponsePayload { signature, ciphertext, model, + stats, }) } } @@ -74,9 +80,15 @@ mod tests { let task_id = uuid::Uuid::new_v4().to_string(); // creates a signed and encrypted payload - let payload = - TaskResponsePayload::new(RESULT, &task_id, &task_pk, &signer_sk, MODEL.to_string()) - .expect("Should create payload"); + let payload = TaskResponsePayload::new( + RESULT, + &task_id, + &task_pk, + &signer_sk, + MODEL.to_string(), + Default::default(), + ) + .expect("Should create payload"); // decrypt result and compare it to plaintext let ciphertext_bytes = hex::decode(payload.ciphertext).unwrap(); diff --git a/compute/src/payloads/stats.rs b/compute/src/payloads/stats.rs new file mode 100644 index 0000000..86a2d66 --- /dev/null +++ b/compute/src/payloads/stats.rs @@ -0,0 +1,55 @@ +use serde::{Deserialize, Serialize}; +use std::time::Instant; + +use crate::utils::get_current_time_nanos; + +/// A task stat. +/// Returning this as the payload helps to debug the errors received at client side. +#[derive(Default, Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TaskStats { + /// Timestamp at which the task was received from network & parsed. + pub received_at: u128, + /// Timestamp at which the task was published back to network. + pub published_at: u128, + /// Time taken to execute the task. + pub execution_time: u128, +} + +impl TaskStats { + /// Records the current timestamp within `received_at`. + pub fn record_received_at(mut self) -> Self { + // can unwrap safely here as UNIX_EPOCH is always smaller than now + self.received_at = get_current_time_nanos(); + self + } + + /// Records the current timestamp within `published_at`. + pub fn record_published_at(mut self) -> Self { + self.published_at = get_current_time_nanos(); + self + } + + pub fn record_execution_time(mut self, started_at: Instant) -> Self { + self.execution_time = Instant::now().duration_since(started_at).as_nanos(); + self + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_stats() { + let mut stats = TaskStats::default(); + + assert_eq!(stats.received_at, 0); + stats = stats.record_received_at(); + assert_ne!(stats.received_at, 0); + + assert_eq!(stats.published_at, 0); + stats = stats.record_published_at(); + assert_ne!(stats.published_at, 0); + } +} diff --git a/compute/src/utils/misc.rs b/compute/src/utils/misc.rs index 1c5fde7..521106e 100644 --- a/compute/src/utils/misc.rs +++ b/compute/src/utils/misc.rs @@ -2,19 +2,19 @@ use dkn_p2p::libp2p::{multiaddr::Protocol, Multiaddr}; use port_check::is_port_reachable; use std::{ net::{Ipv4Addr, SocketAddrV4}, - time::{Duration, SystemTime}, + time::SystemTime, }; /// Returns the current time in nanoseconds since the Unix epoch. /// /// If a `SystemTimeError` occurs, will return 0 just to keep things running. -#[inline] +#[inline(always)] pub fn get_current_time_nanos() -> u128 { SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap_or_else(|e| { log::error!("Error getting current time: {}", e); - Duration::new(0, 0) + Default::default() }) .as_nanos() }