Skip to content

Commit dcd5bfb

Browse files
authored
Merge pull request #227 from koushiro/improve-config
Improve archive config
2 parents 30ecb33 + 735930e commit dcd5bfb

35 files changed

+892
-1054
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template-archive/Cargo.lock

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template-archive/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ name = "node-template-archive"
33
version = "0.2.1"
44
authors = ["Andrew Plaza <aplaza@liquidthink.net>"]
55
edition = "2018"
6+
description = "Indexes Substrate Data"
67

78
[dependencies]
89
anyhow = "1.0"
9-
clap = { version = "2.33.1", features = ["yaml", "suggestions", "color"] }
1010
ctrlc = { version = "3.1.5", features = ["termination"] }
1111
log = "0.4"
1212
serde = "1.0"
13+
structopt = { version = "0.3", features = ["suggestions", "color"] }
1314
toml = "0.5"
1415

1516
node-template-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
1617
node-template = { git = "https://github.com/paritytech/substrate", branch = "master" }
1718

18-
substrate-archive = { path = "../../substrate-archive", features = ["logging"] }
19-
substrate-archive-backend = { path = "../../substrate-archive-backend" }
19+
substrate-archive = { path = "../../substrate-archive" }
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[chain]
2+
# Must be an absolute path to chain data db (no ~/)
3+
# Can also be specified via the `CHAIN_DATA_DB` environment variable
4+
data_path = "/.local/share/node-template/chains/dev/db"
5+
6+
# How much should the read-only database keep in cache (MB)
7+
# Optional, default: 128
8+
cache_size = 128
9+
10+
# RocksDB secondary directory
11+
# Optional, default: /<local>/substrate_archive/rocksdb_secondary/
12+
rocksdb_secondary_path = "./substrate_archive/rocksdb_secondary"
13+
14+
[runtime]
15+
# Specification of different methods of executing the runtime Wasm code.
16+
# Optional, "Interpreted" or "Compiled", default: "Interpreted".
17+
#exec_method = "Interpreted"
18+
19+
# Number of threads to dedicate for executing blocks
20+
# Optional, default: the number of logical system threads.
21+
block_workers = 4
22+
23+
# Number of 64KB Heap Pages to allocate for WASM execution
24+
# Optional, default: 1024.
25+
wasm_pages = 256
26+
27+
[database]
28+
# Database url.
29+
# Each chain needs it's own PostgreSQL database
30+
# Can also be specified via the `DATABASE_URL` environment variable.
31+
# For production use, using `DATABASE_URL` is preferable.
32+
# More info on the wiki: https://github.com/paritytech/substrate-archive/wiki/1.)-Requirements.
33+
url = "postgres://user:pass@localhost:5432/archive"
34+
35+
[log]
36+
# Optional log level of stdout, default: "DEBUG"
37+
std = "DEBUG"
38+
39+
# Optional file log.
40+
#[log.file]
41+
# Optional log level of file, default: "DEBUG"
42+
#level = "DEBUG"
43+
# Optional log file directory path, default: "/<local>/substrate_archive/"
44+
#dir = "./output/"
45+
# Optional log file name, default: "archive.log"
46+
#name = "archive.log"
47+
48+
# Advanced options
49+
#
50+
# Changing these may lead to unexpected results.
51+
[control]
52+
# Number of database actors to be spawned.
53+
# Optional, default: 4
54+
db_actor_pool_size = 4
55+
56+
# Number of threads to dedicate for executing tasks
57+
# Optional, default: the number of logical system threads
58+
task_workers = 8
59+
60+
# Timeout to wait for a task to start execution.
61+
# Optional, default: 20 seconds
62+
task_timeout = 20
63+
64+
# Maximum number of tasks to queue in the threadpool.
65+
# Optional, default: 64
66+
max_tasks = 64
67+
68+
# Maximium number of blocks to load and insert into database at a time.
69+
# Useful for controlling memory usage.
70+
# Optional, defaults: 100,000
71+
max_block_load = 100000
72+
73+
[wasm_tracing]
74+
# Targets for tracing.
75+
targets = '''wasm_tracing,pallet,frame,state'''
76+
77+
# Folder where tracing-enabled WASM binaries are kept.
78+
#folder = ""

bin/node-template-archive/archive_conf.toml

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

bin/node-template-archive/src/cli_opts.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,45 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with substrate-archive. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use std::path::PathBuf;
17+
use std::{fs, path::PathBuf};
1818

19-
use clap::{load_yaml, App};
19+
use anyhow::Result;
20+
use structopt::StructOpt;
2021

21-
#[derive(Clone)]
22+
use substrate_archive::ArchiveConfig;
23+
24+
#[derive(Clone, StructOpt)]
25+
#[structopt(author, about)]
2226
pub struct CliOpts {
23-
pub file: Option<PathBuf>,
24-
pub log_level: log::LevelFilter,
27+
/// Sets a custom config file
28+
#[structopt(short = "c", long, name = "FILE")]
29+
pub config: Option<PathBuf>,
30+
/// Sets spec for chain to run in (dev/local).
31+
#[structopt(short = "s", long = "spec", name = "CHAIN", parse(from_str = parse_chain_spec))]
2532
pub chain_spec: node_template::chain_spec::ChainSpec,
2633
}
2734

35+
fn parse_chain_spec(spec: &str) -> node_template::chain_spec::ChainSpec {
36+
let spec = match spec {
37+
"dev" => node_template::chain_spec::development_config(),
38+
"" | "local" => node_template::chain_spec::local_testnet_config(),
39+
path => node_template::chain_spec::ChainSpec::from_json_file(PathBuf::from(path)),
40+
};
41+
spec.expect("Chain spec could not be loaded")
42+
}
43+
2844
impl CliOpts {
29-
pub fn parse() -> Self {
30-
let yaml = load_yaml!("cli_opts.yaml");
31-
let matches = App::from(yaml).get_matches();
32-
let file = matches.value_of("config");
33-
let log_level = match matches.occurrences_of("verbose") {
34-
0 => log::LevelFilter::Info,
35-
1 => log::LevelFilter::Info,
36-
2 => log::LevelFilter::Info,
37-
3 => log::LevelFilter::Debug,
38-
4 | _ => log::LevelFilter::Trace,
39-
};
40-
let chain_spec = match matches.value_of("spec") {
41-
Some("dev") => node_template::chain_spec::development_config(),
42-
Some("") | Some("local") => node_template::chain_spec::local_testnet_config(),
43-
Some(path) => node_template::chain_spec::ChainSpec::from_json_file(PathBuf::from(path)),
44-
_ => panic!("Chain spec could not be loaded; is the path correct?"),
45-
};
46-
CliOpts {
47-
file: file.map(PathBuf::from),
48-
log_level,
49-
chain_spec: chain_spec.expect("Chain spec could not be loaded"),
45+
pub fn init() -> Self {
46+
CliOpts::from_args()
47+
}
48+
49+
pub fn parse(&self) -> Result<Option<ArchiveConfig>> {
50+
if let Some(config) = &self.config {
51+
let toml_str = fs::read_to_string(config.as_path())?;
52+
let config = toml::from_str::<ArchiveConfig>(toml_str.as_str())?;
53+
Ok(Some(config))
54+
} else {
55+
Ok(None)
5056
}
5157
}
5258
}

bin/node-template-archive/src/cli_opts.yaml

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

0 commit comments

Comments
 (0)