1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#![doc(html_root_url = "https://docs.rs/casper-node/1.3.1")]
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/casper-network/casper-node/master/images/CasperLabs_Logo_Favicon_RGB_50px.png",
html_logo_url = "https://raw.githubusercontent.com/casper-network/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png",
test(attr(forbid(warnings)))
)]
#![warn(
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_qualifications
)]
#![feature(test)]
extern crate test;
pub mod components;
mod config_migration;
pub mod crypto;
mod data_migration;
pub mod effect;
pub mod logging;
pub mod protocol;
pub mod reactor;
#[cfg(test)]
pub mod testing;
pub mod tls;
pub mod types;
pub mod utils;
use std::sync::{
atomic::{AtomicBool, AtomicUsize},
Arc,
};
use ansi_term::Color::Red;
use once_cell::sync::Lazy;
#[cfg(not(test))]
use rand::SeedableRng;
use signal_hook::{
consts::{signal::SIGUSR1, TERM_SIGNALS},
flag,
};
pub use components::{
block_proposer::Config as BlockProposerConfig,
consensus::Config as ConsensusConfig,
contract_runtime::Config as ContractRuntimeConfig,
deploy_acceptor::Config as DeployAcceptorConfig,
event_stream_server::Config as EventStreamServerConfig,
fetcher::Config as FetcherConfig,
gossiper::{Config as GossipConfig, Error as GossipError},
linear_chain_sync::Config as LinearChainSyncConfig,
rest_server::Config as RestServerConfig,
rpc_server::{rpcs, Config as RpcServerConfig},
small_network::{Config as SmallNetworkConfig, Error as SmallNetworkError},
storage::{Config as StorageConfig, Error as StorageError},
};
pub use config_migration::{migrate_config, Error as ConfigMigrationError};
pub use data_migration::{migrate_data, Error as DataMigrationError};
pub use types::NodeRng;
pub use utils::OS_PAGE_SIZE;
pub const MAX_THREAD_COUNT: usize = 512;
fn version_string(color: bool) -> String {
let mut version = format!("{}-{}", env!("CARGO_PKG_VERSION"), env!("VERGEN_SHA_SHORT"));
if env!("NODE_BUILD_PROFILE") != "release" {
version += "@";
let profile = env!("NODE_BUILD_PROFILE").to_uppercase();
version.push_str(&if color {
Red.paint(&profile).to_string()
} else {
profile
});
}
version
}
pub static VERSION_STRING_COLOR: Lazy<String> = Lazy::new(|| version_string(true));
pub static VERSION_STRING: Lazy<String> = Lazy::new(|| version_string(false));
pub static TERMINATION_REQUESTED: Lazy<Arc<AtomicUsize>> =
Lazy::new(|| Arc::new(AtomicUsize::new(0)));
pub static QUEUE_DUMP_REQUESTED: Lazy<Arc<AtomicBool>> =
Lazy::new(|| Arc::new(AtomicBool::new(false)));
pub fn setup_signal_hooks() {
for signal in TERM_SIGNALS {
flag::register_usize(
*signal,
Arc::clone(&*TERMINATION_REQUESTED),
*signal as usize,
)
.unwrap_or_else(|error| panic!("failed to register signal {}: {}", signal, error));
}
let _ = flag::register(SIGUSR1, Arc::clone(&*QUEUE_DUMP_REQUESTED));
}
#[cfg(not(test))]
pub fn new_rng() -> NodeRng {
NodeRng::from_entropy()
}
#[cfg(test)]
pub fn new_rng() -> NodeRng {
NodeRng::new()
}