Database backend (#133)

* DB backend

* DB backend

* Cleanup

* Clean build files after running tests

* Fixed comment

* add OOM lang item to runtime-io
This commit is contained in:
Arkadiy Paronyan
2018-05-02 13:36:36 +02:00
committed by Gav Wood
parent 81f133f36d
commit 1fd21618d9
9 changed files with 25 additions and 5 deletions
+1
View File
@@ -21,6 +21,7 @@ app_dirs = "1.2"
tokio-core = "0.1.12" tokio-core = "0.1.12"
futures = "0.1.17" futures = "0.1.17"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
fdlimit = "0.1"
substrate-client = { path = "../../substrate/client" } substrate-client = { path = "../../substrate/client" }
substrate-network = { path = "../../substrate/network" } substrate-network = { path = "../../substrate/network" }
substrate-codec = { path = "../../substrate/codec" } substrate-codec = { path = "../../substrate/codec" }
+10
View File
@@ -27,6 +27,7 @@ extern crate time;
extern crate futures; extern crate futures;
extern crate tokio_core; extern crate tokio_core;
extern crate ctrlc; extern crate ctrlc;
extern crate fdlimit;
extern crate ed25519; extern crate ed25519;
extern crate triehash; extern crate triehash;
extern crate substrate_codec as codec; extern crate substrate_codec as codec;
@@ -98,6 +99,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
// TODO [ToDr] Split parameters parsing from actual execution. // TODO [ToDr] Split parameters parsing from actual execution.
let log_pattern = matches.value_of("log").unwrap_or(""); let log_pattern = matches.value_of("log").unwrap_or("");
init_logger(log_pattern); init_logger(log_pattern);
fdlimit::raise_fd_limit();
let mut config = service::Configuration::default(); let mut config = service::Configuration::default();
@@ -111,6 +113,8 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
.to_string_lossy() .to_string_lossy()
.into(); .into();
config.database_path = db_path(&base_path).to_string_lossy().into();
let mut role = service::Role::FULL; let mut role = service::Role::FULL;
if matches.is_present("collator") { if matches.is_present("collator") {
info!("Starting collator."); info!("Starting collator.");
@@ -204,6 +208,12 @@ fn keystore_path(base_path: &Path) -> PathBuf {
path path
} }
fn db_path(base_path: &Path) -> PathBuf {
let mut path = base_path.to_owned();
path.push("db");
path
}
fn network_path(base_path: &Path) -> PathBuf { fn network_path(base_path: &Path) -> PathBuf {
let mut path = base_path.to_owned(); let mut path = base_path.to_owned();
path.push("network"); path.push("network");
+1 -1
View File
@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Parity Technologies <robert@parity.io>"] authors = ["Parity Technologies <robert@parity.io>"]
[dependencies] [dependencies]
ethcrypto = { git = "https://github.com/paritytech/parity", default_features = false } ethcore-crypto = { git = "https://github.com/paritytech/parity", default_features = false }
ed25519 = { path = "../../substrate/ed25519" } ed25519 = { path = "../../substrate/ed25519" }
error-chain = "0.11" error-chain = "0.11"
hex = "0.3" hex = "0.3"
+1 -1
View File
@@ -16,7 +16,7 @@
//! Keystore (and session key management) for polkadot. //! Keystore (and session key management) for polkadot.
extern crate ethcrypto as crypto; extern crate ethcore_crypto as crypto;
extern crate subtle; extern crate subtle;
extern crate ed25519; extern crate ed25519;
extern crate rand; extern crate rand;
+1
View File
@@ -24,5 +24,6 @@ substrate-runtime-io = { path = "../../substrate/runtime-io" }
substrate-primitives = { path = "../../substrate/primitives" } substrate-primitives = { path = "../../substrate/primitives" }
substrate-network = { path = "../../substrate/network" } substrate-network = { path = "../../substrate/network" }
substrate-client = { path = "../../substrate/client" } substrate-client = { path = "../../substrate/client" }
substrate-client-db = { path = "../../substrate/client/db" }
substrate-codec = { path = "../../substrate/codec" } substrate-codec = { path = "../../substrate/codec" }
substrate-executor = { path = "../../substrate/executor" } substrate-executor = { path = "../../substrate/executor" }
+3
View File
@@ -39,6 +39,8 @@ pub struct Configuration {
pub network: NetworkConfiguration, pub network: NetworkConfiguration,
/// Path to key files. /// Path to key files.
pub keystore_path: String, pub keystore_path: String,
/// Path to the database.
pub database_path: String,
/// Additional key seeds. /// Additional key seeds.
pub keys: Vec<String>, pub keys: Vec<String>,
/// Chain specification. /// Chain specification.
@@ -52,6 +54,7 @@ impl Default for Configuration {
transaction_pool: Default::default(), transaction_pool: Default::default(),
network: Default::default(), network: Default::default(),
keystore_path: Default::default(), keystore_path: Default::default(),
database_path: Default::default(),
keys: Default::default(), keys: Default::default(),
chain_spec: ChainSpec::Development, chain_spec: ChainSpec::Development,
} }
+8 -3
View File
@@ -33,6 +33,7 @@ extern crate substrate_runtime_io as runtime_io;
extern crate substrate_primitives as primitives; extern crate substrate_primitives as primitives;
extern crate substrate_network as network; extern crate substrate_network as network;
extern crate substrate_codec as codec; extern crate substrate_codec as codec;
extern crate substrate_client_db as client_db;
extern crate substrate_executor; extern crate substrate_executor;
extern crate exit_future; extern crate exit_future;
@@ -64,14 +65,13 @@ use polkadot_api::PolkadotApi;
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig, use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig, BuildExternalities}; SessionConfig, StakingConfig, BuildExternalities};
use client::{genesis, BlockchainEvents}; use client::{genesis, BlockchainEvents};
use client::in_mem::Backend as InMemory;
use network::ManageNetwork; use network::ManageNetwork;
use exit_future::Signal; use exit_future::Signal;
pub use self::error::{ErrorKind, Error}; pub use self::error::{ErrorKind, Error};
pub use config::{Configuration, Role, ChainSpec}; pub use config::{Configuration, Role, ChainSpec};
type Client = client::Client<InMemory, NativeExecutor<LocalDispatch>>; type Client = client::Client<client_db::Backend, NativeExecutor<LocalDispatch>>;
/// Polkadot service. /// Polkadot service.
pub struct Service { pub struct Service {
@@ -275,7 +275,12 @@ impl Service {
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect()) (primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
}; };
let client = Arc::new(client::new_in_mem(executor, prepare_genesis)?); let db_settings = client_db::DatabaseSettings {
cache_size: None,
path: config.database_path.into(),
};
let client = Arc::new(client_db::new_client(db_settings, executor, prepare_genesis)?);
let best_header = client.best_block_header()?; let best_header = client.best_block_header()?;
info!("Starting Polkadot. Best block is #{}", best_header.number); info!("Starting Polkadot. Best block is #{}", best_header.number);
let transaction_pool = Arc::new(Mutex::new(TransactionPool::new(config.transaction_pool))); let transaction_pool = Arc::new(Mutex::new(TransactionPool::new(config.transaction_pool)));