Skip to content

Commit fc108fa

Browse files
authored
Merge pull request #141 from koushiro/update-xtra
Update xtra to v0.5.0-rc.1
2 parents 295b507 + e68d4d0 commit fc108fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1237
-1000
lines changed

Cargo.lock

Lines changed: 245 additions & 183 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: 236 additions & 196 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: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@ version = "0.2.1"
44
authors = ["Andrew Plaza <aplaza@liquidthink.net>"]
55
edition = "2018"
66

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
97
[dependencies]
10-
substrate-archive = { path = "../../substrate-archive", features = ["logging"] }
11-
substrate-archive-common = { path = "../../substrate-archive-common" }
12-
substrate-archive-backend = { path = "../../substrate-archive-backend" }
13-
node-template-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
14-
node-template = { git = "https://github.com/paritytech/substrate", branch = "master" }
15-
8+
anyhow = "1.0"
169
clap = { version = "2.33.1", features = ["yaml", "suggestions", "color"] }
17-
toml = "0.5"
18-
futures = "0.3.5"
10+
ctrlc = { version = "3.1.5", features = ["termination"] }
1911
log = "0.4"
20-
pretty_env_logger = "0.4.0"
21-
anyhow = "1.0.31"
2212
serde = "1.0"
23-
ctrlc = { version = "3.1.5", features = ["termination"] }
13+
toml = "0.5"
14+
15+
node-template-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
16+
node-template = { git = "https://github.com/paritytech/substrate", branch = "master" }
2417

25-
[features]
18+
substrate-archive = { path = "../../substrate-archive", features = ["logging"] }
19+
substrate-archive-common = { path = "../../substrate-archive-common" }
20+
substrate-archive-backend = { path = "../../substrate-archive-backend" }

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

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,52 @@
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 clap::{load_yaml, App};
1817
use std::path::PathBuf;
1918

19+
use clap::{load_yaml, App};
20+
2021
#[derive(Clone)]
2122
pub struct CliOpts {
22-
pub file: PathBuf,
23-
pub log_level: log::LevelFilter,
24-
pub chain_spec: node_template::chain_spec::ChainSpec,
23+
pub file: PathBuf,
24+
pub log_level: log::LevelFilter,
25+
pub chain_spec: node_template::chain_spec::ChainSpec,
2526
}
2627

2728
impl CliOpts {
28-
pub fn parse() -> Self {
29-
let yaml = load_yaml!("cli_opts.yaml");
30-
let matches = App::from(yaml).get_matches();
31-
let log_level = match matches.occurrences_of("verbose") {
32-
0 => log::LevelFilter::Info,
33-
1 => log::LevelFilter::Info,
34-
2 => log::LevelFilter::Info,
35-
3 => log::LevelFilter::Debug,
36-
4 | _ => log::LevelFilter::Trace,
37-
};
38-
let file = matches
39-
.value_of("config")
40-
.expect("Config is a required value");
41-
let chain_spec;
42-
let spec = matches.value_of("spec");
43-
if spec.is_some() {
44-
match spec {
45-
Some("dev") => {
46-
chain_spec = node_template::chain_spec::development_config();
47-
}
48-
Some("") | Some("local") => {
49-
chain_spec = node_template::chain_spec::local_testnet_config();
50-
}
51-
path => {
52-
chain_spec = node_template::chain_spec::ChainSpec::from_json_file(
53-
std::path::PathBuf::from(path.expect("checked for existence; qed")),
54-
)
55-
}
56-
}
57-
} else {
58-
panic!("Chain spec could not be loaded; is the path correct?")
59-
}
60-
CliOpts {
61-
file: PathBuf::from(file),
62-
log_level,
63-
chain_spec: chain_spec.expect("Chain spec could not be loaded"),
64-
}
65-
}
29+
pub fn parse() -> Self {
30+
let yaml = load_yaml!("cli_opts.yaml");
31+
let matches = App::from(yaml).get_matches();
32+
let log_level = match matches.occurrences_of("verbose") {
33+
0 => log::LevelFilter::Info,
34+
1 => log::LevelFilter::Info,
35+
2 => log::LevelFilter::Info,
36+
3 => log::LevelFilter::Debug,
37+
4 | _ => log::LevelFilter::Trace,
38+
};
39+
let file = matches.value_of("config").expect("Config is a required value");
40+
let chain_spec;
41+
let spec = matches.value_of("spec");
42+
if spec.is_some() {
43+
match spec {
44+
Some("dev") => {
45+
chain_spec = node_template::chain_spec::development_config();
46+
}
47+
Some("") | Some("local") => {
48+
chain_spec = node_template::chain_spec::local_testnet_config();
49+
}
50+
path => {
51+
chain_spec = node_template::chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(
52+
path.expect("checked for existence; qed"),
53+
))
54+
}
55+
}
56+
} else {
57+
panic!("Chain spec could not be loaded; is the path correct?")
58+
}
59+
CliOpts {
60+
file: PathBuf::from(file),
61+
log_level,
62+
chain_spec: chain_spec.expect("Chain spec could not be loaded"),
63+
}
64+
}
6665
}

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

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,85 +14,88 @@
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 super::cli_opts::CliOpts;
17+
use std::path::{Path, PathBuf};
18+
1819
use anyhow::Result;
1920
use serde::{Deserialize, Serialize};
20-
use std::path::{Path, PathBuf};
21+
2122
use substrate_archive::MigrationConfig;
2223

24+
use crate::cli_opts::CliOpts;
25+
2326
#[derive(Clone)]
2427
pub struct Config {
25-
db_path: PathBuf,
26-
psql_conf: MigrationConfig,
27-
cli: CliOpts,
28-
cache_size: Option<usize>,
29-
block_workers: Option<usize>,
30-
wasm_pages: Option<u64>,
28+
db_path: PathBuf,
29+
psql_conf: MigrationConfig,
30+
cli: CliOpts,
31+
cache_size: Option<usize>,
32+
block_workers: Option<usize>,
33+
wasm_pages: Option<u64>,
3134
}
3235

3336
#[derive(Serialize, Deserialize, Debug, Clone)]
3437
struct TomlConfig {
35-
db_path: PathBuf,
36-
cache_size: Option<usize>,
37-
block_workers: Option<usize>,
38-
wasm_pages: Option<u64>,
39-
db_host: Option<String>,
40-
db_port: Option<String>,
41-
db_user: Option<String>,
42-
db_pass: Option<String>,
43-
db_name: Option<String>,
38+
db_path: PathBuf,
39+
cache_size: Option<usize>,
40+
block_workers: Option<usize>,
41+
wasm_pages: Option<u64>,
42+
db_host: Option<String>,
43+
db_port: Option<String>,
44+
db_user: Option<String>,
45+
db_pass: Option<String>,
46+
db_name: Option<String>,
4447
}
4548

4649
impl Config {
47-
pub fn new() -> Result<Self> {
48-
let cli_opts = CliOpts::parse();
49-
let toml_conf = Self::parse_file(cli_opts.file.as_path())?;
50-
log::debug!("{:?}", toml_conf);
51-
52-
let psql_conf = MigrationConfig {
53-
host: toml_conf.db_host.clone(),
54-
port: toml_conf.db_port.clone(),
55-
user: toml_conf.db_user.clone(),
56-
pass: toml_conf.db_pass.clone(),
57-
name: toml_conf.db_name.clone(),
58-
};
59-
60-
Ok(Self {
61-
db_path: toml_conf.db_path,
62-
psql_conf,
63-
cli: cli_opts,
64-
cache_size: toml_conf.cache_size,
65-
block_workers: toml_conf.block_workers,
66-
wasm_pages: toml_conf.wasm_pages,
67-
})
68-
}
69-
70-
fn parse_file(path: &Path) -> Result<TomlConfig> {
71-
let toml_str = std::fs::read_to_string(path)?;
72-
Ok(toml::from_str(toml_str.as_str())?)
73-
}
74-
75-
pub fn cli(&self) -> &CliOpts {
76-
&self.cli
77-
}
78-
79-
pub fn cache_size(&self) -> Option<usize> {
80-
self.cache_size
81-
}
82-
83-
pub fn psql_conf(&self) -> MigrationConfig {
84-
self.psql_conf.clone()
85-
}
86-
87-
pub fn block_workers(&self) -> Option<usize> {
88-
self.block_workers
89-
}
90-
91-
pub fn db_path(&self) -> &Path {
92-
self.db_path.as_path()
93-
}
94-
95-
pub fn wasm_pages(&self) -> Option<u64> {
96-
self.wasm_pages.clone()
97-
}
50+
pub fn new() -> Result<Self> {
51+
let cli_opts = CliOpts::parse();
52+
let toml_conf = Self::parse_file(cli_opts.file.as_path())?;
53+
log::debug!("{:?}", toml_conf);
54+
55+
let psql_conf = MigrationConfig {
56+
host: toml_conf.db_host.clone(),
57+
port: toml_conf.db_port.clone(),
58+
user: toml_conf.db_user.clone(),
59+
pass: toml_conf.db_pass.clone(),
60+
name: toml_conf.db_name.clone(),
61+
};
62+
63+
Ok(Self {
64+
db_path: toml_conf.db_path,
65+
psql_conf,
66+
cli: cli_opts,
67+
cache_size: toml_conf.cache_size,
68+
block_workers: toml_conf.block_workers,
69+
wasm_pages: toml_conf.wasm_pages,
70+
})
71+
}
72+
73+
fn parse_file(path: &Path) -> Result<TomlConfig> {
74+
let toml_str = std::fs::read_to_string(path)?;
75+
Ok(toml::from_str(toml_str.as_str())?)
76+
}
77+
78+
pub fn cli(&self) -> &CliOpts {
79+
&self.cli
80+
}
81+
82+
pub fn cache_size(&self) -> Option<usize> {
83+
self.cache_size
84+
}
85+
86+
pub fn psql_conf(&self) -> MigrationConfig {
87+
self.psql_conf.clone()
88+
}
89+
90+
pub fn block_workers(&self) -> Option<usize> {
91+
self.block_workers
92+
}
93+
94+
pub fn db_path(&self) -> &Path {
95+
self.db_path.as_path()
96+
}
97+
98+
pub fn wasm_pages(&self) -> Option<u64> {
99+
self.wasm_pages.clone()
100+
}
98101
}

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

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,39 @@
1616
mod cli_opts;
1717
mod config;
1818

19-
use anyhow::Result;
20-
use node_template_runtime::{self as runtime, opaque::Block};
2119
use std::sync::atomic::{AtomicBool, Ordering};
2220
use std::sync::Arc;
21+
22+
use node_template_runtime::{self as runtime, opaque::Block};
23+
2324
use substrate_archive::{Archive, ArchiveBuilder};
2425
use substrate_archive_backend::SecondaryRocksDB;
2526

26-
pub fn main() -> Result<()> {
27-
let config = config::Config::new()?;
28-
substrate_archive::init_logger(config.cli().log_level, log::LevelFilter::Debug)?;
29-
30-
let mut archive = ArchiveBuilder::<
31-
Block,
32-
runtime::RuntimeApi,
33-
node_template::service::Executor,
34-
SecondaryRocksDB,
35-
> {
36-
block_workers: config.block_workers(),
37-
wasm_pages: config.wasm_pages(),
38-
cache_size: config.cache_size(),
39-
..ArchiveBuilder::default()
40-
}
41-
.chain_data_db(config.db_path().to_str().unwrap().to_string())
42-
.pg_url(config.psql_conf().url())
43-
.chain_spec(Box::new(config.cli().chain_spec.clone()))
44-
.build()?;
45-
archive.drive()?;
46-
47-
let running = Arc::new(AtomicBool::new(true));
48-
let r = running.clone();
49-
50-
ctrlc::set_handler(move || {
51-
r.store(false, Ordering::SeqCst);
52-
})
53-
.expect("Error setting Ctrl-C handler");
54-
while running.load(Ordering::SeqCst) {}
55-
archive.shutdown()?;
56-
Ok(())
27+
pub fn main() -> anyhow::Result<()> {
28+
let config = config::Config::new()?;
29+
substrate_archive::init_logger(config.cli().log_level, log::LevelFilter::Debug)?;
30+
31+
let mut archive =
32+
ArchiveBuilder::<Block, runtime::RuntimeApi, node_template::service::Executor, SecondaryRocksDB> {
33+
block_workers: config.block_workers(),
34+
wasm_pages: config.wasm_pages(),
35+
cache_size: config.cache_size(),
36+
..ArchiveBuilder::default()
37+
}
38+
.chain_data_db(config.db_path().to_str().unwrap().to_string())
39+
.pg_url(config.psql_conf().url())
40+
.chain_spec(Box::new(config.cli().chain_spec.clone()))
41+
.build()?;
42+
archive.drive()?;
43+
44+
let running = Arc::new(AtomicBool::new(true));
45+
let r = running.clone();
46+
47+
ctrlc::set_handler(move || {
48+
r.store(false, Ordering::SeqCst);
49+
})
50+
.expect("Error setting Ctrl-C handler");
51+
while running.load(Ordering::SeqCst) {}
52+
archive.shutdown()?;
53+
Ok(())
5754
}

0 commit comments

Comments
 (0)