Tidy beacon node runtime code

This commit is contained in:
Paul Hauner
2019-06-08 09:46:04 -04:00
parent 749f2fcb5f
commit fd6766c268
7 changed files with 59 additions and 40 deletions

View File

@@ -5,10 +5,14 @@ use leveldb::database::Database;
use leveldb::error::Error as LevelDBError;
use leveldb::options::{Options, ReadOptions, WriteOptions};
use std::path::Path;
use std::sync::Arc;
/// A wrapped leveldb database.
#[derive(Clone)]
pub struct LevelDB {
db: Database<BytesKey>,
// Note: this `Arc` is only included because of an artificial constraint by gRPC. Hopefully we
// can remove this one day.
db: Arc<Database<BytesKey>>,
}
impl LevelDB {
@@ -18,7 +22,7 @@ impl LevelDB {
options.create_if_missing = true;
let db = Database::open(path, options)?;
let db = Arc::new(Database::open(path, options)?);
Ok(Self { db })
}

View File

@@ -1,19 +1,23 @@
use super::{Error, Store};
use parking_lot::RwLock;
use std::collections::HashMap;
use std::sync::Arc;
type DBHashMap = HashMap<Vec<u8>, Vec<u8>>;
/// A thread-safe `HashMap` wrapper.
#[derive(Clone)]
pub struct MemoryStore {
db: RwLock<DBHashMap>,
// Note: this `Arc` is only included because of an artificial constraint by gRPC. Hopefully we
// can remove this one day.
db: Arc<RwLock<DBHashMap>>,
}
impl MemoryStore {
/// Create a new, empty database.
pub fn open() -> Self {
Self {
db: RwLock::new(HashMap::new()),
db: Arc::new(RwLock::new(HashMap::new())),
}
}