Skip to content

Commit

Permalink
support pruning mode (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
toxotguo authored Dec 21, 2018
1 parent b528e19 commit c1ca876
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ pub fn build_cli() -> App<'static, 'static> {
.help("Listen to all WebSocket interfaces (default is local)")
.takes_value(false),
)
.arg(
Arg::with_name("pruning")
.long("pruning")
.help("State Db PruningMode archiveall|archivecanonical|constrained (default is Constrained(256))")
.takes_value(true),
)
.subcommand(SubCommand::with_name("validator").about(
"Enable validator mode",
).arg(
Expand Down
6 changes: 3 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use std::path::PathBuf;
use Arc;

use client_db;
use state_db;
use substrate_client;

pub use chainx_api::{TBackend, TClient, TClientBlockBuilder, TExecutor};
use chainx_executor::NativeExecutor;
use cli::ChainSpec;
use state_machine::ExecutionStrategy;
use state_db::PruningMode;

const FINALIZATION_WINDOW: u64 = 32;

pub fn build_client(db_path: &str, chainspec: ChainSpec) -> Arc<TClient> {
pub fn build_client(db_path: &str, chainspec: ChainSpec, pruning: PruningMode) -> Arc<TClient> {
let backend = Arc::new(
TBackend::new(
client_db::DatabaseSettings {
cache_size: None,
path: PathBuf::from(db_path),
pruning: state_db::PruningMode::default(),
pruning: pruning,
},
FINALIZATION_WINDOW,
)
Expand Down
18 changes: 16 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ fn main() {
ChainSpec::Multi
}
};
let pruning = match matches.value_of("pruning").unwrap_or("constrained") {
"archiveall" => {
info!("Pruning is ArchiveAll mode");
state_db::PruningMode::ArchiveAll
}
"archivecanonical" => {
info!("Pruning is ArchiveCanonical mode");
state_db::PruningMode::ArchiveCanonical
}
"constrained" | _ => {
info!("Pruning is Constrained mode");
state_db::PruningMode::default()
}
};
let port = match matches.value_of("port") {
Some(port) => port
.parse()
Expand All @@ -99,8 +113,8 @@ fn main() {
);

let db_path = matches.value_of("db-path").unwrap_or("./.chainx");
let client = client::build_client(db_path, chainspec);

let client = client::build_client(db_path, chainspec, pruning);
let (exit_send, exit) = exit_future::signal();
let mut runtime = Runtime::new().expect("failed to start runtime on current thread");
let task_executor = runtime.executor();
Expand Down

0 comments on commit c1ca876

Please sign in to comment.