commit
2e51589403
|
@ -26,7 +26,7 @@ pub const COL_BLOCK_HEADERS: u32 = 2;
|
|||
pub const COL_BLOCK_TRANSACTIONS: u32 = 3;
|
||||
pub const COL_TRANSACTIONS: u32 = 4;
|
||||
pub const COL_TRANSACTIONS_META: u32 = 5;
|
||||
const COL_BLOCK_NUMBERS: u32 = 6;
|
||||
pub const COL_BLOCK_NUMBERS: u32 = 6;
|
||||
const _COL_RESERVED3: u32 = 7;
|
||||
const _COL_RESERVED4: u32 = 8;
|
||||
const _COL_RESERVED5: u32 = 9;
|
||||
|
@ -62,9 +62,18 @@ impl Storage {
|
|||
|
||||
/// new storage at the selected path
|
||||
/// if no directory exists, it will be created
|
||||
pub fn new<P: AsRef<Path>>(path: P) -> Result<Storage, Error> {
|
||||
pub fn with_cache<P: AsRef<Path>>(path: P, total_cache: usize) -> Result<Storage, Error> {
|
||||
try!(fs::create_dir_all(path.as_ref()));
|
||||
let cfg = DatabaseConfig::with_columns(Some(COL_COUNT));
|
||||
let mut cfg = DatabaseConfig::with_columns(Some(COL_COUNT));
|
||||
|
||||
cfg.set_cache(Some(COL_TRANSACTIONS), total_cache / 4);
|
||||
cfg.set_cache(Some(COL_TRANSACTIONS_META), total_cache / 4);
|
||||
cfg.set_cache(Some(COL_BLOCK_HEADERS), total_cache / 4);
|
||||
|
||||
cfg.set_cache(Some(COL_BLOCK_HASHES), total_cache / 12);
|
||||
cfg.set_cache(Some(COL_BLOCK_TRANSACTIONS), total_cache / 12);
|
||||
cfg.set_cache(Some(COL_BLOCK_NUMBERS), total_cache / 12);
|
||||
|
||||
let db = try!(Database::open(&cfg, &*path.as_ref().to_string_lossy()));
|
||||
|
||||
let storage = Storage {
|
||||
|
@ -102,6 +111,10 @@ impl Storage {
|
|||
Ok(storage)
|
||||
}
|
||||
|
||||
pub fn new<P: AsRef<Path>>(path: P) -> Result<Storage, Error> {
|
||||
Self::with_cache(path, 256)
|
||||
}
|
||||
|
||||
fn read_meta(&self, key: &[u8]) -> Option<Bytes> {
|
||||
self.get(COL_META, key)
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ args:
|
|||
- printtoconsole:
|
||||
long: printtoconsole
|
||||
help: Send trace/debug info to console instead of debug.log file
|
||||
- db-cache:
|
||||
long: db-cache
|
||||
help: Sets db cache size
|
||||
subcommands:
|
||||
- import:
|
||||
about: Import blocks from bitcoin core database
|
||||
|
|
|
@ -11,8 +11,11 @@ pub struct Config {
|
|||
pub inbound_connections: u32,
|
||||
pub outbound_connections: u32,
|
||||
pub p2p_threads: usize,
|
||||
pub db_cache: usize,
|
||||
}
|
||||
|
||||
pub const DEFAULT_DB_CACHE: usize = 512;
|
||||
|
||||
pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
||||
let print_to_console = matches.is_present("printtoconsole");
|
||||
let magic = match (matches.is_present("testnet"), matches.is_present("regtest")) {
|
||||
|
@ -52,6 +55,11 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
None => None,
|
||||
};
|
||||
|
||||
let db_cache = match matches.value_of("db-cache") {
|
||||
Some(s) => try!(s.parse().map_err(|_| "Invalid cache size - should be number in MB".to_owned())),
|
||||
None => DEFAULT_DB_CACHE,
|
||||
};
|
||||
|
||||
let config = Config {
|
||||
print_to_console: print_to_console,
|
||||
magic: magic,
|
||||
|
@ -61,6 +69,7 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
inbound_connections: in_connections,
|
||||
outbound_connections: out_connections,
|
||||
p2p_threads: p2p_threads,
|
||||
db_cache: db_cache,
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
|
|
|
@ -5,9 +5,9 @@ use chain::RepresentH256;
|
|||
use {db, APP_INFO};
|
||||
use config::Config;
|
||||
|
||||
pub fn open_db(_cfg: &Config) -> db::SharedStore {
|
||||
pub fn open_db(cfg: &Config) -> db::SharedStore {
|
||||
let db_path = app_dir(AppDataType::UserData, &APP_INFO, "db").expect("Failed to get app dir");
|
||||
Arc::new(db::Storage::new(db_path).expect("Failed to open database"))
|
||||
Arc::new(db::Storage::with_cache(db_path, cfg.db_cache).expect("Failed to open database"))
|
||||
}
|
||||
|
||||
pub fn node_table_path() -> PathBuf {
|
||||
|
|
Loading…
Reference in New Issue