safety_rules/
lib.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8#![forbid(unsafe_code)]
9
10extern crate rand_08 as rand;
11
12mod configurable_validator_signer;
13mod consensus_state;
14mod error;
15mod logging;
16mod persistent_safety_storage;
17mod safety_rules;
18
19pub use crate::{
20    consensus_state::ConsensusState, error::Error,
21    persistent_safety_storage::PersistentSafetyStorage,
22    safety_rules::SafetyRules,
23};
24
25/// Create a SafetyRules instance.
26///
27/// The author and keys are threaded directly from the runtime rather than read
28/// from `SafetyRulesConfig`, because they're always overwritten from
29/// Conflux-side config at startup.
30pub fn create_safety_rules(
31    config: &diem_config::config::SafetyRulesConfig,
32    author: diem_types::PeerId,
33    consensus_private_key: diem_types::validator_config::ConsensusPrivateKey,
34    vrf_private_key: Option<
35        diem_types::validator_config::ConsensusVRFPrivateKey,
36    >,
37    export_consensus_key: bool,
38) -> SafetyRules {
39    use diem_secure_storage::{KVStorage, OnDiskStorage};
40
41    let internal_storage: OnDiskStorage = (&config.backend).into();
42    if let Err(error) = internal_storage.available() {
43        panic!("Storage is not available: {:?}", error);
44    }
45
46    let persistent_storage = PersistentSafetyStorage::initialize(
47        internal_storage,
48        author,
49        consensus_private_key,
50        config.enable_cached_safety_data,
51    );
52
53    SafetyRules::new(
54        persistent_storage,
55        export_consensus_key,
56        vrf_private_key,
57        author,
58    )
59}
60
61#[cfg(any(test, feature = "fuzzing"))]
62pub mod fuzzing_utils;
63
64#[cfg(any(test, feature = "fuzzing"))]
65pub use crate::fuzzing_utils::fuzzing;
66
67#[cfg(any(test, feature = "testing"))]
68pub mod test_utils;
69
70#[cfg(test)]
71mod tests;