snarkos_node_bft_ledger_service/
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// See https://github.com/ProvableHQ/snarkVM/issues/2775
17#![forbid(unsafe_code)]
18
19#[macro_use]
20extern crate async_trait;
21
22#[cfg(feature = "metrics")]
23extern crate snarkos_node_metrics as metrics;
24
25#[cfg(feature = "ledger")]
26pub mod ledger;
27#[cfg(feature = "ledger")]
28pub use ledger::*;
29
30#[cfg(feature = "mock")]
31pub mod mock;
32#[cfg(feature = "mock")]
33pub use mock::*;
34
35#[cfg(feature = "prover")]
36pub mod prover;
37#[cfg(feature = "prover")]
38pub use prover::*;
39
40#[cfg(feature = "translucent")]
41pub mod translucent;
42#[cfg(feature = "translucent")]
43pub use translucent::*;
44
45pub mod traits;
46pub use traits::*;
47
48/// Formats an ID into a truncated identifier (for logging purposes).
49pub fn fmt_id(id: impl ToString) -> String {
50    let id = id.to_string();
51    let mut formatted_id = id.chars().take(16).collect::<String>();
52    if id.chars().count() > 16 {
53        formatted_id.push_str("..");
54    }
55    formatted_id
56}
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(snarkvm::prelude::anyhow!("[tokio::spawn_blocking] {error}")),
65        }
66    };
67}