mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 05:48:31 +00:00
Tidy beacon node runtime code
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user