snarkos_node_bft/lib.rs
1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkOS 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]
21extern crate async_trait;
22#[macro_use]
23extern crate tracing;
24
25#[cfg(feature = "metrics")]
26extern crate snarkos_node_metrics as metrics;
27
28pub use snarkos_node_bft_events as events;
29pub use snarkos_node_bft_ledger_service as ledger_service;
30pub use snarkos_node_bft_storage_service as storage_service;
31
32pub mod helpers;
33
34mod bft;
35pub use bft::*;
36
37mod gateway;
38pub use gateway::*;
39
40mod primary;
41pub use primary::*;
42
43mod sync;
44pub use sync::*;
45
46mod worker;
47pub use worker::*;
48
49pub const CONTEXT: &str = "[MemoryPool]";
50
51/// The port on which the memory pool listens for incoming connections.
52pub const MEMORY_POOL_PORT: u16 = 5000; // port
53
54/// The maximum number of milliseconds to wait before proposing a batch.
55pub const MAX_BATCH_DELAY_IN_MS: u64 = 2500; // ms
56/// The minimum number of seconds to wait before proposing a batch.
57pub const MIN_BATCH_DELAY_IN_SECS: u64 = 1; // seconds
58/// The maximum number of milliseconds to wait before timing out on a fetch.
59pub 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.
61pub 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.
63pub const MAX_TIMESTAMP_DELTA_IN_SECS: i64 = 10; // seconds
64/// The maximum number of workers that can be spawned.
65pub 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.
69pub 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.
71pub 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]
75macro_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}