removed unused functions and warnings
This commit is contained in:
parent
fb4901cbcf
commit
552fe1fb4b
@ -484,7 +484,7 @@ impl BlockChain {
|
||||
|
||||
/// Transforms block into WriteBatch that may be written into database
|
||||
/// Additionally, if it's new best block it returns new best block object.
|
||||
fn block_to_extras_insert_batch(&self, bytes: &[u8], receipts: &[Receipt]) -> (WriteBatch, Option<BestBlock>, BlockDetails) {
|
||||
fn block_to_extras_insert_batch(&self, bytes: &[u8], _receipts: &[Receipt]) -> (WriteBatch, Option<BestBlock>, BlockDetails) {
|
||||
// create views onto rlp
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
@ -616,11 +616,6 @@ impl BlockChain {
|
||||
self.best_block.read().unwrap().total_difficulty
|
||||
}
|
||||
|
||||
/// Get the transactions' log blooms of a block.
|
||||
fn log_blooms(&self, hash: &H256) -> Option<BlockLogBlooms> {
|
||||
self.query_extras(hash, &self.block_logs)
|
||||
}
|
||||
|
||||
/// Get block blooms.
|
||||
fn blocks_blooms(&self, hash: &H256) -> Option<BlocksBlooms> {
|
||||
self.query_extras(hash, &self.blocks_blooms)
|
||||
|
@ -57,7 +57,6 @@
|
||||
//!
|
||||
use std::collections::{HashMap};
|
||||
use util::hash::*;
|
||||
use util::sha3::*;
|
||||
use chainfilter::{BloomIndex, FilterDataSource};
|
||||
use chainfilter::indexer::Indexer;
|
||||
|
||||
@ -89,10 +88,12 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
|
||||
None => return None,
|
||||
Some(level_bloom) => match level {
|
||||
// if we are on the lowest level
|
||||
// take the value, exclude to_block
|
||||
0 if offset < to_block => return Some(vec![offset]),
|
||||
0 => return match offset < to_block {
|
||||
// take the value if its smaller than to_block
|
||||
true => Some(vec![offset]),
|
||||
// return None if it is is equal to to_block
|
||||
0 => return None,
|
||||
false => None
|
||||
},
|
||||
// return None if current level doesnt contain given bloom
|
||||
_ if !level_bloom.contains(bloom) => return None,
|
||||
// continue processing && go down
|
||||
@ -135,65 +136,6 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
|
||||
result
|
||||
}
|
||||
|
||||
/// Adds new blooms starting from block number.
|
||||
pub fn add_blooms(&self, blooms: &[H2048], block_number: usize) -> HashMap<BloomIndex, H2048> {
|
||||
let mut result: HashMap<BloomIndex, H2048> = HashMap::new();
|
||||
|
||||
for level in 0..self.indexer.levels() {
|
||||
for i in 0..blooms.len() {
|
||||
let bloom_index = self.indexer.bloom_index(block_number + i, level);
|
||||
let is_new_bloom = match result.get_mut(&bloom_index) {
|
||||
|
||||
// it was already modified
|
||||
Some(to_shift) => {
|
||||
*to_shift = &blooms[i] | to_shift;
|
||||
false
|
||||
}
|
||||
None => true,
|
||||
};
|
||||
|
||||
// it hasn't been modified yet
|
||||
if is_new_bloom {
|
||||
let new_bloom = match self.data_source.bloom_at_index(&bloom_index) {
|
||||
Some(ref old_bloom) => old_bloom | &blooms[i],
|
||||
None => blooms[i].clone(),
|
||||
};
|
||||
result.insert(bloom_index, new_bloom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// Resets bloom at level 0 and forces rebuild on higher levels.
|
||||
pub fn reset_bloom(&self, bloom: &H2048, block_number: usize) -> HashMap<BloomIndex, H2048> {
|
||||
let mut result: HashMap<BloomIndex, H2048> = HashMap::new();
|
||||
|
||||
let mut reset_index = self.indexer.bloom_index(block_number, 0);
|
||||
result.insert(reset_index.clone(), bloom.clone());
|
||||
|
||||
for level in 1..self.indexer.levels() {
|
||||
let index = self.indexer.bloom_index(block_number, level);
|
||||
// get all bloom indexes that were used to construct this bloom
|
||||
let lower_indexes = self.indexer.lower_level_bloom_indexes(&index);
|
||||
let new_bloom = lower_indexes.into_iter()
|
||||
// skip reseted one
|
||||
.filter(|li| li != &reset_index)
|
||||
// get blooms for these indexes
|
||||
.map(|li| self.data_source.bloom_at_index(&li))
|
||||
// filter existing ones
|
||||
.filter_map(|b| b)
|
||||
// BitOr all of them
|
||||
.fold(H2048::new(), |acc, bloom| acc | bloom);
|
||||
|
||||
reset_index = index.clone();
|
||||
result.insert(index, &new_bloom | bloom);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// Resets blooms at level 0 and forces rebuild on higher levels.
|
||||
pub fn reset_chain_head(&self, blooms: &[H2048], block_number: usize, old_highest_block: usize) -> HashMap<BloomIndex, H2048> {
|
||||
let mut result: HashMap<BloomIndex, H2048> = HashMap::new();
|
||||
@ -233,25 +175,6 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
|
||||
result
|
||||
}
|
||||
|
||||
/// Sets lowest level bloom to 0 and forces rebuild on higher levels.
|
||||
pub fn clear_bloom(&self, block_number: usize) -> HashMap<BloomIndex, H2048> {
|
||||
self.reset_bloom(&H2048::new(), block_number)
|
||||
}
|
||||
|
||||
/// Returns numbers of blocks that may contain Address.
|
||||
pub fn blocks_with_address(&self, address: &Address, from_block: usize, to_block: usize) -> Vec<usize> {
|
||||
let mut bloom = H2048::new();
|
||||
bloom.shift_bloomed(&address.sha3());
|
||||
self.blocks_with_bloom(&bloom, from_block, to_block)
|
||||
}
|
||||
|
||||
/// Returns numbers of blocks that may contain Topic.
|
||||
pub fn blocks_with_topic(&self, topic: &H256, from_block: usize, to_block: usize) -> Vec<usize> {
|
||||
let mut bloom = H2048::new();
|
||||
bloom.shift_bloomed(&topic.sha3());
|
||||
self.blocks_with_bloom(&bloom, from_block, to_block)
|
||||
}
|
||||
|
||||
/// Returns numbers of blocks that may log bloom.
|
||||
pub fn blocks_with_bloom(&self, bloom: &H2048, from_block: usize, to_block: usize) -> Vec<usize> {
|
||||
let mut result = vec![];
|
||||
|
@ -47,6 +47,12 @@ impl FilterDataSource for MemoryCache {
|
||||
}
|
||||
}
|
||||
|
||||
fn topic_to_bloom(topic: &H256) -> H2048 {
|
||||
let mut bloom = H2048::new();
|
||||
bloom.shift_bloomed(&topic.sha3());
|
||||
bloom
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_topic_basic_search() {
|
||||
let index_size = 16;
|
||||
@ -58,9 +64,7 @@ fn test_topic_basic_search() {
|
||||
let modified_blooms = {
|
||||
let filter = ChainFilter::new(&cache, index_size, bloom_levels);
|
||||
let block_number = 23;
|
||||
let mut bloom = H2048::new();
|
||||
bloom.shift_bloomed(&topic.sha3());
|
||||
filter.add_bloom(&bloom, block_number)
|
||||
filter.add_bloom(&topic_to_bloom(&topic), block_number)
|
||||
};
|
||||
|
||||
// number of modified blooms should always be equal number of levels
|
||||
@ -69,27 +73,27 @@ fn test_topic_basic_search() {
|
||||
|
||||
{
|
||||
let filter = ChainFilter::new(&cache, index_size, bloom_levels);
|
||||
let blocks = filter.blocks_with_topic(&topic, 0, 100);
|
||||
let blocks = filter.blocks_with_bloom(&topic_to_bloom(&topic), 0, 100);
|
||||
assert_eq!(blocks.len(), 1);
|
||||
assert_eq!(blocks[0], 23);
|
||||
}
|
||||
|
||||
{
|
||||
let filter = ChainFilter::new(&cache, index_size, bloom_levels);
|
||||
let blocks = filter.blocks_with_topic(&topic, 0, 23);
|
||||
let blocks = filter.blocks_with_bloom(&topic_to_bloom(&topic), 0, 23);
|
||||
assert_eq!(blocks.len(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
let filter = ChainFilter::new(&cache, index_size, bloom_levels);
|
||||
let blocks = filter.blocks_with_topic(&topic, 23, 24);
|
||||
let blocks = filter.blocks_with_bloom(&topic_to_bloom(&topic), 23, 24);
|
||||
assert_eq!(blocks.len(), 1);
|
||||
assert_eq!(blocks[0], 23);
|
||||
}
|
||||
|
||||
{
|
||||
let filter = ChainFilter::new(&cache, index_size, bloom_levels);
|
||||
let blocks = filter.blocks_with_topic(&topic, 24, 100);
|
||||
let blocks = filter.blocks_with_bloom(&topic_to_bloom(&topic), 24, 100);
|
||||
assert_eq!(blocks.len(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ mod tests {
|
||||
self.numbers.get(&index).cloned()
|
||||
}
|
||||
|
||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber> {
|
||||
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockNumber, _to_block: BlockNumber) -> Vec<BlockNumber> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user