snarkos_node_bft/
lib.rs

1// Copyright 2024 Aleo Network Foundation
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
25pub use snarkos_node_bft_events as events;
26pub use snarkos_node_bft_ledger_service as ledger_service;
27pub use snarkos_node_bft_storage_service as storage_service;
28
29pub mod helpers;
30
31mod bft;
32pub use bft::*;
33
34mod gateway;
35pub use gateway::*;
36
37mod primary;
38pub use primary::*;
39
40mod sync;
41pub use sync::*;
42
43mod worker;
44pub use worker::*;
45
46pub const CONTEXT: &str = "[MemoryPool]";
47
48/// The port on which the memory pool listens for incoming connections.
49pub const MEMORY_POOL_PORT: u16 = 5000; // port
50
51/// The maximum number of milliseconds to wait before proposing a batch.
52pub const MAX_BATCH_DELAY_IN_MS: u64 = 2500; // ms
53/// The minimum number of seconds to wait before proposing a batch.
54pub const MIN_BATCH_DELAY_IN_SECS: u64 = 1; // seconds
55/// The maximum number of milliseconds to wait before timing out on a fetch.
56pub const MAX_FETCH_TIMEOUT_IN_MS: u64 = 3 * MAX_BATCH_DELAY_IN_MS; // ms
57/// The maximum number of seconds allowed for the leader to send their certificate.
58pub const MAX_LEADER_CERTIFICATE_DELAY_IN_SECS: i64 = 2 * MAX_BATCH_DELAY_IN_MS as i64 / 1000; // seconds
59/// The maximum number of seconds before the timestamp is considered expired.
60pub const MAX_TIMESTAMP_DELTA_IN_SECS: i64 = 10; // seconds
61/// The maximum number of workers that can be spawned.
62pub const MAX_WORKERS: u8 = 1; // worker(s)
63
64/// The frequency at which each primary broadcasts a ping to every other node.
65/// Note: If this is updated, be sure to update `MAX_BLOCKS_BEHIND` to correspond properly.
66pub const PRIMARY_PING_IN_MS: u64 = 2 * MAX_BATCH_DELAY_IN_MS; // ms
67/// The frequency at which each worker broadcasts a ping to every other node.
68pub const WORKER_PING_IN_MS: u64 = 4 * MAX_BATCH_DELAY_IN_MS; // ms
69
70/// A helper macro to spawn a blocking task.
71#[macro_export]
72macro_rules! spawn_blocking {
73    ($expr:expr) => {
74        match tokio::task::spawn_blocking(move || $expr).await {
75            Ok(value) => value,
76            Err(error) => Err(anyhow::anyhow!("[tokio::spawn_blocking] {error}")),
77        }
78    };
79}