amareleo_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 tracing;
22
23pub use amareleo_node_bft_events as events;
24pub use amareleo_node_bft_ledger_service as ledger_service;
25pub use amareleo_node_bft_storage_service as storage_service;
26
27pub mod helpers;
28
29mod bft;
30pub use bft::*;
31
32mod primary;
33pub use primary::*;
34
35mod sync;
36pub use sync::*;
37
38mod worker;
39pub use worker::*;
40
41/// The maximum number of milliseconds to wait before proposing a batch.
42pub const MAX_BATCH_DELAY_IN_MS: u64 = 2000; // ms
43/// The minimum number of seconds to wait before proposing a batch.
44pub const MIN_BATCH_DELAY_IN_SECS: u64 = 1; // seconds
45/// The maximum number of seconds allowed for the leader to send their certificate.
46pub const MAX_LEADER_CERTIFICATE_DELAY_IN_SECS: i64 = 2 * MAX_BATCH_DELAY_IN_MS as i64 / 1000; // seconds
47/// The maximum number of seconds before the timestamp is considered expired.
48pub const MAX_TIMESTAMP_DELTA_IN_SECS: i64 = 10; // seconds
49/// The maximum number of workers that can be spawned.
50pub const MAX_WORKERS: u8 = 1; // worker(s)
51/// The development mode RNG seed.
52pub const DEVELOPMENT_MODE_RNG_SEED: u64 = 1234567890u64;
53/// The development mode number of genesis committee members.
54pub const DEVELOPMENT_MODE_NUM_GENESIS_COMMITTEE_MEMBERS: u16 = 4;
55
56/// A helper macro to spawn a blocking task.
57#[macro_export]
58macro_rules! spawn_blocking {
59    ($expr:expr) => {
60        match tokio::task::spawn_blocking(move || $expr).await {
61            Ok(value) => value,
62            Err(error) => Err(anyhow::anyhow!("[tokio::spawn_blocking] {error}")),
63        }
64    };
65}