lib.rs
1 // Copyright (c) 2025 ADnet Contributors 2 // This file is part of the AlphaOS library. 3 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 8 // http://www.apache.org/licenses/LICENSE-2.0 9 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 #![forbid(unsafe_code)] 17 #![allow(clippy::blocks_in_conditions)] 18 #![allow(clippy::type_complexity)] 19 20 #[macro_use] 21 extern crate async_trait; 22 #[macro_use] 23 extern crate tracing; 24 25 #[cfg(feature = "metrics")] 26 extern crate alphaos_node_metrics as metrics; 27 28 pub use alphaos_node_bft_events as events; 29 pub use alphaos_node_bft_ledger_service as ledger_service; 30 pub use alphaos_node_bft_storage_service as storage_service; 31 32 pub mod helpers; 33 34 mod bft; 35 pub use bft::*; 36 37 mod gateway; 38 pub use gateway::*; 39 40 mod primary; 41 pub use primary::*; 42 43 mod sync; 44 pub use sync::*; 45 46 mod worker; 47 pub use worker::*; 48 49 pub const CONTEXT: &str = "[MemoryPool]"; 50 51 /// The port on which the memory pool listens for incoming connections. 52 pub const MEMORY_POOL_PORT: u16 = 5000; // port 53 54 /// The maximum number of milliseconds to wait before proposing a batch. 55 pub const MAX_BATCH_DELAY_IN_MS: u64 = 2500; // ms 56 /// The minimum number of seconds to wait before proposing a batch. 57 pub const MIN_BATCH_DELAY_IN_SECS: u64 = 1; // seconds 58 /// The maximum number of milliseconds to wait before timing out on a fetch. 59 pub const MAX_FETCH_TIMEOUT_IN_MS: u64 = 3 * MAX_BATCH_DELAY_IN_MS; // ms 60 /// The maximum number of seconds allowed for the leader to send their certificate. 61 pub const MAX_LEADER_CERTIFICATE_DELAY_IN_SECS: i64 = 2 * MAX_BATCH_DELAY_IN_MS as i64 / 1000; // seconds 62 /// The maximum number of seconds before the timestamp is considered expired. 63 pub const MAX_TIMESTAMP_DELTA_IN_SECS: i64 = 10; // seconds 64 /// The maximum number of workers that can be spawned. 65 pub const MAX_WORKERS: u8 = 1; // worker(s) 66 67 /// The interval at which each primary broadcasts a ping to every other node. 68 /// Note: If this is updated, be sure to update `MAX_BLOCKS_BEHIND` to correspond properly. 69 pub const PRIMARY_PING_IN_MS: u64 = 2 * MAX_BATCH_DELAY_IN_MS; // ms 70 /// The interval at which each worker broadcasts a ping to every other node. 71 pub const WORKER_PING_IN_MS: u64 = 4 * MAX_BATCH_DELAY_IN_MS; // ms 72 73 /// A helper macro to spawn a blocking task. 74 #[macro_export] 75 macro_rules! spawn_blocking { 76 ($expr:expr) => { 77 match tokio::task::spawn_blocking(move || $expr).await { 78 Ok(value) => value, 79 Err(error) => Err(anyhow::anyhow!("[tokio::spawn_blocking] {error}")), 80 } 81 }; 82 }