Skip to content

Commit

Permalink
refactor: set data_diras global
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Oct 25, 2023
1 parent 375977b commit 15dbee6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
11 changes: 8 additions & 3 deletions spec/src/versionbits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
mod convert;

use crate::consensus::Consensus;
use ckb_logger::error;
use ckb_types::{
core::{EpochExt, EpochNumber, HeaderView, Ratio, TransactionView, Version, DATA_DIR},
core::{EpochExt, EpochNumber, HeaderView, Ratio, TransactionView, Version},
global::DATA_DIR,
packed::{Byte32, CellbaseWitnessReader},
prelude::*,
};
use std::fmt;
use std::sync::Arc;
use std::{collections::HashMap, path::PathBuf};
use ckb_logger::error;

/// What bits to set in version for versionbits blocks
pub const VERSIONBITS_TOP_BITS: Version = 0x00000000;
Expand Down Expand Up @@ -155,7 +156,11 @@ impl Cache {
}

pub fn insert(&self, key: &Byte32, value: ThresholdState) {
if let Err(e) = cacache::write_sync(&self.path, Self::encode_key(&key), Self::encode_value(value)) {
if let Err(e) = cacache::write_sync(
&self.path,
Self::encode_key(&key),
Self::encode_value(value),
) {
error!("cacache write_sync failed {:?}", e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion util/app-config/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! we must put nested config struct in the tail to make it serializable,
//! details <https://docs.rs/toml/0.5.0/toml/ser/index.html>
use ckb_types::core::DATA_DIR;
use ckb_types::global::DATA_DIR;
use path_clean::PathClean;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down
4 changes: 0 additions & 4 deletions util/types/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ pub use advanced_builders::{BlockBuilder, HeaderBuilder, TransactionBuilder};
pub use blockchain::DepType;
pub use extras::{BlockExt, EpochExt, EpochNumberWithFraction, TransactionInfo};
pub use fee_rate::FeeRate;
use once_cell::sync::OnceCell;
pub use reward::{BlockEconomicState, BlockIssuance, BlockReward, MinerReward};
use std::path::PathBuf;
pub use transaction_meta::{TransactionMeta, TransactionMetaBuilder};
pub use tx_pool::TransactionWithStatus;
pub use views::{
Expand All @@ -61,5 +59,3 @@ pub type Cycle = u64;

/// Version number.
pub type Version = u32;

pub static DATA_DIR: OnceCell<PathBuf> = OnceCell::new();
8 changes: 8 additions & 0 deletions util/types/src/global.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Global data, initialized in the launch phase.

use once_cell::sync::OnceCell;
use std::path::PathBuf;

/// ckb data directory path, located under root/data, initialized during the launch phase
pub static DATA_DIR: OnceCell<PathBuf> = OnceCell::new();
1 change: 1 addition & 0 deletions util/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use molecule::{self, error};
pub use numext_fixed_uint::{u256, U128, U256};

pub mod core;
pub mod global;

pub mod constants;
mod conversion;
Expand Down

0 comments on commit 15dbee6

Please sign in to comment.