diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index c6acc1280..e971711e0 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -20,6 +20,7 @@ use common::*; use rlp::*; use hashdb::*; use memorydb::*; +use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, VERSION_KEY}; use super::traits::JournalDB; use kvdb::{Database, DBTransaction, DatabaseConfig}; #[cfg(test)] @@ -38,17 +39,14 @@ pub struct ArchiveDB { latest_era: Option, } -// all keys must be at least 12 bytes -const LATEST_ERA_KEY : [u8; 12] = [ b'l', b'a', b's', b't', 0, 0, 0, 0, 0, 0, 0, 0 ]; -const VERSION_KEY : [u8; 12] = [ b'j', b'v', b'e', b'r', 0, 0, 0, 0, 0, 0, 0, 0 ]; const DB_VERSION : u32 = 0x103; impl ArchiveDB { /// Create a new instance from file pub fn new(path: &str) -> ArchiveDB { let opts = DatabaseConfig { - //use 12 bytes as prefix, this must match account_db prefix - prefix_size: Some(12), + // this must match account_db prefix + prefix_size: Some(DB_PREFIX_LEN), max_open_files: 256, }; let backing = Database::open(&opts, path).unwrap_or_else(|e| { diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index 7cb117447..4d897e3db 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -20,6 +20,7 @@ use common::*; use rlp::*; use hashdb::*; use memorydb::*; +use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, VERSION_KEY}; use super::traits::JournalDB; use kvdb::{Database, DBTransaction, DatabaseConfig}; #[cfg(test)] @@ -67,9 +68,6 @@ pub struct EarlyMergeDB { latest_era: Option, } -// all keys must be at least 12 bytes -const LATEST_ERA_KEY : [u8; 12] = [ b'l', b'a', b's', b't', 0, 0, 0, 0, 0, 0, 0, 0 ]; -const VERSION_KEY : [u8; 12] = [ b'j', b'v', b'e', b'r', 0, 0, 0, 0, 0, 0, 0, 0 ]; const DB_VERSION : u32 = 0x003; const PADDING : [u8; 10] = [ 0u8; 10 ]; @@ -77,8 +75,8 @@ impl EarlyMergeDB { /// Create a new instance from file pub fn new(path: &str) -> EarlyMergeDB { let opts = DatabaseConfig { - //use 12 bytes as prefix, this must match account_db prefix - prefix_size: Some(12), + // this must match account_db prefix + prefix_size: Some(DB_PREFIX_LEN), max_open_files: 256, }; let backing = Database::open(&opts, path).unwrap_or_else(|e| { diff --git a/util/src/journaldb/mod.rs b/util/src/journaldb/mod.rs index 6e389b3c0..9f242e950 100644 --- a/util/src/journaldb/mod.rs +++ b/util/src/journaldb/mod.rs @@ -79,3 +79,8 @@ pub fn new(path: &str, algorithm: Algorithm) -> Box { Algorithm::RefCounted => Box::new(refcounteddb::RefCountedDB::new(path)), } } + +// all keys must be at least 12 bytes +const DB_PREFIX_LEN : usize = 12; +const LATEST_ERA_KEY : [u8; DB_PREFIX_LEN] = [ b'l', b'a', b's', b't', 0, 0, 0, 0, 0, 0, 0, 0 ]; +const VERSION_KEY : [u8; DB_PREFIX_LEN] = [ b'j', b'v', b'e', b'r', 0, 0, 0, 0, 0, 0, 0, 0 ]; diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index 86d8d5c4d..435dd7880 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -20,6 +20,7 @@ use common::*; use rlp::*; use hashdb::*; use memorydb::*; +use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, VERSION_KEY}; use kvdb::{Database, DBTransaction, DatabaseConfig}; #[cfg(test)] use std::env; @@ -92,9 +93,6 @@ impl Clone for OverlayRecentDB { } } -// all keys must be at least 12 bytes -const LATEST_ERA_KEY : [u8; 12] = [ b'l', b'a', b's', b't', 0, 0, 0, 0, 0, 0, 0, 0 ]; -const VERSION_KEY : [u8; 12] = [ b'j', b'v', b'e', b'r', 0, 0, 0, 0, 0, 0, 0, 0 ]; const DB_VERSION : u32 = 0x203; const PADDING : [u8; 10] = [ 0u8; 10 ]; @@ -107,8 +105,8 @@ impl OverlayRecentDB { /// Create a new instance from file pub fn from_prefs(path: &str) -> OverlayRecentDB { let opts = DatabaseConfig { - //use 12 bytes as prefix, this must match account_db prefix - prefix_size: Some(12), + // this must match account_db prefix + prefix_size: Some(DB_PREFIX_LEN), max_open_files: 256, }; let backing = Database::open(&opts, path).unwrap_or_else(|e| { diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index 7f24a729c..3bcb0faaf 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -20,6 +20,7 @@ use common::*; use rlp::*; use hashdb::*; use overlaydb::*; +use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, VERSION_KEY}; use super::traits::JournalDB; use kvdb::{Database, DBTransaction, DatabaseConfig}; #[cfg(test)] @@ -40,8 +41,6 @@ pub struct RefCountedDB { removes: Vec, } -const LATEST_ERA_KEY : [u8; 12] = [ b'l', b'a', b's', b't', 0, 0, 0, 0, 0, 0, 0, 0 ]; -const VERSION_KEY : [u8; 12] = [ b'j', b'v', b'e', b'r', 0, 0, 0, 0, 0, 0, 0, 0 ]; const DB_VERSION : u32 = 0x200; const PADDING : [u8; 10] = [ 0u8; 10 ]; @@ -49,8 +48,8 @@ impl RefCountedDB { /// Create a new instance given a `backing` database. pub fn new(path: &str) -> RefCountedDB { let opts = DatabaseConfig { - //use 12 bytes as prefix, this must match account_db prefix - prefix_size: Some(12), + // this must match account_db prefix + prefix_size: Some(DB_PREFIX_LEN), max_open_files: 256, }; let backing = Database::open(&opts, path).unwrap_or_else(|e| {