refactor sync and bin
This commit is contained in:
parent
b9793e06dd
commit
77c01c41e0
|
@ -5,7 +5,7 @@ use chain::RepresentH256;
|
|||
use {db, APP_INFO};
|
||||
use config::Config;
|
||||
|
||||
pub fn open_db(_cfg: &Config) -> Arc<db::Store> {
|
||||
pub fn open_db(_cfg: &Config) -> db::SharedStore {
|
||||
let db_path = app_dir(AppDataType::UserData, &APP_INFO, "db").expect("Failed to get app dir");
|
||||
Arc::new(db::Storage::new(db_path).expect("Failed to open database"))
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub fn node_table_path() -> PathBuf {
|
|||
node_table
|
||||
}
|
||||
|
||||
pub fn init_db(cfg: &Config, db: &Arc<db::Store>) -> Result<(), String> {
|
||||
pub fn init_db(cfg: &Config, db: &db::SharedStore) -> Result<(), String> {
|
||||
// insert genesis block if db is empty
|
||||
let genesis_block = cfg.magic.genesis_block();
|
||||
match db.block_hash(0) {
|
||||
|
|
|
@ -10,7 +10,7 @@ pub struct BlocksWriter {
|
|||
}
|
||||
|
||||
impl BlocksWriter {
|
||||
pub fn new(storage: Arc<db::Store>) -> BlocksWriter {
|
||||
pub fn new(storage: db::SharedStore) -> BlocksWriter {
|
||||
BlocksWriter {
|
||||
storage: storage.clone(),
|
||||
verifier: ChainVerifier::new(storage),
|
||||
|
|
|
@ -49,12 +49,12 @@ pub enum Error {
|
|||
}
|
||||
|
||||
/// Create blocks writer.
|
||||
pub fn create_sync_blocks_writer(db: Arc<db::Store>) -> blocks_writer::BlocksWriter {
|
||||
pub fn create_sync_blocks_writer(db: db::SharedStore) -> blocks_writer::BlocksWriter {
|
||||
blocks_writer::BlocksWriter::new(db)
|
||||
}
|
||||
|
||||
/// Create inbound synchronization connections factory for given `db`.
|
||||
pub fn create_sync_connection_factory(handle: &Handle, consensus_params: ConsensusParams, db: Arc<db::Store>) -> p2p::LocalSyncNodeRef {
|
||||
pub fn create_sync_connection_factory(handle: &Handle, consensus_params: ConsensusParams, db: db::SharedStore) -> p2p::LocalSyncNodeRef {
|
||||
use synchronization_chain::Chain as SyncChain;
|
||||
use synchronization_executor::LocalSynchronizationTaskExecutor as SyncExecutor;
|
||||
use local_node::LocalNode as SyncNode;
|
||||
|
|
|
@ -101,7 +101,7 @@ pub struct Chain {
|
|||
/// Best storage block (stored for optimizations)
|
||||
best_storage_block: db::BestBlock,
|
||||
/// Local blocks storage
|
||||
storage: Arc<db::Store>,
|
||||
storage: db::SharedStore,
|
||||
/// In-memory queue of blocks hashes
|
||||
hash_chain: HashQueueChain,
|
||||
/// In-memory queue of blocks headers
|
||||
|
@ -134,7 +134,7 @@ impl BlockState {
|
|||
|
||||
impl Chain {
|
||||
/// Create new `Chain` with given storage
|
||||
pub fn new(storage: Arc<db::Store>) -> Self {
|
||||
pub fn new(storage: db::SharedStore) -> Self {
|
||||
// we only work with storages with genesis block
|
||||
let genesis_block_hash = storage.block_hash(0)
|
||||
.expect("storage with genesis block is required");
|
||||
|
@ -165,7 +165,7 @@ impl Chain {
|
|||
}
|
||||
|
||||
/// Get storage
|
||||
pub fn storage(&self) -> Arc<db::Store> {
|
||||
pub fn storage(&self) -> db::SharedStore {
|
||||
self.storage.clone()
|
||||
}
|
||||
|
||||
|
@ -666,6 +666,7 @@ mod tests {
|
|||
use primitives::hash::H256;
|
||||
use devtools::RandomTempPath;
|
||||
use test_data;
|
||||
use db::BlockStapler;
|
||||
|
||||
#[test]
|
||||
fn chain_empty() {
|
||||
|
|
|
@ -1114,12 +1114,12 @@ pub mod tests {
|
|||
use db;
|
||||
use devtools::RandomTempPath;
|
||||
|
||||
fn create_disk_storage() -> Arc<db::Store> {
|
||||
fn create_disk_storage() -> db::SharedStore {
|
||||
let path = RandomTempPath::create_dir();
|
||||
Arc::new(db::Storage::new(path.as_path()).unwrap())
|
||||
}
|
||||
|
||||
fn create_sync(storage: Option<Arc<db::Store>>) -> (Core, Handle, Arc<Mutex<DummyTaskExecutor>>, ChainRef, Arc<Mutex<SynchronizationClient<DummyTaskExecutor>>>) {
|
||||
fn create_sync(storage: Option<db::SharedStore>) -> (Core, Handle, Arc<Mutex<DummyTaskExecutor>>, ChainRef, Arc<Mutex<SynchronizationClient<DummyTaskExecutor>>>) {
|
||||
let event_loop = event_loop();
|
||||
let handle = event_loop.handle();
|
||||
let storage = match storage {
|
||||
|
|
Loading…
Reference in New Issue