Skip to content

Commit 90bb7fb

Browse files
committed
nuke the remaining statics
1 parent c198738 commit 90bb7fb

6 files changed

Lines changed: 20 additions & 66 deletions

File tree

binaries/cuprated/src/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cuprate_helper::time::secs_to_hms;
1010

1111
use crate::{
1212
logging::{self, CupratedTracingFilter},
13-
statics, NodeContext,
13+
NodeContext,
1414
};
1515

1616
/// A command request with a response channel.
@@ -140,7 +140,7 @@ async fn handle_command(
140140
Command::Status => {
141141
let context = context_service.blockchain_context();
142142

143-
let uptime = statics::START_INSTANT.elapsed().unwrap_or_default();
143+
let uptime = node_ctx.start_instant.elapsed().unwrap_or_default();
144144

145145
let (h, m, s) = secs_to_hms(uptime.as_secs());
146146
let height = context.chain_height;

binaries/cuprated/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub mod commands;
3838
pub mod config;
3939
pub mod constants;
4040
pub mod logging;
41-
pub mod statics;
4241
pub mod version;
4342

4443
mod p2p;
@@ -107,6 +106,12 @@ pub struct NodeContext {
107106

108107
/// Sync state notifications.
109108
pub sync: SyncState,
109+
110+
/// The time this node was launched.
111+
pub start_instant: std::time::SystemTime,
112+
113+
/// The time this node was launched as a UNIX timestamp.
114+
pub start_instant_unix: u64,
110115
}
111116

112117
/// An active `cuprated` node.
@@ -158,9 +163,6 @@ impl Node {
158163
/// Panics if the database is corrupt, critical services fail to start, or
159164
/// `config.target_max_memory` is unresolved.
160165
pub async fn launch(config: Config) -> Self {
161-
// Initialize global static `LazyLock` data.
162-
statics::init_lazylock_statics();
163-
164166
let fast_sync_hashes = blockchain::get_fast_sync_hashes(config.fast_sync, config.network());
165167

166168
// Initialize the database thread pool.
@@ -225,6 +227,7 @@ impl Node {
225227
let (blockchain_manager_handle, blockchain_manager_rx) = BlockchainManagerHandle::new();
226228

227229
// Create the node context.
230+
let start_instant = std::time::SystemTime::now();
228231
let node_ctx = NodeContext {
229232
network: config.network(),
230233
fast_sync_hashes,
@@ -234,6 +237,11 @@ impl Node {
234237
blockchain_context: context_svc.clone(),
235238
txpool_read: txpool_read_handle.clone(),
236239
sync: sync_state,
240+
start_instant_unix: start_instant
241+
.duration_since(std::time::UNIX_EPOCH)
242+
.unwrap_or_default()
243+
.as_secs(),
244+
start_instant,
237245
};
238246

239247
// Start clearnet P2P zone

binaries/cuprated/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ fn main() {
3636
// Set global private permissions for created files.
3737
cuprate_helper::fs::set_private_global_file_permissions();
3838

39-
// Initialize global static `LazyLock` data.
40-
cuprated::statics::init_lazylock_statics();
41-
4239
// Parse CLI args and read config.
4340
let args = Args::parse();
4441
args.do_quick_requests();

binaries/cuprated/src/rpc/handlers/json_rpc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ use crate::{
6767
service::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
6868
CupratedRpcHandler,
6969
},
70-
statics::START_INSTANT_UNIX,
7170
};
7271

7372
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
@@ -528,7 +527,11 @@ async fn get_info(
528527
)]
529528
let rpc_connections_count = if restricted { 0 } else { 0 };
530529

531-
let start_time = if restricted { 0 } else { *START_INSTANT_UNIX };
530+
let start_time = if restricted {
531+
0
532+
} else {
533+
state.node_ctx.start_instant_unix
534+
};
532535
let synchronized = blockchain_manager::synced(todo!()).await?;
533536

534537
let target_height = blockchain_manager::target_height(todo!()).await?;

binaries/cuprated/src/rpc/handlers/other_json.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ use crate::{
5959
},
6060
CupratedRpcHandler,
6161
},
62-
statics::START_INSTANT_UNIX,
6362
txpool::IncomingTxs,
6463
};
6564

@@ -645,7 +644,7 @@ async fn get_net_stats(
645644

646645
Ok(GetNetStatsResponse {
647646
base: helper::response_base(false),
648-
start_time: *START_INSTANT_UNIX,
647+
start_time: state.node_ctx.start_instant_unix,
649648
total_packets_in: todo!(),
650649
total_bytes_in: todo!(),
651650
total_packets_out: todo!(),

binaries/cuprated/src/statics.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)