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