bloom refactor (#7475)

* ethereum-types refactor in progress

* ethereum-types refactor in progress

* ethereum-types refactor in progress

* ethereum-types refactor in progress

* ethereum-types refactor finished

* cleanup bloom mess

* simplify usage of Bloom in few places

* removed obsolete util/src/lib.rs

* removed commented out code

* ethereum-types 0.1.4

* updated ethereum-types and tiny-keccak
This commit is contained in:
Marek Kotewicz
2018-01-14 22:43:28 +01:00
committed by GitHub
parent e7f36665bb
commit 668d910c44
65 changed files with 2023 additions and 519 deletions

View File

@@ -17,10 +17,10 @@
//! Ethcore basic typenames.
/// Type for a 2048-bit log-bloom, as used by our blocks.
pub use ethereum_types::LogBloom;
use ethereum_types::Bloom;
/// Constant 2048-bit datum for 0. Often used as a default.
pub static ZERO_LOGBLOOM: LogBloom = ::ethereum_types::H2048([0x00; 256]);
pub static ZERO_LOGBLOOM: Bloom = Bloom([0x00; 256]);
/// Semantic boolean for when a seal/signature is included.
pub enum Seal {

View File

@@ -23,11 +23,11 @@ use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
use triehash::ordered_trie_root;
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
use ethereum_types::{H256, U256, Address};
use ethereum_types::{H256, U256, Address, Bloom};
use bytes::Bytes;
use unexpected::{Mismatch, OutOfBounds};
use basic_types::{LogBloom, Seal};
use basic_types::Seal;
use vm::{EnvInfo, LastHashes};
use engines::EthEngine;
use error::{Error, BlockError};
@@ -453,7 +453,7 @@ impl<'x> OpenBlock<'x> {
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
s.block.header.set_state_root(s.block.state.root().clone());
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
s.block.header.set_log_bloom(s.block.receipts.iter().fold(LogBloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
s.block.header.set_log_bloom(s.block.receipts.iter().fold(Bloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
s.block.header.set_gas_used(s.block.receipts.last().map_or(U256::zero(), |r| r.gas_used));
ClosedBlock {
@@ -486,7 +486,7 @@ impl<'x> OpenBlock<'x> {
}
s.block.header.set_state_root(s.block.state.root().clone());
s.block.header.set_log_bloom(s.block.receipts.iter().fold(LogBloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
s.block.header.set_log_bloom(s.block.receipts.iter().fold(Bloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
s.block.header.set_gas_used(s.block.receipts.last().map_or(U256::zero(), |r| r.gas_used));
LockedBlock {

View File

@@ -22,7 +22,7 @@ use std::mem;
use itertools::Itertools;
use bloomchain as bc;
use heapsize::HeapSizeOf;
use ethereum_types::{H256, H2048, U256};
use ethereum_types::{H256, Bloom, U256};
use parking_lot::{Mutex, RwLock};
use bytes::Bytes;
use rlp::*;
@@ -32,7 +32,7 @@ use transaction::*;
use views::*;
use log_entry::{LogEntry, LocalizedLogEntry};
use receipt::Receipt;
use blooms::{Bloom, BloomGroup};
use blooms::BloomGroup;
use blockchain::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData};
use blockchain::best_block::{BestBlock, BestAncientBlock};
use types::blockchain_info::BlockChainInfo;
@@ -149,7 +149,7 @@ pub trait BlockProvider {
}
/// Returns numbers of blocks containing given bloom.
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber>;
fn blocks_with_bloom(&self, bloom: &Bloom, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber>;
/// Returns logs matching given filter.
fn logs<F>(&self, blocks: Vec<BlockNumber>, matches: F, limit: Option<usize>) -> Vec<LocalizedLogEntry>
@@ -354,7 +354,7 @@ impl BlockProvider for BlockChain {
}
/// Returns numbers of blocks containing given bloom.
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber> {
fn blocks_with_bloom(&self, bloom: &Bloom, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber> {
let range = from_block as bc::Number..to_block as bc::Number;
let chain = bc::group::BloomGroupChain::new(self.blooms_config, self);
chain.with_bloom(&range, &Bloom::from(bloom.clone()).into())
@@ -2132,11 +2132,11 @@ mod tests {
#[test]
fn test_bloom_filter_simple() {
// TODO: From here
let bloom_b1: H2048 = "00000020000000000000000000000000000000000000000002000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000400000000000000000000002000".into();
let bloom_b1: Bloom = "00000020000000000000000000000000000000000000000002000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000400000000000000000000002000".into();
let bloom_b2: H2048 = "00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
let bloom_b2: Bloom = "00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
let bloom_ba: H2048 = "00000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
let bloom_ba: Bloom = "00000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
let mut canon_chain = ChainGenerator::default();
let mut finalizer = BlockFinalizer::default();

View File

@@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use rlp::*;
use ethereum_types::{H256, H2048};
use ethereum_types::{H256, Bloom};
use bytes::Bytes;
use header::Header;
use transaction::SignedTransaction;
@@ -51,7 +51,7 @@ impl Forkable for Block {
}
impl WithBloom for Block {
fn with_bloom(mut self, bloom: H2048) -> Self where Self: Sized {
fn with_bloom(mut self, bloom: Bloom) -> Self where Self: Sized {
self.header.set_log_bloom(bloom);
self
}

View File

@@ -14,15 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use ethereum_types::H2048;
use ethereum_types::Bloom as LogBloom;
pub trait WithBloom {
fn with_bloom(self, bloom: H2048) -> Self where Self: Sized;
fn with_bloom(self, bloom: LogBloom) -> Self where Self: Sized;
}
pub struct Bloom<'a, I> where I: 'a {
pub iter: &'a mut I,
pub bloom: H2048,
pub bloom: LogBloom,
}
impl<'a, I> Iterator for Bloom<'a, I> where I: Iterator, <I as Iterator>::Item: WithBloom {

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use ethereum_types::{H2048, U256};
use ethereum_types::{Bloom as LogBloom, U256};
use bytes::Bytes;
use header::BlockNumber;
use transaction::SignedTransaction;
@@ -30,7 +30,7 @@ pub trait ChainIterator: Iterator + Sized {
/// Blocks generated by fork will have lower difficulty than current chain.
fn fork(&self, fork_number: usize) -> Fork<Self> where Self: Clone;
/// Should be called to make every consecutive block have given bloom.
fn with_bloom(&mut self, bloom: H2048) -> Bloom<Self>;
fn with_bloom(&mut self, bloom: LogBloom) -> Bloom<Self>;
/// Should be called to make every consecutive block have given transaction.
fn with_transaction(&mut self, transaction: SignedTransaction) -> Transaction<Self>;
/// Should be called to complete block. Without complete, block may have incorrect hash.
@@ -47,7 +47,7 @@ impl<I> ChainIterator for I where I: Iterator + Sized {
}
}
fn with_bloom(&mut self, bloom: H2048) -> Bloom<Self> {
fn with_bloom(&mut self, bloom: LogBloom) -> Bloom<Self> {
Bloom {
iter: self,
bloom: bloom
@@ -111,7 +111,7 @@ impl Iterator for ChainGenerator {
}
mod tests {
use ethereum_types::{H256, H2048};
use ethereum_types::{H256, Bloom as LogBloom};
use views::BlockView;
use blockchain::generator::{ChainIterator, ChainGenerator, BlockFinalizer};
@@ -150,7 +150,7 @@ mod tests {
#[test]
fn with_bloom_generator() {
let bloom = H2048([0x1; 256]);
let bloom = LogBloom([0x1; 256]);
let mut gen = ChainGenerator::default();
let mut finalizer = BlockFinalizer::default();

View File

@@ -1,49 +0,0 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use bloomchain as bc;
use heapsize::HeapSizeOf;
use basic_types::LogBloom;
/// Helper structure representing bloom of the trace.
#[derive(Debug, Clone, RlpEncodableWrapper, RlpDecodableWrapper)]
pub struct Bloom(LogBloom);
impl From<LogBloom> for Bloom {
fn from(bloom: LogBloom) -> Self {
Bloom(bloom)
}
}
impl From<bc::Bloom> for Bloom {
fn from(bloom: bc::Bloom) -> Self {
let bytes: [u8; 256] = bloom.into();
Bloom(LogBloom::from(bytes))
}
}
impl Into<bc::Bloom> for Bloom {
fn into(self) -> bc::Bloom {
let log = self.0;
bc::Bloom::from(log.0)
}
}
impl HeapSizeOf for Bloom {
fn heap_size_of_children(&self) -> usize {
0
}
}

View File

@@ -15,12 +15,11 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use bloomchain::group as bc;
use rlp::*;
use heapsize::HeapSizeOf;
use super::Bloom;
use ethereum_types::Bloom;
/// Represents group of X consecutive blooms.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, RlpEncodableWrapper, RlpDecodableWrapper)]
pub struct BloomGroup {
blooms: Vec<Bloom>,
}
@@ -51,22 +50,6 @@ impl Into<bc::BloomGroup> for BloomGroup {
}
}
impl Decodable for BloomGroup {
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
let blooms = rlp.as_list()?;
let group = BloomGroup {
blooms: blooms
};
Ok(group)
}
}
impl Encodable for BloomGroup {
fn rlp_append(&self, s: &mut RlpStream) {
s.append_list(&self.blooms);
}
}
impl HeapSizeOf for BloomGroup {
fn heap_size_of_children(&self) -> usize {
self.blooms.heap_size_of_children()

View File

@@ -16,10 +16,8 @@
//! Bridge between bloomchain crate types and ethcore.
mod bloom;
mod bloom_group;
mod group_position;
pub use self::bloom::Bloom;
pub use self::bloom_group::BloomGroup;
pub use self::group_position::GroupPosition;

View File

@@ -30,7 +30,7 @@ use views;
use hash::keccak;
use heapsize::HeapSizeOf;
use ethereum_types::{H256, H2048, U256, Address};
use ethereum_types::{H256, Bloom, U256, Address};
use rlp::Rlp;
/// Owning header view.
@@ -86,7 +86,7 @@ impl Header {
pub fn receipts_root(&self) -> H256 { self.view().receipts_root() }
/// Returns the block log bloom
pub fn log_bloom(&self) -> H2048 { self.view().log_bloom() }
pub fn log_bloom(&self) -> Bloom { self.view().log_bloom() }
/// Difficulty of this block
pub fn difficulty(&self) -> U256 { self.view().difficulty() }
@@ -232,7 +232,7 @@ impl Block {
pub fn receipts_root(&self) -> H256 { self.header_view().receipts_root() }
/// Returns the block log bloom
pub fn log_bloom(&self) -> H2048 { self.header_view().log_bloom() }
pub fn log_bloom(&self) -> Bloom { self.header_view().log_bloom() }
/// Difficulty of this block
pub fn difficulty(&self) -> U256 { self.header_view().difficulty() }

View File

@@ -21,7 +21,7 @@ use futures::Future;
use native_contracts::ValidatorSet as Provider;
use hash::keccak;
use ethereum_types::{H160, H256, U256, Address};
use ethereum_types::{H160, H256, U256, Address, Bloom};
use parking_lot::{Mutex, RwLock};
use bytes::Bytes;
@@ -30,7 +30,6 @@ use unexpected::Mismatch;
use rlp::{UntrustedRlp, RlpStream};
use kvdb::DBValue;
use basic_types::LogBloom;
use client::EngineClient;
use machine::{AuxiliaryData, Call, EthereumMachine, AuxiliaryRequest};
use header::Header;
@@ -238,7 +237,7 @@ impl ValidatorSafeContract {
// produce the same bloom.
//
// The log data is an array of all new validator addresses.
fn expected_bloom(&self, header: &Header) -> LogBloom {
fn expected_bloom(&self, header: &Header) -> Bloom {
let topics = vec![*EVENT_NAME_HASH, *header.parent_hash()];
debug!(target: "engine", "Expected topics for header {}: {:?}",
@@ -253,7 +252,7 @@ impl ValidatorSafeContract {
// check receipts for log event. bloom should be `expected_bloom` for the
// header the receipts correspond to.
fn extract_from_event(&self, bloom: LogBloom, header: &Header, receipts: &[Receipt]) -> Option<SimpleList> {
fn extract_from_event(&self, bloom: Bloom, header: &Header, receipts: &[Receipt]) -> Option<SimpleList> {
let check_log = |log: &LogEntry| {
log.address == self.address &&
log.topics.len() == 2 &&

View File

@@ -18,14 +18,13 @@
use std::fmt;
use kvdb;
use ethereum_types::{H256, U256, Address};
use ethereum_types::{H256, U256, Address, Bloom};
use util_error::UtilError;
use snappy::InvalidInput;
use unexpected::{Mismatch, OutOfBounds};
use trie::TrieError;
use io::*;
use header::BlockNumber;
use basic_types::LogBloom;
use client::Error as ClientError;
use snapshot::Error as SnapshotError;
use engines::EngineError;
@@ -86,7 +85,7 @@ pub enum BlockError {
/// Timestamp header field is too far in future.
TemporarilyInvalid(OutOfBounds<u64>),
/// Log bloom header field is invalid.
InvalidLogBloom(Mismatch<LogBloom>),
InvalidLogBloom(Mismatch<Bloom>),
/// Parent hash field of header is invalid; this is an invalid error indicating a logic flaw in the codebase.
/// TODO: remove and favour an assert!/panic!.
InvalidParentHash(Mismatch<H256>),

View File

@@ -20,9 +20,9 @@ use std::cmp;
use std::cell::RefCell;
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP, keccak};
use heapsize::HeapSizeOf;
use ethereum_types::{H256, U256, Address};
use ethereum_types::{H256, U256, Address, Bloom};
use bytes::Bytes;
use basic_types::{LogBloom, ZERO_LOGBLOOM};
use basic_types::{ZERO_LOGBLOOM};
use time::get_time;
use rlp::*;
@@ -59,7 +59,7 @@ pub struct Header {
/// Block receipts root.
receipts_root: H256,
/// Block bloom.
log_bloom: LogBloom,
log_bloom: Bloom,
/// Gas used for contracts execution.
gas_used: U256,
/// Block gas limit.
@@ -146,7 +146,7 @@ impl Header {
/// Get the receipts root field of the header.
pub fn receipts_root(&self) -> &H256 { &self.receipts_root }
/// Get the log bloom field of the header.
pub fn log_bloom(&self) -> &LogBloom { &self.log_bloom }
pub fn log_bloom(&self) -> &Bloom { &self.log_bloom }
/// Get the transactions root field of the header.
pub fn transactions_root(&self) -> &H256 { &self.transactions_root }
/// Get the uncles hash field of the header.
@@ -180,7 +180,7 @@ impl Header {
/// Set the receipts root field of the header.
pub fn set_receipts_root(&mut self, a: H256) { self.receipts_root = a; self.note_dirty() }
/// Set the log bloom field of the header.
pub fn set_log_bloom(&mut self, a: LogBloom) { self.log_bloom = a; self.note_dirty() }
pub fn set_log_bloom(&mut self, a: Bloom) { self.log_bloom = a; self.note_dirty() }
/// Set the timestamp field of the header.
pub fn set_timestamp(&mut self, a: u64) { self.timestamp = a; self.note_dirty(); }
/// Set the timestamp field of the header to the current time.

View File

@@ -107,7 +107,7 @@ extern crate rustc_hex;
extern crate stats;
extern crate time;
extern crate using_queue;
extern crate bloomable;
extern crate table;
extern crate vm;
extern crate wasm;
extern crate memory_cache;

View File

@@ -21,7 +21,7 @@ use std::collections::BTreeMap;
use std::path::Path;
use std::sync::Arc;
use ethereum_types::{H256, H2048, U256, Address};
use ethereum_types::{H256, Bloom, U256, Address};
use memorydb::MemoryDB;
use bytes::Bytes;
use ethjson;
@@ -576,7 +576,7 @@ impl Spec {
header.set_extra_data(self.extra_data.clone());
header.set_state_root(self.state_root());
header.set_receipts_root(self.receipts_root.clone());
header.set_log_bloom(H2048::new().clone());
header.set_log_bloom(Bloom::default());
header.set_gas_used(self.gas_used.clone());
header.set_gas_limit(self.gas_limit.clone());
header.set_difficulty(self.difficulty.clone());

View File

@@ -1,77 +0,0 @@
use bloomchain::Bloom;
use bloomchain::group::{BloomGroup, GroupPosition};
use basic_types::LogBloom;
/// Helper structure representing bloom of the trace.
#[derive(Clone, RlpEncodableWrapper, RlpDecodableWrapper)]
pub struct BlockTracesBloom(LogBloom);
impl From<LogBloom> for BlockTracesBloom {
fn from(bloom: LogBloom) -> BlockTracesBloom {
BlockTracesBloom(bloom)
}
}
impl From<Bloom> for BlockTracesBloom {
fn from(bloom: Bloom) -> BlockTracesBloom {
let bytes: [u8; 256] = bloom.into();
BlockTracesBloom(LogBloom::from(bytes))
}
}
impl Into<Bloom> for BlockTracesBloom {
fn into(self) -> Bloom {
let log = self.0;
Bloom::from(log.0)
}
}
/// Represents group of X consecutive blooms.
#[derive(Clone, RlpEncodableWrapper, RlpDecodableWrapper)]
pub struct BlockTracesBloomGroup {
blooms: Vec<BlockTracesBloom>,
}
impl From<BloomGroup> for BlockTracesBloomGroup {
fn from(group: BloomGroup) -> Self {
let blooms = group.blooms
.into_iter()
.map(From::from)
.collect();
BlockTracesBloomGroup {
blooms: blooms
}
}
}
impl Into<BloomGroup> for BlockTracesBloomGroup {
fn into(self) -> BloomGroup {
let blooms = self.blooms
.into_iter()
.map(Into::into)
.collect();
BloomGroup {
blooms: blooms
}
}
}
/// Represents `BloomGroup` position in database.
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub struct TraceGroupPosition {
/// Bloom level.
pub level: u8,
/// Group index.
pub index: u32,
}
impl From<GroupPosition> for TraceGroupPosition {
fn from(p: GroupPosition) -> Self {
TraceGroupPosition {
level: p.level as u8,
index: p.index as u32,
}
}
}

View File

@@ -279,8 +279,6 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
} else {
self.traces(block_hash).expect("Traces database is incomplete.").bloom()
})
.map(blooms::Bloom::from)
.map(Into::into)
.collect();
let chain = BloomGroupChain::new(self.bloom_config, self);

View File

@@ -16,7 +16,6 @@
//! Tracing
mod bloom;
mod config;
mod db;
mod executive_tracer;

View File

@@ -17,11 +17,8 @@
//! Trace filters type definitions
use std::ops::Range;
use bloomchain::{Filter as BloomFilter, Bloom, Number};
use hash::keccak;
use ethereum_types::Address;
use bloomable::Bloomable;
use basic_types::LogBloom;
use bloomchain::{Filter as BloomFilter, Number};
use ethereum_types::{Address, Bloom, BloomInput};
use trace::flat::FlatTrace;
use super::trace::{Action, Res};
@@ -51,23 +48,27 @@ impl AddressesFilter {
}
/// Returns blooms of this addresses filter.
pub fn blooms(&self) -> Vec<LogBloom> {
pub fn blooms(&self) -> Vec<Bloom> {
match self.list.is_empty() {
true => vec![LogBloom::default()],
true => vec![Bloom::default()],
false => self.list.iter()
.map(|address| LogBloom::from_bloomed(&keccak(address)))
.map(|address| Bloom::from(BloomInput::Raw(address)))
.collect(),
}
}
/// Returns vector of blooms zipped with blooms of this addresses filter.
pub fn with_blooms(&self, blooms: Vec<LogBloom>) -> Vec<LogBloom> {
pub fn with_blooms(&self, blooms: Vec<Bloom>) -> Vec<Bloom> {
match self.list.is_empty() {
true => blooms,
false => blooms
.into_iter()
.flat_map(|bloom| self.list.iter()
.map(|address| bloom.with_bloomed(&keccak(address)))
.map(|address| {
let mut bloom = Bloom::from(bloom.0);
bloom.accrue(BloomInput::Raw(address));
bloom
})
.collect::<Vec<_>>())
.collect(),
}
@@ -102,7 +103,7 @@ impl BloomFilter for Filter {
impl Filter {
/// Returns combinations of each address.
fn bloom_possibilities(&self) -> Vec<LogBloom> {
fn bloom_possibilities(&self) -> Vec<Bloom> {
self.to_address.with_blooms(self.from_address.blooms())
}
@@ -138,9 +139,7 @@ impl Filter {
#[cfg(test)]
mod tests {
use ethereum_types::Address;
use hash::keccak;
use bloomable::Bloomable;
use ethereum_types::{Address, Bloom, BloomInput};
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
use trace::flat::FlatTrace;
use trace::{Filter, AddressesFilter, TraceError, RewardType};
@@ -155,7 +154,7 @@ mod tests {
};
let blooms = filter.bloom_possibilities();
assert_eq!(blooms, vec![Default::default()]);
assert_eq!(blooms, vec![Bloom::default()]);
}
#[test]
@@ -169,9 +168,9 @@ mod tests {
let blooms = filter.bloom_possibilities();
assert_eq!(blooms.len(), 1);
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
assert!(blooms[0].contains_bloomed(&keccak(Address::from(2))));
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(3))));
assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(2))));
assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(3))));
}
#[test]
@@ -185,8 +184,8 @@ mod tests {
let blooms = filter.bloom_possibilities();
assert_eq!(blooms.len(), 1);
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(2))));
assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(2))));
}
#[test]
@@ -200,8 +199,8 @@ mod tests {
let blooms = filter.bloom_possibilities();
assert_eq!(blooms.len(), 1);
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(2))));
assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(2))));
}
#[test]
@@ -215,25 +214,25 @@ mod tests {
let blooms = filter.bloom_possibilities();
assert_eq!(blooms.len(), 4);
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
assert!(blooms[0].contains_bloomed(&keccak(Address::from(2))));
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(3))));
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(4))));
assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(2))));
assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(3))));
assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(4))));
assert!(blooms[1].contains_bloomed(&keccak(Address::from(1))));
assert!(blooms[1].contains_bloomed(&keccak(Address::from(4))));
assert!(!blooms[1].contains_bloomed(&keccak(Address::from(2))));
assert!(!blooms[1].contains_bloomed(&keccak(Address::from(3))));
assert!(blooms[1].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(blooms[1].contains_input(BloomInput::Raw(&Address::from(4))));
assert!(!blooms[1].contains_input(BloomInput::Raw(&Address::from(2))));
assert!(!blooms[1].contains_input(BloomInput::Raw(&Address::from(3))));
assert!(blooms[2].contains_bloomed(&keccak(Address::from(2))));
assert!(blooms[2].contains_bloomed(&keccak(Address::from(3))));
assert!(!blooms[2].contains_bloomed(&keccak(Address::from(1))));
assert!(!blooms[2].contains_bloomed(&keccak(Address::from(4))));
assert!(blooms[2].contains_input(BloomInput::Raw(&Address::from(2))));
assert!(blooms[2].contains_input(BloomInput::Raw(&Address::from(3))));
assert!(!blooms[2].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(!blooms[2].contains_input(BloomInput::Raw(&Address::from(4))));
assert!(blooms[3].contains_bloomed(&keccak(Address::from(3))));
assert!(blooms[3].contains_bloomed(&keccak(Address::from(4))));
assert!(!blooms[3].contains_bloomed(&keccak(Address::from(1))));
assert!(!blooms[3].contains_bloomed(&keccak(Address::from(2))));
assert!(blooms[3].contains_input(BloomInput::Raw(&Address::from(3))));
assert!(blooms[3].contains_input(BloomInput::Raw(&Address::from(4))));
assert!(!blooms[3].contains_input(BloomInput::Raw(&Address::from(1))));
assert!(!blooms[3].contains_input(BloomInput::Raw(&Address::from(2))));
}
#[test]

View File

@@ -19,7 +19,7 @@
use std::collections::VecDeque;
use rlp::*;
use heapsize::HeapSizeOf;
use basic_types::LogBloom;
use ethereum_types::Bloom;
use super::trace::{Action, Res};
/// Trace localized in vector of traces produced by a single transaction.
@@ -41,7 +41,7 @@ pub struct FlatTrace {
impl FlatTrace {
/// Returns bloom of the trace.
pub fn bloom(&self) -> LogBloom {
pub fn bloom(&self) -> Bloom {
self.action.bloom() | self.result.bloom()
}
}
@@ -94,7 +94,7 @@ impl HeapSizeOf for FlatTransactionTraces {
impl FlatTransactionTraces {
/// Returns bloom of all traces in the collection.
pub fn bloom(&self) -> LogBloom {
pub fn bloom(&self) -> Bloom {
self.0.iter().fold(Default::default(), | bloom, trace | bloom | trace.bloom())
}
}
@@ -123,7 +123,7 @@ impl From<Vec<FlatTransactionTraces>> for FlatBlockTraces {
impl FlatBlockTraces {
/// Returns bloom of all traces in the block.
pub fn bloom(&self) -> LogBloom {
pub fn bloom(&self) -> Bloom {
self.0.iter().fold(Default::default(), | bloom, tx_traces | bloom | tx_traces.bloom())
}
}

View File

@@ -16,14 +16,11 @@
//! Tracing datatypes.
use ethereum_types::{U256, Address};
use ethereum_types::{U256, Address, Bloom, BloomInput};
use bytes::Bytes;
use hash::keccak;
use bloomable::Bloomable;
use rlp::*;
use vm::ActionParams;
use basic_types::LogBloom;
use evm::CallType;
use super::error::Error;
@@ -49,8 +46,8 @@ pub struct CreateResult {
impl CreateResult {
/// Returns bloom.
pub fn bloom(&self) -> LogBloom {
LogBloom::from_bloomed(&keccak(&self.address))
pub fn bloom(&self) -> Bloom {
BloomInput::Raw(&self.address).into()
}
}
@@ -87,9 +84,11 @@ impl From<ActionParams> for Call {
impl Call {
/// Returns call action bloom.
/// The bloom contains from and to addresses.
pub fn bloom(&self) -> LogBloom {
LogBloom::from_bloomed(&keccak(&self.from))
.with_bloomed(&keccak(&self.to))
pub fn bloom(&self) -> Bloom {
let mut bloom = Bloom::default();
bloom.accrue(BloomInput::Raw(&self.from));
bloom.accrue(BloomInput::Raw(&self.to));
bloom
}
}
@@ -120,8 +119,8 @@ impl From<ActionParams> for Create {
impl Create {
/// Returns bloom create action bloom.
/// The bloom contains only from address.
pub fn bloom(&self) -> LogBloom {
LogBloom::from_bloomed(&keccak(&self.from))
pub fn bloom(&self) -> Bloom {
BloomInput::Raw(&self.from).into()
}
}
@@ -167,8 +166,8 @@ pub struct Reward {
impl Reward {
/// Return reward action bloom.
pub fn bloom(&self) -> LogBloom {
LogBloom::from_bloomed(&keccak(&self.author))
pub fn bloom(&self) -> Bloom {
BloomInput::Raw(&self.author).into()
}
}
@@ -207,9 +206,11 @@ pub struct Suicide {
impl Suicide {
/// Return suicide action bloom.
pub fn bloom(&self) -> LogBloom {
LogBloom::from_bloomed(&keccak(self.address))
.with_bloomed(&keccak(self.refund_address))
pub fn bloom(&self) -> Bloom {
let mut bloom = Bloom::default();
bloom.accrue(BloomInput::Raw(&self.address));
bloom.accrue(BloomInput::Raw(&self.refund_address));
bloom
}
}
@@ -266,7 +267,7 @@ impl Decodable for Action {
impl Action {
/// Returns action bloom.
pub fn bloom(&self) -> LogBloom {
pub fn bloom(&self) -> Bloom {
match *self {
Action::Call(ref call) => call.bloom(),
Action::Create(ref create) => create.bloom(),
@@ -338,7 +339,7 @@ impl Decodable for Res {
impl Res {
/// Returns result bloom.
pub fn bloom(&self) -> LogBloom {
pub fn bloom(&self) -> Bloom {
match *self {
Res::Create(ref create) => create.bloom(),
Res::Call(_) | Res::FailedCall(_) | Res::FailedCreate(_) | Res::None => Default::default(),

View File

@@ -335,7 +335,7 @@ mod tests {
use super::*;
use std::collections::{BTreeMap, HashMap};
use ethereum_types::{H256, H2048, U256};
use ethereum_types::{H256, Bloom, U256};
use blockchain::extras::{BlockDetails, TransactionAddress, BlockReceipts};
use encoded;
use hash::keccak;
@@ -453,7 +453,7 @@ mod tests {
unimplemented!()
}
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockNumber, _to_block: BlockNumber) -> Vec<BlockNumber> {
fn blocks_with_bloom(&self, _bloom: &Bloom, _from_block: BlockNumber, _to_block: BlockNumber) -> Vec<BlockNumber> {
unimplemented!()
}

View File

@@ -17,7 +17,7 @@
//! View onto block header rlp
use hash::keccak;
use ethereum_types::{H256, H2048, U256, Address};
use ethereum_types::{H256, Bloom, U256, Address};
use bytes::Bytes;
use rlp::{self, Rlp};
use header::BlockNumber;
@@ -69,7 +69,7 @@ impl<'a> HeaderView<'a> {
pub fn receipts_root(&self) -> H256 { self.rlp.val_at(5) }
/// Returns block log bloom.
pub fn log_bloom(&self) -> H2048 { self.rlp.val_at(6) }
pub fn log_bloom(&self) -> Bloom { self.rlp.val_at(6) }
/// Returns block difficulty.
pub fn difficulty(&self) -> U256 { self.rlp.val_at(7) }
@@ -111,7 +111,7 @@ impl<'a> HeaderView<'a> {
mod tests {
use std::str::FromStr;
use rustc_hex::FromHex;
use ethereum_types::{H256, H2048, U256, Address};
use ethereum_types::{H256, Bloom, U256, Address};
use super::HeaderView;
#[test]
@@ -129,7 +129,7 @@ mod tests {
assert_eq!(view.state_root(), H256::from_str("5fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25").unwrap());
assert_eq!(view.transactions_root(), H256::from_str("88d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158").unwrap());
assert_eq!(view.receipts_root(), H256::from_str("07c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1").unwrap());
assert_eq!(view.log_bloom(), H2048::default());
assert_eq!(view.log_bloom(), Bloom::default());
assert_eq!(view.difficulty(), U256::from(0x02_00_80));
assert_eq!(view.number(), 3);
assert_eq!(view.gas_limit(), U256::from(0x2f_ef_ba));