Commit 5a582e7e authored by Andronik Ordian's avatar Andronik Ordian

secret-store: move db stuff to secret-store as per Anton's request

parent 4219e5a6
Pipeline #71697 passed with stages
in 15 minutes and 18 seconds
......@@ -20,6 +20,3 @@
mod impls;
pub use self::impls::{open_db_light, restoration_db_handler, migrate};
#[cfg(feature = "secretstore")]
pub use self::impls::open_secretstore_db;
......@@ -36,8 +36,6 @@ use cache::CacheConfig;
mod blooms;
mod migration;
mod helpers;
#[cfg(feature = "secretstore")]
mod migration_secretstore;
pub use self::migration::migrate;
......@@ -61,21 +59,6 @@ impl BlockChainDB for AppDB {
}
}
/// Open a secret store DB using the given secret store data path. The DB path is one level beneath the data path.
#[cfg(feature = "secretstore")]
pub fn open_secretstore_db(data_path: &str) -> Result<Arc<dyn KeyValueDB>, String> {
use std::path::PathBuf;
migration_secretstore::upgrade_db(data_path).map_err(|e| e.to_string())?;
let mut db_path = PathBuf::from(data_path);
db_path.push("db");
let db_path = db_path.to_str().ok_or_else(|| "Invalid secretstore path".to_string())?;
let config = DatabaseConfig::with_columns(Some(1));
Ok(Arc::new(Database::open(&config, &db_path).map_err(|e| format!("Error opening database: {:?}", e))?))
}
/// Create a restoration db handler using the config generated by `client_path` and `client_config`.
pub fn restoration_db_handler(client_path: &Path, client_config: &ClientConfig) -> Box<dyn BlockChainDBHandler> {
let client_db_config = helpers::client_db_config(client_path, client_config);
......
......@@ -124,7 +124,6 @@ mod server {
use ethcore_secretstore;
use parity_crypto::publickey::KeyPair;
use ansi_term::Colour::{Red, White};
use db;
use super::{Configuration, Dependencies, NodeSecretKey, ContractAddress, Executor};
fn into_service_contract_address(address: ContractAddress) -> ethcore_secretstore::ContractAddress {
......@@ -203,7 +202,7 @@ mod server {
cconf.cluster_config.nodes.insert(self_secret.public().clone(), cconf.cluster_config.listener_address.clone());
let db = db::open_secretstore_db(&conf.data_path)?;
let db = ethcore_secretstore::open_secretstore_db(&conf.data_path)?;
let key_server = ethcore_secretstore::start(deps.client, deps.sync, deps.miner, self_secret, cconf, db, executor)
.map_err(|e| format!("Error starting KeyServer {}: {}", key_server_name, e))?;
......
......@@ -22,6 +22,7 @@ futures = "0.1"
hyper = { version = "0.12", default-features = false }
keccak-hash = "0.4.0"
kvdb = "0.1"
kvdb-rocksdb = "0.2.0"
lazy_static = "1.0"
log = "0.4"
parity-bytes = "0.1"
......
......@@ -266,12 +266,10 @@ impl From<SerializableDocumentKeyShareV3> for DocumentKeyShare {
#[cfg(test)]
pub mod tests {
extern crate tempdir;
use std::collections::HashMap;
use std::sync::Arc;
use parking_lot::RwLock;
use self::tempdir::TempDir;
use tempdir::TempDir;
use crypto::publickey::{Random, Generator, Public};
use kvdb_rocksdb::{Database, DatabaseConfig};
use types::{Error, ServerKeyId};
......
......@@ -25,6 +25,7 @@ extern crate ethereum_types;
extern crate hyper;
extern crate keccak_hash as hash;
extern crate kvdb;
extern crate kvdb_rocksdb;
extern crate parity_bytes as bytes;
extern crate parity_crypto as crypto;
extern crate parity_runtime;
......@@ -58,7 +59,7 @@ extern crate ethkey;
#[cfg(test)]
extern crate env_logger;
#[cfg(test)]
extern crate kvdb_rocksdb;
extern crate tempdir;
#[cfg(feature = "accounts")]
extern crate ethcore_accounts as accounts;
......@@ -76,9 +77,11 @@ mod key_server_set;
mod node_key_pair;
mod listener;
mod trusted_client;
mod migration;
use std::sync::Arc;
use kvdb::KeyValueDB;
use kvdb_rocksdb::{Database, DatabaseConfig};
use ethcore::client::Client;
use ethcore::miner::Miner;
use sync::SyncProvider;
......@@ -91,6 +94,20 @@ pub use self::node_key_pair::PlainNodeKeyPair;
#[cfg(feature = "accounts")]
pub use self::node_key_pair::KeyStoreNodeKeyPair;
/// Open a secret store DB using the given secret store data path. The DB path is one level beneath the data path.
pub fn open_secretstore_db(data_path: &str) -> Result<Arc<dyn KeyValueDB>, String> {
use std::path::PathBuf;
migration::upgrade_db(data_path).map_err(|e| e.to_string())?;
let mut db_path = PathBuf::from(data_path);
db_path.push("db");
let db_path = db_path.to_str().ok_or_else(|| "Invalid secretstore path".to_string())?;
let config = DatabaseConfig::with_columns(Some(1));
Ok(Arc::new(Database::open(&config, &db_path).map_err(|e| format!("Error opening database: {:?}", e))?))
}
/// Start new key server instance
pub fn start(client: Arc<Client>, sync: Arc<dyn SyncProvider>, miner: Arc<Miner>, self_key_pair: Arc<dyn NodeKeyPair>, mut config: ServiceConfiguration,
db: Arc<dyn KeyValueDB>, executor: Executor) -> Result<Box<dyn KeyServer>, Error>
......
......@@ -23,7 +23,7 @@ use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read as _, Write as _}
use std::path::PathBuf;
use kvdb::DBTransaction;
use super::kvdb_rocksdb::{Database, DatabaseConfig};
use kvdb_rocksdb::{Database, DatabaseConfig};
/// We used to store the version in the database (until version 4).
const LEGACY_DB_META_KEY_VERSION: &[u8; 7] = b"version";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment