Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

new blooms database #8712

Merged
merged 44 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
343b298
new blooms database
debris May 25, 2018
b9ac847
Merge branch 'master' into new-blooms-db
debris May 25, 2018
2eb233b
fixed conflict in Cargo.lock
debris May 25, 2018
f55ee49
removed bloomchain
debris May 25, 2018
94dfcd4
cleanup in progress
debris May 25, 2018
88aa4ff
Merge branch 'master' into new-blooms-db
debris May 26, 2018
0da3c9b
all tests passing in trace db with new blooms-db
debris May 26, 2018
0fb7b95
added trace_blooms to BlockChainDB interface, fixed db flushing
debris May 26, 2018
c8b30a4
Merge branch 'master' into new-blooms-db
debris May 30, 2018
975fdcb
Merge branch 'master' into new-blooms-db
debris May 31, 2018
24a6ba2
BlockChainDB no longer exposes RwLock in the interface
debris May 31, 2018
c321556
Merge branch 'master' into new-blooms-db
debris Jun 1, 2018
7fa05cd
automatically flush blooms-db after every insert
debris Jun 1, 2018
979ed33
blooms-db uses io::BufReader to read files, wrap blooms-db into Mutex…
debris Jun 1, 2018
77f0af8
fix json_tests
debris Jun 1, 2018
6367cea
blooms-db can filter multiple possibilities at the same time
debris Jun 1, 2018
6a806a1
removed enum trace/db.rs CacheId
debris Jun 1, 2018
65f9f91
lint fixes
debris Jun 1, 2018
ffd5a2a
fixed tests
debris Jun 1, 2018
1781d4a
Merge branch 'master' into new-blooms-db
debris Jun 2, 2018
646957a
Merge branch 'master' into new-blooms-db
debris Jun 4, 2018
fd06dca
kvdb-rocksdb uses fs-swap crate
debris Jun 4, 2018
bac4638
update Cargo.lock
debris Jun 4, 2018
db2740e
use fs::rename
debris Jun 5, 2018
50aa947
fixed failing test on linux
debris Jun 5, 2018
8f130b5
Merge branch 'master' into fs-swap
debris Jun 9, 2018
7edca53
fix tests
debris Jun 12, 2018
7e48afd
Merge branch 'master' into fs-swap
debris Jun 12, 2018
914aec5
use fs_swap
debris Jun 12, 2018
dc2e02a
Merge branch 'master' into fs-swap
debris Jun 12, 2018
3bc7a8c
fixed failing test on linux
debris Jun 12, 2018
bfc744b
cleanup after swap
debris Jun 13, 2018
41e5eb1
Merge branch 'master' into new-blooms-db
debris Jun 13, 2018
fdc943a
fix tests
debris Jun 13, 2018
249c368
Merge branch 'master' into new-blooms-db
debris Jun 14, 2018
f82f599
fixed osx permissions
debris Jun 14, 2018
1cc78f6
Merge branch 'fix_osx_permissions' into new-blooms-db
debris Jun 14, 2018
59f0fd3
simplify parity database opening functions
debris Jun 14, 2018
447950e
added migration to blooms-db
debris Jun 14, 2018
9894a16
Merge branch 'master' into new-blooms-db
debris Jun 20, 2018
f37f5e7
address @niklasad1 grumbles
debris Jun 20, 2018
26c45cd
fix license and authors field of blooms-db Cargo.toml
debris Jun 20, 2018
28ad097
Merge branch 'fs-swap' into new-blooms-db
debris Jun 20, 2018
f1ead7d
restore blooms-db after snapshot
debris Jun 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,7 @@ mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use hash::keccak;
use kvdb::{KeyValueDB, DBTransaction};
use kvdb_memorydb;
use kvdb::{DBTransaction};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blocks around a single import

use ethereum_types::*;
use receipt::{Receipt, TransactionOutcome};
use blockchain::{BlockProvider, BlockChain, BlockChainDB, Config, ImportRoute};
Expand Down
1 change: 0 additions & 1 deletion ethcore/src/snapshot/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use engines::EthEngine;
use snapshot::{Error, ManifestData};

use ethereum_types::H256;
use kvdb::KeyValueDB;

mod authority;
mod work;
Expand Down
1 change: 0 additions & 1 deletion ethcore/src/snapshot/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use util_error::UtilError;
use bytes::Bytes;
use journaldb::Algorithm;
use kvdb::{KeyValueDB, KeyValueDBHandler};
use snappy;

/// Helper for removing directories in case of error.
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/snapshot/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use snapshot::io::{SnapshotReader, PackedWriter, PackedReader};
use tempdir::TempDir;
use rand::Rng;

use kvdb::{KeyValueDB, DBValue};
use kvdb::{DBValue};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blocks around a single import

use ethereum_types::H256;
use hashdb::HashDB;
use journaldb;
Expand Down
1 change: 0 additions & 1 deletion ethcore/src/snapshot/tests/proof_of_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use transaction::{Transaction, Action, SignedTransaction};
use tempdir::TempDir;

use ethereum_types::Address;
use kvdb_memorydb;
use test_helpers;

use_contract!(test_validator_set, "ValidatorSet", "res/contracts/test_validator_set.json");
Expand Down
4 changes: 1 addition & 3 deletions ethcore/src/snapshot/tests/proof_of_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

//! PoW block chunker and rebuilder tests.

use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use tempdir::TempDir;
use error::{Error, ErrorKind};
Expand All @@ -28,8 +27,7 @@ use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};

use parking_lot::Mutex;
use snappy;
use kvdb::{KeyValueDB, DBTransaction};
use kvdb_memorydb;
use kvdb::{DBTransaction};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blocks around a single import

use test_helpers;

const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { blocks: 30000, max_restore_blocks: 30000 };
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/snapshot/tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ use ids::BlockId;
use snapshot::service::{Service, ServiceParams};
use snapshot::{self, ManifestData, SnapshotService};
use spec::Spec;
use test_helpers::{self, generate_dummy_client_with_spec_and_data};
use test_helpers::{generate_dummy_client_with_spec_and_data};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blocks around a single import

use test_helpers_internal::restoration_db_handler;

use io::IoChannel;
use kvdb_rocksdb::{Database, DatabaseConfig};
use kvdb_rocksdb::{DatabaseConfig};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blocks around a single import


struct NoopDBRestore;

Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> Arc<Client> {

pub fn new_db() -> Arc<BlockChainDB> {
struct TestBlockChainDB {
blooms_dir: TempDir,
_blooms_dir: TempDir,
blooms: RwLock<blooms_db::Database>,
key_value: Arc<KeyValueDB>,
}
Expand All @@ -279,7 +279,7 @@ pub fn new_db() -> Arc<BlockChainDB> {

let db = TestBlockChainDB {
blooms: RwLock::new(blooms_db::Database::open(tempdir.path()).unwrap()),
blooms_dir: tempdir,
_blooms_dir: tempdir,
key_value: Arc::new(::kvdb_memorydb::create(::db::NUM_COLUMNS.unwrap()))
};

Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/test_helpers_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use std::path::Path;
use std::sync::Arc;
use parking_lot::RwLock;
use kvdb::{KeyValueDB, KeyValueDBHandler};
use kvdb::{KeyValueDB};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blocks around a single import

use kvdb_rocksdb::{Database, DatabaseConfig};
use blockchain::{BlockChainDBHandler, BlockChainDB};
use blooms_db;
Expand Down
6 changes: 0 additions & 6 deletions ethcore/src/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use test_helpers::{
};
use types::filter::Filter;
use ethereum_types::{U256, Address};
use kvdb_rocksdb::{Database, DatabaseConfig};
use miner::Miner;
use spec::Spec;
use views::BlockView;
Expand All @@ -43,10 +42,7 @@ use test_helpers;
#[test]
fn imports_from_empty() {
let db = test_helpers::new_db();
//let tempdir = TempDir::new("").unwrap();
let spec = Spec::new_test();
//let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
//let client_db = Arc::new(Database::open(&db_config, tempdir.path().to_str().unwrap()).unwrap());

let client = Client::new(
ClientConfig::default(),
Expand All @@ -64,8 +60,6 @@ fn should_return_registrar() {
let db = test_helpers::new_db();
let tempdir = TempDir::new("").unwrap();
let spec = ethereum::new_morden(&tempdir.path().to_owned());
//let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
//let client_db = Arc::new(Database::open(&db_config, tempdir.path().to_str().unwrap()).unwrap());

let client = Client::new(
ClientConfig::default(),
Expand Down
2 changes: 0 additions & 2 deletions ethcore/src/tests/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

//! Client tests of tracing

use tempdir::TempDir;
use ethkey::KeyPair;
use hash::keccak;
use block::*;
Expand All @@ -26,7 +25,6 @@ use spec::*;
use client::*;
use test_helpers::get_temp_state_db;
use client::{BlockChainClient, Client, ClientConfig};
use kvdb_rocksdb::{Database, DatabaseConfig};
use std::sync::Arc;
use header::Header;
use miner::Miner;
Expand Down
50 changes: 24 additions & 26 deletions ethcore/src/trace/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! Trace database.
use std::ops::Deref;
use std::collections::{HashMap, VecDeque};
use std::collections::{HashMap, BTreeSet, VecDeque};
use std::sync::Arc;
use blockchain::{BlockChainDB};
use heapsize::HeapSizeOf;
use ethereum_types::{H256, H264};
use kvdb::{KeyValueDB, DBTransaction};
use kvdb::{DBTransaction};
use parking_lot::RwLock;
use header::BlockNumber;
use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras};
Expand Down Expand Up @@ -83,7 +82,6 @@ impl<T> TraceDB<T> where T: DatabaseExtras {

TraceDB {
traces: RwLock::new(HashMap::new()),
//blooms: RwLock::new(HashMap::new()),
cache_manager: RwLock::new(CacheManager::new(config.pref_cache_size, config.max_cache_size, 10 * 1024)),
tracesdb: tracesdb,
enabled: config.enabled,
Expand All @@ -93,8 +91,6 @@ impl<T> TraceDB<T> where T: DatabaseExtras {

fn cache_size(&self) -> usize {
self.traces.read().heap_size_of_children()
//let blooms = self.blooms.read().heap_size_of_children();
//traces + blooms
}

/// Let the cache system know that a cacheable item has been used.
Expand All @@ -108,18 +104,15 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
let current_size = self.cache_size();

let mut traces = self.traces.write();
//let mut blooms = self.blooms.write();
let mut cache_manager = self.cache_manager.write();

cache_manager.collect_garbage(current_size, | ids | {
for id in &ids {
match *id {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if let instead of match of a single pattern?

CacheId::Trace(ref h) => { traces.remove(h); },
//CacheId::Bloom(ref h) => { blooms.remove(h); },
}
}
traces.shrink_to_fit();
//blooms.shrink_to_fit();

traces.heap_size_of_children()
});
Expand Down Expand Up @@ -211,8 +204,6 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
// now let's rebuild the blooms
if !request.enacted.is_empty() {
let range_start = request.block_number + 1 - request.enacted.len() as u64;
//let range_end = range_start + request.retracted;
//let replaced_range = range_start..range_end;
let enacted_blooms: Vec<_> = request.enacted
.iter()
// all traces are expected to be found here. That's why `expect` has been used
Expand Down Expand Up @@ -324,19 +315,25 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
}

fn filter(&self, filter: &Filter) -> Vec<LocalizedTrace> {
unimplemented!();
//let chain = BloomGroupChain::new(self.bloom_config, self);
//let numbers = chain.filter(filter);
//numbers.into_iter()
//.flat_map(|n| {
//let number = n as BlockNumber;
//let hash = self.extras.block_hash(number)
//.expect("Expected to find block hash. Extras db is probably corrupted");
//let traces = self.traces(&hash)
//.expect("Expected to find a trace. Db is probably corrupted.");
//self.matching_block_traces(filter, traces, hash, number)
//})
//.collect()
let possibilities = filter.bloom_possibilities();
let blooms_db = self.tracesdb.blooms().read();
let numbers = possibilities.iter()
.map(|bloom| blooms_db.iterate_matching(filter.range.start as u64, filter.range.end as u64, bloom)?.collect::<Result<Vec<_>, _>>())
.collect::<Result<Vec<_>, _>>().expect("TODO: blooms pr")
.into_iter()
.flat_map(|n| n)
.collect::<BTreeSet<_>>();

numbers.into_iter()
.flat_map(|n| {
let number = n as BlockNumber;
let hash = self.extras.block_hash(number)
.expect("Expected to find block hash. Extras db is probably corrupted");
let traces = self.traces(&hash)
.expect("Expected to find a trace. Db is probably corrupted.");
self.matching_block_traces(filter, traces, hash, number)
})
.collect()
}
}

Expand All @@ -345,8 +342,7 @@ mod tests {
use std::collections::HashMap;
use std::sync::Arc;
use ethereum_types::{H256, U256, Address};
use kvdb::{DBTransaction, KeyValueDB};
use kvdb_memorydb;
use kvdb::{DBTransaction};
use header::BlockNumber;
use trace::{Config, TraceDB, Database as TraceDatabase, DatabaseExtras, ImportRequest};
use trace::{Filter, LocalizedTrace, AddressesFilter, TraceError};
Expand Down Expand Up @@ -542,6 +538,7 @@ mod tests {
let mut batch = DBTransaction::new();
tracedb.import(&mut batch, request);
db.key_value().write(batch).unwrap();
db.blooms().write().flush().unwrap();

let filter = Filter {
range: (1..1),
Expand All @@ -558,6 +555,7 @@ mod tests {
let mut batch = DBTransaction::new();
tracedb.import(&mut batch, request);
db.key_value().write(batch).unwrap();
db.blooms().write().flush().unwrap();

let filter = Filter {
range: (1..2),
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/trace/types/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct Filter {

impl Filter {
/// Returns combinations of each address.
fn bloom_possibilities(&self) -> Vec<Bloom> {
pub fn bloom_possibilities(&self) -> Vec<Bloom> {
self.to_address.with_blooms(self.from_address.blooms())
}

Expand Down