Merge branch 'master' into keccak_fn
This commit is contained in:
commit
94f717a255
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -302,6 +302,7 @@ dependencies = [
|
|||||||
"ethcore-util 1.8.0",
|
"ethcore-util 1.8.0",
|
||||||
"ethjson 0.1.0",
|
"ethjson 0.1.0",
|
||||||
"hash 0.1.0",
|
"hash 0.1.0",
|
||||||
|
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rlp 0.2.0",
|
"rlp 0.2.0",
|
||||||
"rlp_derive 0.1.0",
|
"rlp_derive 0.1.0",
|
||||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -518,6 +519,7 @@ dependencies = [
|
|||||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hardware-wallet 1.8.0",
|
"hardware-wallet 1.8.0",
|
||||||
"hash 0.1.0",
|
"hash 0.1.0",
|
||||||
|
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.10.0-a.0 (git+https://github.com/paritytech/hyper)",
|
"hyper 0.10.0-a.0 (git+https://github.com/paritytech/hyper)",
|
||||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -655,6 +657,7 @@ dependencies = [
|
|||||||
"evm 0.1.0",
|
"evm 0.1.0",
|
||||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hash 0.1.0",
|
"hash 0.1.0",
|
||||||
|
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -928,6 +931,7 @@ dependencies = [
|
|||||||
"ethjson 0.1.0",
|
"ethjson 0.1.0",
|
||||||
"evmjit 1.8.0",
|
"evmjit 1.8.0",
|
||||||
"hash 0.1.0",
|
"hash 0.1.0",
|
||||||
|
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -35,6 +35,7 @@ ethstore = { path = "../ethstore" }
|
|||||||
evm = { path = "evm" }
|
evm = { path = "evm" }
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
hardware-wallet = { path = "../hw" }
|
hardware-wallet = { path = "../hw" }
|
||||||
|
heapsize = "0.4"
|
||||||
hyper = { git = "https://github.com/paritytech/hyper", default-features = false }
|
hyper = { git = "https://github.com/paritytech/hyper", default-features = false }
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
|
@ -10,6 +10,7 @@ common-types = { path = "../types" }
|
|||||||
ethcore-util = { path = "../../util" }
|
ethcore-util = { path = "../../util" }
|
||||||
evmjit = { path = "../../evmjit", optional = true }
|
evmjit = { path = "../../evmjit", optional = true }
|
||||||
ethjson = { path = "../../json" }
|
ethjson = { path = "../../json" }
|
||||||
|
heapsize = "0.4"
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
rlp = { path = "../../util/rlp" }
|
rlp = { path = "../../util/rlp" }
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use hash::KECCAK_EMPTY;
|
use hash::KECCAK_EMPTY;
|
||||||
use util::{H256, HeapSizeOf, Mutex};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, Mutex};
|
||||||
use util::cache::MemoryLruCache;
|
use util::cache::MemoryLruCache;
|
||||||
use bit_set::BitSet;
|
use bit_set::BitSet;
|
||||||
use super::super::instructions;
|
use super::super::instructions;
|
||||||
|
@ -25,6 +25,7 @@ extern crate rlp;
|
|||||||
extern crate parity_wasm;
|
extern crate parity_wasm;
|
||||||
extern crate wasm_utils;
|
extern crate wasm_utils;
|
||||||
extern crate ethcore_logger;
|
extern crate ethcore_logger;
|
||||||
|
extern crate heapsize;
|
||||||
extern crate vm;
|
extern crate vm;
|
||||||
extern crate hash;
|
extern crate hash;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ ethcore-io = { path = "../../util/io" }
|
|||||||
ethcore-ipc = { path = "../../ipc/rpc", optional = true }
|
ethcore-ipc = { path = "../../ipc/rpc", optional = true }
|
||||||
ethcore-devtools = { path = "../../devtools" }
|
ethcore-devtools = { path = "../../devtools" }
|
||||||
evm = { path = "../evm" }
|
evm = { path = "../evm" }
|
||||||
|
heapsize = "0.4"
|
||||||
vm = { path = "../vm" }
|
vm = { path = "../vm" }
|
||||||
rlp = { path = "../../util/rlp" }
|
rlp = { path = "../../util/rlp" }
|
||||||
rlp_derive = { path = "../../util/rlp_derive" }
|
rlp_derive = { path = "../../util/rlp_derive" }
|
||||||
|
@ -26,7 +26,8 @@ use ethcore::receipt::Receipt;
|
|||||||
|
|
||||||
use stats::Corpus;
|
use stats::Corpus;
|
||||||
use time::{SteadyTime, Duration};
|
use time::{SteadyTime, Duration};
|
||||||
use util::{U256, H256, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{U256, H256};
|
||||||
use util::cache::MemoryLruCache;
|
use util::cache::MemoryLruCache;
|
||||||
|
|
||||||
/// Configuration for how much data to cache.
|
/// Configuration for how much data to cache.
|
||||||
|
@ -36,7 +36,8 @@ use ethcore::header::Header;
|
|||||||
use ethcore::ids::BlockId;
|
use ethcore::ids::BlockId;
|
||||||
|
|
||||||
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp, UntrustedRlp};
|
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp, UntrustedRlp};
|
||||||
use util::{H256, U256, HeapSizeOf, RwLock};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, U256, RwLock};
|
||||||
use util::kvdb::{DBTransaction, KeyValueDB};
|
use util::kvdb::{DBTransaction, KeyValueDB};
|
||||||
|
|
||||||
use cache::Cache;
|
use cache::Cache;
|
||||||
|
@ -330,7 +330,7 @@ impl Client {
|
|||||||
|
|
||||||
/// Get blockchain mem usage in bytes.
|
/// Get blockchain mem usage in bytes.
|
||||||
pub fn chain_mem_used(&self) -> usize {
|
pub fn chain_mem_used(&self) -> usize {
|
||||||
use util::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
|
|
||||||
self.chain.heap_size_of_children()
|
self.chain.heap_size_of_children()
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ extern crate ethcore_network as network;
|
|||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate evm;
|
extern crate evm;
|
||||||
|
extern crate heapsize;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
35
ethcore/res/null_morden_with_reward.json
Normal file
35
ethcore/res/null_morden_with_reward.json
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "Morden",
|
||||||
|
"engine": {
|
||||||
|
"null": null
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"gasLimitBoundDivisor": "0x0400",
|
||||||
|
"accountStartNonce": "0x0",
|
||||||
|
"maximumExtraDataSize": "0x20",
|
||||||
|
"minGasLimit": "0x1388",
|
||||||
|
"networkID" : "0x2",
|
||||||
|
"blockReward": "0x4563918244F40000"
|
||||||
|
},
|
||||||
|
"genesis": {
|
||||||
|
"seal": {
|
||||||
|
"ethereum": {
|
||||||
|
"nonce": "0x00006d6f7264656e",
|
||||||
|
"mixHash": "0x00000000000000000000000000000000000000647572616c65787365646c6578"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"difficulty": "0x20000",
|
||||||
|
"author": "0x0000000000000000000000000000000000000000",
|
||||||
|
"timestamp": "0x00",
|
||||||
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"extraData": "0x",
|
||||||
|
"gasLimit": "0x2fefd8"
|
||||||
|
},
|
||||||
|
"accounts": {
|
||||||
|
"0000000000000000000000000000000000000001": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
|
||||||
|
"0000000000000000000000000000000000000002": { "balance": "1", "nonce": "1048576", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
||||||
|
"0000000000000000000000000000000000000003": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
||||||
|
"0000000000000000000000000000000000000004": { "balance": "1", "nonce": "1048576", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
||||||
|
"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "1048576" }
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use hash::{keccak, KECCAK_NULL_RLP};
|
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||||
|
|
||||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
|
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
|
||||||
use util::{Bytes, Address, U256, H256, ordered_trie_root};
|
use util::{Bytes, Address, U256, H256, ordered_trie_root};
|
||||||
@ -108,7 +108,7 @@ pub struct BlockRefMut<'a> {
|
|||||||
/// State.
|
/// State.
|
||||||
pub state: &'a mut State<StateDB>,
|
pub state: &'a mut State<StateDB>,
|
||||||
/// Traces.
|
/// Traces.
|
||||||
pub traces: &'a Option<Vec<Vec<FlatTrace>>>,
|
pub traces: &'a mut Option<Vec<Vec<FlatTrace>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of immutable references to `ExecutedBlock` fields that are publicly accessible.
|
/// A set of immutable references to `ExecutedBlock` fields that are publicly accessible.
|
||||||
@ -149,7 +149,7 @@ impl ExecutedBlock {
|
|||||||
uncles: &self.uncles,
|
uncles: &self.uncles,
|
||||||
state: &mut self.state,
|
state: &mut self.state,
|
||||||
receipts: &self.receipts,
|
receipts: &self.receipts,
|
||||||
traces: &self.traces,
|
traces: &mut self.traces,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +197,9 @@ pub trait IsBlock {
|
|||||||
|
|
||||||
/// Get all uncles in this block.
|
/// Get all uncles in this block.
|
||||||
fn uncles(&self) -> &[Header] { &self.block().uncles }
|
fn uncles(&self) -> &[Header] { &self.block().uncles }
|
||||||
|
|
||||||
|
/// Get tracing enabled flag for this block.
|
||||||
|
fn tracing_enabled(&self) -> bool { self.block().traces.is_some() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for a object that has a state database.
|
/// Trait for a object that has a state database.
|
||||||
@ -396,6 +399,7 @@ impl<'x> OpenBlock<'x> {
|
|||||||
if let Err(e) = s.engine.on_close_block(&mut s.block) {
|
if let Err(e) = s.engine.on_close_block(&mut s.block) {
|
||||||
warn!("Encountered error on closing the block: {}", e);
|
warn!("Encountered error on closing the block: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = s.block.state.commit() {
|
if let Err(e) = s.block.state.commit() {
|
||||||
warn!("Encountered error on state commit: {}", e);
|
warn!("Encountered error on state commit: {}", e);
|
||||||
}
|
}
|
||||||
@ -430,7 +434,7 @@ impl<'x> OpenBlock<'x> {
|
|||||||
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
|
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
|
||||||
}
|
}
|
||||||
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
|
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
|
||||||
if s.block.header.uncles_hash().is_zero() {
|
if s.block.header.uncles_hash().is_zero() || s.block.header.uncles_hash() == &KECCAK_EMPTY_LIST_RLP {
|
||||||
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
|
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
|
||||||
}
|
}
|
||||||
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &KECCAK_NULL_RLP {
|
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &KECCAK_NULL_RLP {
|
||||||
|
@ -21,6 +21,7 @@ use std::sync::Arc;
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use bloomchain as bc;
|
use bloomchain as bc;
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use header::*;
|
use header::*;
|
||||||
|
@ -25,7 +25,8 @@ use engines::epoch::{Transition as EpochTransition};
|
|||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
use receipt::Receipt;
|
use receipt::Receipt;
|
||||||
|
|
||||||
use util::{HeapSizeOf, H256, H264, U256};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, H264, U256};
|
||||||
use util::kvdb::PREFIX_LEN as DB_PREFIX_LEN;
|
use util::kvdb::PREFIX_LEN as DB_PREFIX_LEN;
|
||||||
|
|
||||||
/// Represents index of extra data in database
|
/// Represents index of extra data in database
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use bloomchain as bc;
|
use bloomchain as bc;
|
||||||
use util::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use basic_types::LogBloom;
|
use basic_types::LogBloom;
|
||||||
|
|
||||||
/// Helper structure representing bloom of the trace.
|
/// Helper structure representing bloom of the trace.
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use bloomchain::group as bc;
|
use bloomchain::group as bc;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use util::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use super::Bloom;
|
use super::Bloom;
|
||||||
|
|
||||||
/// Represents group of X consecutive blooms.
|
/// Represents group of X consecutive blooms.
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use bloomchain::group as bc;
|
use bloomchain::group as bc;
|
||||||
use util::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
|
|
||||||
/// Represents `BloomGroup` position in database.
|
/// Represents `BloomGroup` position in database.
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||||
|
@ -28,8 +28,9 @@ use header::{BlockNumber, Header as FullHeader};
|
|||||||
use transaction::UnverifiedTransaction;
|
use transaction::UnverifiedTransaction;
|
||||||
use views;
|
use views;
|
||||||
|
|
||||||
use util::{Address, H256, H2048, U256, HeapSizeOf};
|
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{Address, H256, H2048, U256};
|
||||||
use rlp::Rlp;
|
use rlp::Rlp;
|
||||||
|
|
||||||
/// Owning header view.
|
/// Owning header view.
|
||||||
|
@ -31,7 +31,6 @@ use error::{Error, TransactionError, BlockError};
|
|||||||
use ethjson;
|
use ethjson;
|
||||||
use header::{Header, BlockNumber};
|
use header::{Header, BlockNumber};
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use state::CleanupMode;
|
|
||||||
use transaction::UnverifiedTransaction;
|
use transaction::UnverifiedTransaction;
|
||||||
|
|
||||||
use super::signer::EngineSigner;
|
use super::signer::EngineSigner;
|
||||||
@ -548,17 +547,7 @@ impl Engine for AuthorityRound {
|
|||||||
|
|
||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
let fields = block.fields_mut();
|
::engines::common::bestow_block_reward(block, self)
|
||||||
// Bestow block reward
|
|
||||||
let reward = self.params().block_reward;
|
|
||||||
let res = fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty)
|
|
||||||
.map_err(::error::Error::from)
|
|
||||||
.and_then(|_| fields.state.commit());
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
|
||||||
if let Err(ref e) = res {
|
|
||||||
warn!("Encountered error on closing block: {}", e);
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check the number of seal fields.
|
/// Check the number of seal fields.
|
||||||
|
@ -399,8 +399,9 @@ pub mod common {
|
|||||||
use transaction::SYSTEM_ADDRESS;
|
use transaction::SYSTEM_ADDRESS;
|
||||||
use executive::Executive;
|
use executive::Executive;
|
||||||
use vm::{CallType, ActionParams, ActionValue, EnvInfo, LastHashes};
|
use vm::{CallType, ActionParams, ActionValue, EnvInfo, LastHashes};
|
||||||
use trace::{NoopTracer, NoopVMTracer};
|
use trace::{NoopTracer, NoopVMTracer, Tracer, ExecutiveTracer, RewardType};
|
||||||
use state::Substate;
|
use state::Substate;
|
||||||
|
use state::CleanupMode;
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use super::Engine;
|
use super::Engine;
|
||||||
@ -469,4 +470,27 @@ pub mod common {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trace rewards on closing block
|
||||||
|
pub fn bestow_block_reward<E: Engine + ?Sized>(block: &mut ExecutedBlock, engine: &E) -> Result<(), Error> {
|
||||||
|
let fields = block.fields_mut();
|
||||||
|
// Bestow block reward
|
||||||
|
let reward = engine.params().block_reward;
|
||||||
|
let res = fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty)
|
||||||
|
.map_err(::error::Error::from)
|
||||||
|
.and_then(|_| fields.state.commit());
|
||||||
|
|
||||||
|
let block_author = fields.header.author().clone();
|
||||||
|
fields.traces.as_mut().map(|mut traces| {
|
||||||
|
let mut tracer = ExecutiveTracer::default();
|
||||||
|
tracer.trace_reward(block_author, engine.params().block_reward, RewardType::Block);
|
||||||
|
traces.push(tracer.drain())
|
||||||
|
});
|
||||||
|
|
||||||
|
// Commit state so that we can actually figure out the state root.
|
||||||
|
if let Err(ref e) = res {
|
||||||
|
warn!("Encountered error on bestowing reward: {}", e);
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,15 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use util::Address;
|
use util::Address;
|
||||||
use builtin::Builtin;
|
use builtin::Builtin;
|
||||||
|
use block::{ExecutedBlock, IsBlock};
|
||||||
|
use util::U256;
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
use error::Error;
|
||||||
|
use state::CleanupMode;
|
||||||
|
use trace::{Tracer, ExecutiveTracer, RewardType};
|
||||||
|
|
||||||
/// An engine which does not provide any consensus mechanism and does not seal blocks.
|
/// An engine which does not provide any consensus mechanism and does not seal blocks.
|
||||||
pub struct NullEngine {
|
pub struct NullEngine {
|
||||||
@ -64,4 +69,48 @@ impl Engine for NullEngine {
|
|||||||
fn snapshot_components(&self) -> Option<Box<::snapshot::SnapshotComponents>> {
|
fn snapshot_components(&self) -> Option<Box<::snapshot::SnapshotComponents>> {
|
||||||
Some(Box::new(::snapshot::PowSnapshot::new(10000, 10000)))
|
Some(Box::new(::snapshot::PowSnapshot::new(10000, 10000)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
|
if self.params.block_reward == U256::zero() {
|
||||||
|
// we don't have to apply reward in this case
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Block reward
|
||||||
|
let tracing_enabled = block.tracing_enabled();
|
||||||
|
let fields = block.fields_mut();
|
||||||
|
let mut tracer = ExecutiveTracer::default();
|
||||||
|
|
||||||
|
let result_block_reward = U256::from(1000000000);
|
||||||
|
fields.state.add_balance(
|
||||||
|
fields.header.author(),
|
||||||
|
&result_block_reward,
|
||||||
|
CleanupMode::NoEmpty
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if tracing_enabled {
|
||||||
|
let block_author = fields.header.author().clone();
|
||||||
|
tracer.trace_reward(block_author, result_block_reward, RewardType::Block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Uncle rewards
|
||||||
|
let result_uncle_reward = U256::from(10000000);
|
||||||
|
for u in fields.uncles.iter() {
|
||||||
|
let uncle_author = u.author().clone();
|
||||||
|
fields.state.add_balance(
|
||||||
|
u.author(),
|
||||||
|
&(result_uncle_reward),
|
||||||
|
CleanupMode::NoEmpty
|
||||||
|
)?;
|
||||||
|
if tracing_enabled {
|
||||||
|
tracer.trace_reward(uncle_author, result_uncle_reward, RewardType::Uncle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fields.state.commit()?;
|
||||||
|
if tracing_enabled {
|
||||||
|
fields.traces.as_mut().map(|mut traces| traces.push(tracer.drain()));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ use account_provider::AccountProvider;
|
|||||||
use block::*;
|
use block::*;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use engines::{Engine, Seal, EngineError, ConstructedVerifier};
|
use engines::{Engine, Seal, EngineError, ConstructedVerifier};
|
||||||
use state::CleanupMode;
|
|
||||||
use io::IoService;
|
use io::IoService;
|
||||||
use super::signer::EngineSigner;
|
use super::signer::EngineSigner;
|
||||||
use super::validator_set::{ValidatorSet, SimpleList};
|
use super::validator_set::{ValidatorSet, SimpleList};
|
||||||
@ -542,17 +541,7 @@ impl Engine for Tendermint {
|
|||||||
|
|
||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error>{
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error>{
|
||||||
let fields = block.fields_mut();
|
::engines::common::bestow_block_reward(block, self)
|
||||||
// Bestow block reward
|
|
||||||
let reward = self.params().block_reward;
|
|
||||||
let res = fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty)
|
|
||||||
.map_err(::error::Error::from)
|
|
||||||
.and_then(|_| fields.state.commit());
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
|
||||||
if let Err(ref e) = res {
|
|
||||||
warn!("Encountered error on closing block: {}", e);
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
/// Preconfigured validator list.
|
/// Preconfigured validator list.
|
||||||
|
|
||||||
use util::{H256, Address, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, Address};
|
||||||
|
|
||||||
use engines::{Call, Engine};
|
use engines::{Call, Engine};
|
||||||
use header::{BlockNumber, Header};
|
use header::{BlockNumber, Header};
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||||
use util::{Bytes, H256, Address, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{Bytes, H256, Address};
|
||||||
|
|
||||||
use engines::{Call, Engine};
|
use engines::{Call, Engine};
|
||||||
use header::{Header, BlockNumber};
|
use header::{Header, BlockNumber};
|
||||||
|
@ -25,6 +25,7 @@ use block::*;
|
|||||||
use builtin::Builtin;
|
use builtin::Builtin;
|
||||||
use vm::EnvInfo;
|
use vm::EnvInfo;
|
||||||
use error::{BlockError, Error, TransactionError};
|
use error::{BlockError, Error, TransactionError};
|
||||||
|
use trace::{Tracer, ExecutiveTracer, RewardType};
|
||||||
use header::{Header, BlockNumber};
|
use header::{Header, BlockNumber};
|
||||||
use state::CleanupMode;
|
use state::CleanupMode;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
@ -286,38 +287,60 @@ impl Engine for Arc<Ethash> {
|
|||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
|
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
|
use std::ops::Shr;
|
||||||
let reward = self.params().block_reward;
|
let reward = self.params().block_reward;
|
||||||
|
let tracing_enabled = block.tracing_enabled();
|
||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
let eras_rounds = self.ethash_params.ecip1017_era_rounds;
|
let eras_rounds = self.ethash_params.ecip1017_era_rounds;
|
||||||
let (eras, reward) = ecip1017_eras_block_reward(eras_rounds, reward, fields.header.number());
|
let (eras, reward) = ecip1017_eras_block_reward(eras_rounds, reward, fields.header.number());
|
||||||
|
let mut tracer = ExecutiveTracer::default();
|
||||||
|
|
||||||
// Bestow block reward
|
// Bestow block reward
|
||||||
|
let result_block_reward = reward + reward.shr(5) * U256::from(fields.uncles.len());
|
||||||
fields.state.add_balance(
|
fields.state.add_balance(
|
||||||
fields.header.author(),
|
fields.header.author(),
|
||||||
&(reward + reward / U256::from(32) * U256::from(fields.uncles.len())),
|
&result_block_reward,
|
||||||
CleanupMode::NoEmpty
|
CleanupMode::NoEmpty
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
if tracing_enabled {
|
||||||
|
let block_author = fields.header.author().clone();
|
||||||
|
tracer.trace_reward(block_author, result_block_reward, RewardType::Block);
|
||||||
|
}
|
||||||
|
|
||||||
// Bestow uncle rewards
|
// Bestow uncle rewards
|
||||||
let current_number = fields.header.number();
|
let current_number = fields.header.number();
|
||||||
for u in fields.uncles.iter() {
|
for u in fields.uncles.iter() {
|
||||||
|
let uncle_author = u.author().clone();
|
||||||
|
let result_uncle_reward: U256;
|
||||||
|
|
||||||
if eras == 0 {
|
if eras == 0 {
|
||||||
|
result_uncle_reward = (reward * U256::from(8 + u.number() - current_number)).shr(3);
|
||||||
fields.state.add_balance(
|
fields.state.add_balance(
|
||||||
u.author(),
|
u.author(),
|
||||||
&(reward * U256::from(8 + u.number() - current_number) / U256::from(8)),
|
&result_uncle_reward,
|
||||||
CleanupMode::NoEmpty
|
CleanupMode::NoEmpty
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
result_uncle_reward = reward.shr(5);
|
||||||
fields.state.add_balance(
|
fields.state.add_balance(
|
||||||
u.author(),
|
u.author(),
|
||||||
&(reward / U256::from(32)),
|
&result_uncle_reward,
|
||||||
CleanupMode::NoEmpty
|
CleanupMode::NoEmpty
|
||||||
)
|
)
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
// Trace uncle rewards
|
||||||
|
if tracing_enabled {
|
||||||
|
tracer.trace_reward(uncle_author, result_uncle_reward, RewardType::Uncle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
fields.state.commit()?;
|
fields.state.commit()?;
|
||||||
|
if tracing_enabled {
|
||||||
|
fields.traces.as_mut().map(|mut traces| traces.push(tracer.drain()));
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP, keccak};
|
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use basic_types::{LogBloom, ZERO_LOGBLOOM};
|
use basic_types::{LogBloom, ZERO_LOGBLOOM};
|
||||||
use time::get_time;
|
use time::get_time;
|
||||||
|
@ -102,6 +102,7 @@ extern crate price_info;
|
|||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate rlp;
|
extern crate rlp;
|
||||||
extern crate hash;
|
extern crate hash;
|
||||||
|
extern crate heapsize;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rlp_derive;
|
extern crate rlp_derive;
|
||||||
|
@ -105,7 +105,8 @@ use std::cmp::Ordering;
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::{HashSet, HashMap, BTreeSet, BTreeMap};
|
use std::collections::{HashSet, HashMap, BTreeSet, BTreeMap};
|
||||||
use linked_hash_map::LinkedHashMap;
|
use linked_hash_map::LinkedHashMap;
|
||||||
use util::{Address, H256, U256, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{Address, H256, U256};
|
||||||
use table::Table;
|
use table::Table;
|
||||||
use transaction::*;
|
use transaction::*;
|
||||||
use error::{Error, TransactionError};
|
use error::{Error, TransactionError};
|
||||||
|
@ -484,6 +484,9 @@ impl Spec {
|
|||||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus.
|
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus.
|
||||||
pub fn new_test() -> Spec { load_bundled!("null_morden") }
|
pub fn new_test() -> Spec { load_bundled!("null_morden") }
|
||||||
|
|
||||||
|
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close.
|
||||||
|
pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") }
|
||||||
|
|
||||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is keccak('').
|
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is keccak('').
|
||||||
pub fn new_null() -> Spec { load_bundled!("null") }
|
pub fn new_null() -> Spec { load_bundled!("null") }
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
mod client;
|
mod client;
|
||||||
mod evm;
|
mod evm;
|
||||||
|
mod trace;
|
||||||
|
|
||||||
#[cfg(feature="ipc")]
|
#[cfg(feature="ipc")]
|
||||||
mod rpc;
|
mod rpc;
|
||||||
|
207
ethcore/src/tests/trace.rs
Normal file
207
ethcore/src/tests/trace.rs
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
//! Client tests of tracing
|
||||||
|
|
||||||
|
use ethkey::KeyPair;
|
||||||
|
use hash::keccak;
|
||||||
|
use block::*;
|
||||||
|
use util::*;
|
||||||
|
use io::*;
|
||||||
|
use spec::*;
|
||||||
|
use client::*;
|
||||||
|
use tests::helpers::*;
|
||||||
|
use devtools::RandomTempPath;
|
||||||
|
use client::{BlockChainClient, Client, ClientConfig};
|
||||||
|
use util::kvdb::{Database, DatabaseConfig};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use header::Header;
|
||||||
|
use miner::Miner;
|
||||||
|
use transaction::{Action, Transaction};
|
||||||
|
use views::BlockView;
|
||||||
|
use trace::{RewardType, LocalizedTrace};
|
||||||
|
use trace::trace::Action::Reward;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_trace_block_and_uncle_reward() {
|
||||||
|
let dir = RandomTempPath::new();
|
||||||
|
let spec = Spec::new_test_with_reward();
|
||||||
|
let engine = &*spec.engine;
|
||||||
|
|
||||||
|
// Create client
|
||||||
|
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||||
|
let mut client_config = ClientConfig::default();
|
||||||
|
client_config.tracing.enabled = true;
|
||||||
|
let client_db = Arc::new(Database::open(&db_config, dir.as_path().to_str().unwrap()).unwrap());
|
||||||
|
let client = Client::new(
|
||||||
|
client_config,
|
||||||
|
&spec,
|
||||||
|
client_db,
|
||||||
|
Arc::new(Miner::with_spec(&spec)),
|
||||||
|
IoChannel::disconnected(),
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
// Create test data:
|
||||||
|
// genesis
|
||||||
|
// |
|
||||||
|
// root_block
|
||||||
|
// |
|
||||||
|
// parent_block
|
||||||
|
// |
|
||||||
|
// block with transaction and uncle
|
||||||
|
|
||||||
|
let genesis_header = spec.genesis_header();
|
||||||
|
let mut db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap();
|
||||||
|
let mut rolling_timestamp = 40;
|
||||||
|
let mut last_hashes = vec![];
|
||||||
|
let mut last_header = genesis_header.clone();
|
||||||
|
last_hashes.push(last_header.hash());
|
||||||
|
|
||||||
|
let kp = KeyPair::from_secret_slice(&keccak("")).unwrap();
|
||||||
|
let author = kp.address();
|
||||||
|
|
||||||
|
// Add root block first
|
||||||
|
let mut root_block = OpenBlock::new(
|
||||||
|
engine,
|
||||||
|
Default::default(),
|
||||||
|
false,
|
||||||
|
db,
|
||||||
|
&last_header,
|
||||||
|
Arc::new(last_hashes.clone()),
|
||||||
|
author.clone(),
|
||||||
|
(3141562.into(), 31415620.into()),
|
||||||
|
vec![],
|
||||||
|
false,
|
||||||
|
).unwrap();
|
||||||
|
root_block.set_difficulty(U256::from(0x20000));
|
||||||
|
rolling_timestamp += 10;
|
||||||
|
root_block.set_timestamp(rolling_timestamp);
|
||||||
|
|
||||||
|
let root_block = root_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||||
|
|
||||||
|
if let Err(e) = client.import_block(root_block.rlp_bytes()) {
|
||||||
|
panic!("error importing block which is valid by definition: {:?}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_header = BlockView::new(&root_block.rlp_bytes()).header();
|
||||||
|
let root_header = last_header.clone();
|
||||||
|
db = root_block.drain();
|
||||||
|
|
||||||
|
last_hashes.push(last_header.hash());
|
||||||
|
|
||||||
|
// Add parent block
|
||||||
|
let mut parent_block = OpenBlock::new(
|
||||||
|
engine,
|
||||||
|
Default::default(),
|
||||||
|
false,
|
||||||
|
db,
|
||||||
|
&last_header,
|
||||||
|
Arc::new(last_hashes.clone()),
|
||||||
|
author.clone(),
|
||||||
|
(3141562.into(), 31415620.into()),
|
||||||
|
vec![],
|
||||||
|
false,
|
||||||
|
).unwrap();
|
||||||
|
parent_block.set_difficulty(U256::from(0x20000));
|
||||||
|
rolling_timestamp += 10;
|
||||||
|
parent_block.set_timestamp(rolling_timestamp);
|
||||||
|
|
||||||
|
let parent_block = parent_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||||
|
|
||||||
|
if let Err(e) = client.import_block(parent_block.rlp_bytes()) {
|
||||||
|
panic!("error importing block which is valid by definition: {:?}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_header = BlockView::new(&parent_block.rlp_bytes()).header();
|
||||||
|
db = parent_block.drain();
|
||||||
|
|
||||||
|
last_hashes.push(last_header.hash());
|
||||||
|
|
||||||
|
// Add testing block with transaction and uncle
|
||||||
|
let mut block = OpenBlock::new(
|
||||||
|
engine,
|
||||||
|
Default::default(),
|
||||||
|
true,
|
||||||
|
db,
|
||||||
|
&last_header,
|
||||||
|
Arc::new(last_hashes.clone()),
|
||||||
|
author.clone(),
|
||||||
|
(3141562.into(), 31415620.into()),
|
||||||
|
vec![],
|
||||||
|
false
|
||||||
|
).unwrap();
|
||||||
|
block.set_difficulty(U256::from(0x20000));
|
||||||
|
rolling_timestamp += 10;
|
||||||
|
block.set_timestamp(rolling_timestamp);
|
||||||
|
|
||||||
|
let mut n = 0;
|
||||||
|
for _ in 0..1 {
|
||||||
|
block.push_transaction(Transaction {
|
||||||
|
nonce: n.into(),
|
||||||
|
gas_price: 10000.into(),
|
||||||
|
gas: 100000.into(),
|
||||||
|
action: Action::Create,
|
||||||
|
data: vec![],
|
||||||
|
value: U256::zero(),
|
||||||
|
}.sign(kp.secret(), Some(spec.network_id())), None).unwrap();
|
||||||
|
n += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut uncle = Header::new();
|
||||||
|
let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into();
|
||||||
|
uncle.set_author(uncle_author);
|
||||||
|
uncle.set_parent_hash(root_header.hash());
|
||||||
|
uncle.set_gas_limit(U256::from(50_000));
|
||||||
|
uncle.set_number(root_header.number() + 1);
|
||||||
|
uncle.set_timestamp(rolling_timestamp);
|
||||||
|
block.push_uncle(uncle).unwrap();
|
||||||
|
|
||||||
|
let block = block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||||
|
|
||||||
|
let res = client.import_block(block.rlp_bytes());
|
||||||
|
if res.is_err() {
|
||||||
|
panic!("error importing block: {:#?}", res.err().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
block.drain();
|
||||||
|
client.flush_queue();
|
||||||
|
client.import_verified_blocks();
|
||||||
|
|
||||||
|
// Test0. Check overall filter
|
||||||
|
let filter = TraceFilter {
|
||||||
|
range: (BlockId::Number(1)..BlockId::Number(3)),
|
||||||
|
from_address: vec![],
|
||||||
|
to_address: vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
let traces = client.filter_traces(filter);
|
||||||
|
assert!(traces.is_some(), "Filtered traces should be present");
|
||||||
|
let traces_vec = traces.unwrap();
|
||||||
|
let block_reward_traces: Vec<LocalizedTrace> = traces_vec.clone().into_iter().filter(|trace| match (trace).action {
|
||||||
|
Reward(ref a) => a.reward_type == RewardType::Block,
|
||||||
|
_ => false,
|
||||||
|
}).collect();
|
||||||
|
assert_eq!(block_reward_traces.len(), 3);
|
||||||
|
let uncle_reward_traces: Vec<LocalizedTrace> = traces_vec.clone().into_iter().filter(|trace| match (trace).action {
|
||||||
|
Reward(ref a) => a.reward_type == RewardType::Uncle,
|
||||||
|
_ => false,
|
||||||
|
}).collect();
|
||||||
|
assert_eq!(uncle_reward_traces.len(), 1);
|
||||||
|
|
||||||
|
// Test1. Check block filter
|
||||||
|
let traces = client.block_traces(BlockId::Number(3));
|
||||||
|
assert_eq!(traces.unwrap().len(), 3);
|
||||||
|
}
|
@ -20,7 +20,8 @@ use std::collections::{HashMap, VecDeque};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use bloomchain::{Number, Config as BloomConfig};
|
use bloomchain::{Number, Config as BloomConfig};
|
||||||
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
|
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
|
||||||
use util::{H256, H264, KeyValueDB, DBTransaction, RwLock, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, H264, KeyValueDB, DBTransaction, RwLock};
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras};
|
use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras};
|
||||||
use db::{self, Key, Writable, Readable, CacheUpdatePolicy};
|
use db::{self, Key, Writable, Readable, CacheUpdatePolicy};
|
||||||
@ -215,8 +216,11 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
|||||||
block_number: BlockNumber,
|
block_number: BlockNumber,
|
||||||
tx_number: usize
|
tx_number: usize
|
||||||
) -> Vec<LocalizedTrace> {
|
) -> Vec<LocalizedTrace> {
|
||||||
let tx_hash = self.extras.transaction_hash(block_number, tx_number)
|
let (trace_tx_number, trace_tx_hash) = match self.extras.transaction_hash(block_number, tx_number) {
|
||||||
.expect("Expected to find transaction hash. Database is probably corrupted");
|
Some(hash) => (Some(tx_number), Some(hash.clone())),
|
||||||
|
//None means trace without transaction (reward)
|
||||||
|
None => (None, None),
|
||||||
|
};
|
||||||
|
|
||||||
let flat_traces: Vec<FlatTrace> = traces.into();
|
let flat_traces: Vec<FlatTrace> = traces.into();
|
||||||
flat_traces.into_iter()
|
flat_traces.into_iter()
|
||||||
@ -227,8 +231,8 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
|||||||
result: trace.result,
|
result: trace.result,
|
||||||
subtraces: trace.subtraces,
|
subtraces: trace.subtraces,
|
||||||
trace_address: trace.trace_address.into_iter().collect(),
|
trace_address: trace.trace_address.into_iter().collect(),
|
||||||
transaction_number: tx_number,
|
transaction_number: trace_tx_number,
|
||||||
transaction_hash: tx_hash.clone(),
|
transaction_hash: trace_tx_hash,
|
||||||
block_number: block_number,
|
block_number: block_number,
|
||||||
block_hash: block_hash
|
block_hash: block_hash
|
||||||
}),
|
}),
|
||||||
@ -321,8 +325,8 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
result: trace.result,
|
result: trace.result,
|
||||||
subtraces: trace.subtraces,
|
subtraces: trace.subtraces,
|
||||||
trace_address: trace.trace_address.into_iter().collect(),
|
trace_address: trace.trace_address.into_iter().collect(),
|
||||||
transaction_number: tx_position,
|
transaction_number: Some(tx_position),
|
||||||
transaction_hash: tx_hash,
|
transaction_hash: Some(tx_hash),
|
||||||
block_number: block_number,
|
block_number: block_number,
|
||||||
block_hash: block_hash,
|
block_hash: block_hash,
|
||||||
}
|
}
|
||||||
@ -345,8 +349,8 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
result: trace.result,
|
result: trace.result,
|
||||||
subtraces: trace.subtraces,
|
subtraces: trace.subtraces,
|
||||||
trace_address: trace.trace_address.into_iter().collect(),
|
trace_address: trace.trace_address.into_iter().collect(),
|
||||||
transaction_number: tx_position,
|
transaction_number: Some(tx_position),
|
||||||
transaction_hash: tx_hash.clone(),
|
transaction_hash: Some(tx_hash.clone()),
|
||||||
block_number: block_number,
|
block_number: block_number,
|
||||||
block_hash: block_hash
|
block_hash: block_hash
|
||||||
})
|
})
|
||||||
@ -363,8 +367,11 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
.map(Into::<Vec<FlatTrace>>::into)
|
.map(Into::<Vec<FlatTrace>>::into)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.flat_map(|(tx_position, traces)| {
|
.flat_map(|(tx_position, traces)| {
|
||||||
let tx_hash = self.extras.transaction_hash(block_number, tx_position)
|
let (trace_tx_number, trace_tx_hash) = match self.extras.transaction_hash(block_number, tx_position) {
|
||||||
.expect("Expected to find transaction hash. Database is probably corrupted");
|
Some(hash) => (Some(tx_position), Some(hash.clone())),
|
||||||
|
//None means trace without transaction (reward)
|
||||||
|
None => (None, None),
|
||||||
|
};
|
||||||
|
|
||||||
traces.into_iter()
|
traces.into_iter()
|
||||||
.map(|trace| LocalizedTrace {
|
.map(|trace| LocalizedTrace {
|
||||||
@ -372,8 +379,8 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
result: trace.result,
|
result: trace.result,
|
||||||
subtraces: trace.subtraces,
|
subtraces: trace.subtraces,
|
||||||
trace_address: trace.trace_address.into_iter().collect(),
|
trace_address: trace.trace_address.into_iter().collect(),
|
||||||
transaction_number: tx_position,
|
transaction_number: trace_tx_number,
|
||||||
transaction_hash: tx_hash.clone(),
|
transaction_hash: trace_tx_hash,
|
||||||
block_number: block_number,
|
block_number: block_number,
|
||||||
block_hash: block_hash,
|
block_hash: block_hash,
|
||||||
})
|
})
|
||||||
@ -543,8 +550,8 @@ mod tests {
|
|||||||
result: Res::FailedCall(TraceError::OutOfGas),
|
result: Res::FailedCall(TraceError::OutOfGas),
|
||||||
trace_address: vec![],
|
trace_address: vec![],
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
transaction_number: 0,
|
transaction_number: Some(0),
|
||||||
transaction_hash: tx_hash,
|
transaction_hash: Some(tx_hash),
|
||||||
block_number: block_number,
|
block_number: block_number,
|
||||||
block_hash: block_hash,
|
block_hash: block_hash,
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use util::{Bytes, Address, U256};
|
use util::{Bytes, Address, U256};
|
||||||
use vm::ActionParams;
|
use vm::ActionParams;
|
||||||
use trace::trace::{Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide};
|
use trace::trace::{Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide, Reward, RewardType};
|
||||||
use trace::{Tracer, VMTracer, FlatTrace, TraceError};
|
use trace::{Tracer, VMTracer, FlatTrace, TraceError};
|
||||||
|
|
||||||
/// Simple executive tracer. Traces all calls and creates. Ignores delegatecalls.
|
/// Simple executive tracer. Traces all calls and creates. Ignores delegatecalls.
|
||||||
@ -151,15 +151,22 @@ impl Tracer for ExecutiveTracer {
|
|||||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address) {
|
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address) {
|
||||||
let trace = FlatTrace {
|
let trace = FlatTrace {
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
action: Action::Suicide(Suicide {
|
action: Action::Suicide(Suicide { address, refund_address, balance } ),
|
||||||
address: address,
|
|
||||||
refund_address: refund_address,
|
|
||||||
balance: balance,
|
|
||||||
}),
|
|
||||||
result: Res::None,
|
result: Res::None,
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
};
|
};
|
||||||
debug!(target: "trace", "Traced failed suicide {:?}", trace);
|
debug!(target: "trace", "Traced suicide {:?}", trace);
|
||||||
|
self.traces.push(trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trace_reward(&mut self, author: Address, value: U256, reward_type: RewardType) {
|
||||||
|
let trace = FlatTrace {
|
||||||
|
subtraces: 0,
|
||||||
|
action: Action::Reward(Reward { author, value, reward_type } ),
|
||||||
|
result: Res::None,
|
||||||
|
trace_address: Default::default(),
|
||||||
|
};
|
||||||
|
debug!(target: "trace", "Traced reward {:?}", trace);
|
||||||
self.traces.push(trace);
|
self.traces.push(trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ pub use self::localized::LocalizedTrace;
|
|||||||
|
|
||||||
pub use self::types::{filter, flat, localized, trace};
|
pub use self::types::{filter, flat, localized, trace};
|
||||||
pub use self::types::error::Error as TraceError;
|
pub use self::types::error::Error as TraceError;
|
||||||
pub use self::types::trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff};
|
pub use self::types::trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, RewardType};
|
||||||
pub use self::types::flat::{FlatTrace, FlatTransactionTraces, FlatBlockTraces};
|
pub use self::types::flat::{FlatTrace, FlatTransactionTraces, FlatBlockTraces};
|
||||||
pub use self::types::filter::{Filter, AddressesFilter};
|
pub use self::types::filter::{Filter, AddressesFilter};
|
||||||
|
|
||||||
@ -81,6 +81,9 @@ pub trait Tracer: Send {
|
|||||||
/// Stores suicide info.
|
/// Stores suicide info.
|
||||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address);
|
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address);
|
||||||
|
|
||||||
|
/// Stores reward info.
|
||||||
|
fn trace_reward(&mut self, author: Address, value: U256, reward_type: RewardType);
|
||||||
|
|
||||||
/// Spawn subtracer which will be used to trace deeper levels of execution.
|
/// Spawn subtracer which will be used to trace deeper levels of execution.
|
||||||
fn subtracer(&self) -> Self where Self: Sized;
|
fn subtracer(&self) -> Self where Self: Sized;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
use util::{Bytes, Address, U256};
|
use util::{Bytes, Address, U256};
|
||||||
use vm::ActionParams;
|
use vm::ActionParams;
|
||||||
use trace::{Tracer, VMTracer, FlatTrace, TraceError};
|
use trace::{Tracer, VMTracer, FlatTrace, TraceError};
|
||||||
use trace::trace::{Call, Create, VMTrace};
|
use trace::trace::{Call, Create, VMTrace, RewardType};
|
||||||
|
|
||||||
/// Nonoperative tracer. Does not trace anything.
|
/// Nonoperative tracer. Does not trace anything.
|
||||||
pub struct NoopTracer;
|
pub struct NoopTracer;
|
||||||
@ -58,6 +58,9 @@ impl Tracer for NoopTracer {
|
|||||||
fn trace_suicide(&mut self, _address: Address, _balance: U256, _refund_address: Address) {
|
fn trace_suicide(&mut self, _address: Address, _balance: U256, _refund_address: Address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn trace_reward(&mut self, _: Address, _: U256, _: RewardType) {
|
||||||
|
}
|
||||||
|
|
||||||
fn subtracer(&self) -> Self {
|
fn subtracer(&self) -> Self {
|
||||||
NoopTracer
|
NoopTracer
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ impl Filter {
|
|||||||
let from_matches = self.from_address.matches(&call.from);
|
let from_matches = self.from_address.matches(&call.from);
|
||||||
let to_matches = self.to_address.matches(&call.to);
|
let to_matches = self.to_address.matches(&call.to);
|
||||||
from_matches && to_matches
|
from_matches && to_matches
|
||||||
}
|
},
|
||||||
Action::Create(ref create) => {
|
Action::Create(ref create) => {
|
||||||
let from_matches = self.from_address.matches(&create.from);
|
let from_matches = self.from_address.matches(&create.from);
|
||||||
|
|
||||||
@ -128,7 +128,10 @@ impl Filter {
|
|||||||
let from_matches = self.from_address.matches(&suicide.address);
|
let from_matches = self.from_address.matches(&suicide.address);
|
||||||
let to_matches = self.to_address.matches(&suicide.refund_address);
|
let to_matches = self.to_address.matches(&suicide.refund_address);
|
||||||
from_matches && to_matches
|
from_matches && to_matches
|
||||||
}
|
},
|
||||||
|
Action::Reward(ref reward) => {
|
||||||
|
self.to_address.matches(&reward.author)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,9 +141,9 @@ mod tests {
|
|||||||
use util::Address;
|
use util::Address;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use bloomable::Bloomable;
|
use bloomable::Bloomable;
|
||||||
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide};
|
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
|
||||||
use trace::flat::FlatTrace;
|
use trace::flat::FlatTrace;
|
||||||
use trace::{Filter, AddressesFilter, TraceError};
|
use trace::{Filter, AddressesFilter, TraceError, RewardType};
|
||||||
use evm::CallType;
|
use evm::CallType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -341,5 +344,24 @@ mod tests {
|
|||||||
assert!(f4.matches(&trace));
|
assert!(f4.matches(&trace));
|
||||||
assert!(f5.matches(&trace));
|
assert!(f5.matches(&trace));
|
||||||
assert!(!f6.matches(&trace));
|
assert!(!f6.matches(&trace));
|
||||||
|
|
||||||
|
let trace = FlatTrace {
|
||||||
|
action: Action::Reward(Reward {
|
||||||
|
author: 2.into(),
|
||||||
|
value: 100.into(),
|
||||||
|
reward_type: RewardType::Block,
|
||||||
|
}),
|
||||||
|
result: Res::None,
|
||||||
|
trace_address: vec![].into_iter().collect(),
|
||||||
|
subtraces: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(f0.matches(&trace));
|
||||||
|
assert!(f1.matches(&trace));
|
||||||
|
assert!(f2.matches(&trace));
|
||||||
|
assert!(f3.matches(&trace));
|
||||||
|
assert!(f4.matches(&trace));
|
||||||
|
assert!(f5.matches(&trace));
|
||||||
|
assert!(!f6.matches(&trace));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use util::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use basic_types::LogBloom;
|
use basic_types::LogBloom;
|
||||||
use super::trace::{Action, Res};
|
use super::trace::{Action, Res};
|
||||||
|
|
||||||
@ -138,8 +138,9 @@ impl Into<Vec<FlatTransactionTraces>> for FlatBlockTraces {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use super::{FlatBlockTraces, FlatTransactionTraces, FlatTrace};
|
use super::{FlatBlockTraces, FlatTransactionTraces, FlatTrace};
|
||||||
use trace::trace::{Action, Res, CallResult, Call, Suicide};
|
use trace::trace::{Action, Res, CallResult, Call, Suicide, Reward};
|
||||||
use evm::CallType;
|
use evm::CallType;
|
||||||
|
use trace::RewardType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_flat_transaction_traces() {
|
fn encode_flat_transaction_traces() {
|
||||||
@ -214,9 +215,32 @@ mod tests {
|
|||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let flat_trace3 = FlatTrace {
|
||||||
|
action: Action::Reward(Reward {
|
||||||
|
author: "412fda7643b37d436cb40628f6dbbb80a07267ed".parse().unwrap(),
|
||||||
|
value: 10.into(),
|
||||||
|
reward_type: RewardType::Uncle,
|
||||||
|
}),
|
||||||
|
result: Res::None,
|
||||||
|
trace_address: vec![0].into_iter().collect(),
|
||||||
|
subtraces: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let flat_trace4 = FlatTrace {
|
||||||
|
action: Action::Reward(Reward {
|
||||||
|
author: "412fda7643b37d436cb40628f6dbbb80a07267ed".parse().unwrap(),
|
||||||
|
value: 10.into(),
|
||||||
|
reward_type: RewardType::Block,
|
||||||
|
}),
|
||||||
|
result: Res::None,
|
||||||
|
trace_address: vec![0].into_iter().collect(),
|
||||||
|
subtraces: 0,
|
||||||
|
};
|
||||||
|
|
||||||
let block_traces = FlatBlockTraces(vec![
|
let block_traces = FlatBlockTraces(vec![
|
||||||
FlatTransactionTraces(vec![flat_trace]),
|
FlatTransactionTraces(vec![flat_trace]),
|
||||||
FlatTransactionTraces(vec![flat_trace1, flat_trace2])
|
FlatTransactionTraces(vec![flat_trace1, flat_trace2]),
|
||||||
|
FlatTransactionTraces(vec![flat_trace3, flat_trace4])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let encoded = ::rlp::encode(&block_traces);
|
let encoded = ::rlp::encode(&block_traces);
|
||||||
|
@ -34,9 +34,9 @@ pub struct LocalizedTrace {
|
|||||||
/// [index in root, index in first CALL, index in second CALL, ...]
|
/// [index in root, index in first CALL, index in second CALL, ...]
|
||||||
pub trace_address: Vec<usize>,
|
pub trace_address: Vec<usize>,
|
||||||
/// Transaction number within the block.
|
/// Transaction number within the block.
|
||||||
pub transaction_number: usize,
|
pub transaction_number: Option<usize>,
|
||||||
/// Signed transaction hash.
|
/// Signed transaction hash.
|
||||||
pub transaction_hash: H256,
|
pub transaction_hash: Option<H256>,
|
||||||
/// Block number.
|
/// Block number.
|
||||||
pub block_number: BlockNumber,
|
pub block_number: BlockNumber,
|
||||||
/// Block hash.
|
/// Block hash.
|
||||||
|
@ -128,6 +128,77 @@ impl Create {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reward type.
|
||||||
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
#[cfg_attr(feature = "ipc", binary)]
|
||||||
|
pub enum RewardType {
|
||||||
|
/// Block
|
||||||
|
Block,
|
||||||
|
/// Uncle
|
||||||
|
Uncle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for RewardType {
|
||||||
|
fn rlp_append(&self, s: &mut RlpStream) {
|
||||||
|
let v = match *self {
|
||||||
|
RewardType::Block => 0u32,
|
||||||
|
RewardType::Uncle => 1,
|
||||||
|
};
|
||||||
|
Encodable::rlp_append(&v, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for RewardType {
|
||||||
|
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||||
|
rlp.as_val().and_then(|v| Ok(match v {
|
||||||
|
0u32 => RewardType::Block,
|
||||||
|
1 => RewardType::Uncle,
|
||||||
|
_ => return Err(DecoderError::Custom("Invalid value of RewardType item")),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reward action
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "ipc", binary)]
|
||||||
|
pub struct Reward {
|
||||||
|
/// Author's address.
|
||||||
|
pub author: Address,
|
||||||
|
/// Reward amount.
|
||||||
|
pub value: U256,
|
||||||
|
/// Reward type.
|
||||||
|
pub reward_type: RewardType,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reward {
|
||||||
|
/// Return reward action bloom.
|
||||||
|
pub fn bloom(&self) -> LogBloom {
|
||||||
|
LogBloom::from_bloomed(&keccak(&self.author))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for Reward {
|
||||||
|
fn rlp_append(&self, s: &mut RlpStream) {
|
||||||
|
s.begin_list(3);
|
||||||
|
s.append(&self.author);
|
||||||
|
s.append(&self.value);
|
||||||
|
s.append(&self.reward_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for Reward {
|
||||||
|
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||||
|
let res = Reward {
|
||||||
|
author: rlp.val_at(0)?,
|
||||||
|
value: rlp.val_at(1)?,
|
||||||
|
reward_type: rlp.val_at(2)?,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Suicide action.
|
/// Suicide action.
|
||||||
#[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)]
|
#[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)]
|
||||||
#[cfg_attr(feature = "ipc", binary)]
|
#[cfg_attr(feature = "ipc", binary)]
|
||||||
@ -158,6 +229,8 @@ pub enum Action {
|
|||||||
Create(Create),
|
Create(Create),
|
||||||
/// Suicide.
|
/// Suicide.
|
||||||
Suicide(Suicide),
|
Suicide(Suicide),
|
||||||
|
/// Reward
|
||||||
|
Reward(Reward),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encodable for Action {
|
impl Encodable for Action {
|
||||||
@ -175,7 +248,12 @@ impl Encodable for Action {
|
|||||||
Action::Suicide(ref suicide) => {
|
Action::Suicide(ref suicide) => {
|
||||||
s.append(&2u8);
|
s.append(&2u8);
|
||||||
s.append(suicide);
|
s.append(suicide);
|
||||||
|
},
|
||||||
|
Action::Reward(ref reward) => {
|
||||||
|
s.append(&3u8);
|
||||||
|
s.append(reward);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,6 +265,7 @@ impl Decodable for Action {
|
|||||||
0 => rlp.val_at(1).map(Action::Call),
|
0 => rlp.val_at(1).map(Action::Call),
|
||||||
1 => rlp.val_at(1).map(Action::Create),
|
1 => rlp.val_at(1).map(Action::Create),
|
||||||
2 => rlp.val_at(1).map(Action::Suicide),
|
2 => rlp.val_at(1).map(Action::Suicide),
|
||||||
|
3 => rlp.val_at(1).map(Action::Reward),
|
||||||
_ => Err(DecoderError::Custom("Invalid action type.")),
|
_ => Err(DecoderError::Custom("Invalid action type.")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,6 +278,7 @@ impl Action {
|
|||||||
Action::Call(ref call) => call.bloom(),
|
Action::Call(ref call) => call.bloom(),
|
||||||
Action::Create(ref create) => create.bloom(),
|
Action::Create(ref create) => create.bloom(),
|
||||||
Action::Suicide(ref suicide) => suicide.bloom(),
|
Action::Suicide(ref suicide) => suicide.bloom(),
|
||||||
|
Action::Reward(ref reward) => reward.bloom(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use util::{H256, Address, U256, Bytes, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, Address, U256, Bytes};
|
||||||
use ethkey::{Signature, Secret, Public, recover, public_to_address, Error as EthkeyError};
|
use ethkey::{Signature, Secret, Public, recover, public_to_address, Error as EthkeyError};
|
||||||
use error::*;
|
use error::*;
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
|
||||||
use util::{HeapSizeOf, H256, U256};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, U256};
|
||||||
|
|
||||||
pub use self::blocks::Blocks;
|
pub use self::blocks::Blocks;
|
||||||
pub use self::headers::Headers;
|
pub use self::headers::Headers;
|
||||||
@ -72,7 +73,8 @@ pub mod blocks {
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use verification::{PreverifiedBlock, verify_block_basic, verify_block_unordered};
|
use verification::{PreverifiedBlock, verify_block_basic, verify_block_unordered};
|
||||||
|
|
||||||
use util::{Bytes, HeapSizeOf, H256, U256};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{Bytes, H256, U256};
|
||||||
|
|
||||||
/// A mode for verifying blocks.
|
/// A mode for verifying blocks.
|
||||||
pub struct Blocks;
|
pub struct Blocks;
|
||||||
|
@ -22,6 +22,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering};
|
|||||||
use std::sync::{Condvar as SCondvar, Mutex as SMutex, Arc};
|
use std::sync::{Condvar as SCondvar, Mutex as SMutex, Arc};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::{VecDeque, HashSet, HashMap};
|
use std::collections::{VecDeque, HashSet, HashMap};
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use io::*;
|
use io::*;
|
||||||
use error::*;
|
use error::*;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use error::{BlockError, Error};
|
use error::{BlockError, Error};
|
||||||
|
@ -11,6 +11,7 @@ ethcore-util = { path = "../../util" }
|
|||||||
ethjson = { path = "../../json" }
|
ethjson = { path = "../../json" }
|
||||||
bloomable = { path = "../../util/bloomable" }
|
bloomable = { path = "../../util/bloomable" }
|
||||||
hash = { path = "../../util/hash" }
|
hash = { path = "../../util/hash" }
|
||||||
|
heapsize = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rustc-hex= "1.0"
|
rustc-hex= "1.0"
|
||||||
|
@ -23,6 +23,7 @@ extern crate rlp;
|
|||||||
extern crate rlp_derive;
|
extern crate rlp_derive;
|
||||||
extern crate bloomable;
|
extern crate bloomable;
|
||||||
extern crate hash;
|
extern crate hash;
|
||||||
|
extern crate heapsize;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate rustc_hex;
|
extern crate rustc_hex;
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use util::{H256, Address, Bytes, HeapSizeOf};
|
use heapsize::HeapSizeOf;
|
||||||
|
use util::{H256, Address, Bytes};
|
||||||
use bloomable::Bloomable;
|
use bloomable::Bloomable;
|
||||||
|
|
||||||
use {BlockNumber};
|
use {BlockNumber};
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
//! Receipt
|
//! Receipt
|
||||||
|
|
||||||
use util::{H256, U256, Address};
|
use util::{H256, U256, Address};
|
||||||
use util::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
|
|
||||||
use {BlockNumber};
|
use {BlockNumber};
|
||||||
|
@ -102,6 +102,9 @@ pub struct Params {
|
|||||||
pub block_reward: Option<Uint>,
|
pub block_reward: Option<Uint>,
|
||||||
/// See `CommonParams` docs.
|
/// See `CommonParams` docs.
|
||||||
pub registrar: Option<Address>,
|
pub registrar: Option<Address>,
|
||||||
|
/// Apply reward flag
|
||||||
|
#[serde(rename="applyReward")]
|
||||||
|
pub apply_reward: Option<bool>,
|
||||||
/// Node permission contract address.
|
/// Node permission contract address.
|
||||||
#[serde(rename="nodePermissionContract")]
|
#[serde(rename="nodePermissionContract")]
|
||||||
pub node_permission_contract: Option<Address>,
|
pub node_permission_contract: Option<Address>,
|
||||||
|
@ -47,8 +47,8 @@ fn io() -> Tester {
|
|||||||
result: Res::None,
|
result: Res::None,
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
trace_address: vec![0],
|
trace_address: vec![0],
|
||||||
transaction_number: 0,
|
transaction_number: Some(0),
|
||||||
transaction_hash: 5.into(),
|
transaction_hash: Some(5.into()),
|
||||||
block_number: 10,
|
block_number: 10,
|
||||||
block_hash: 10.into(),
|
block_hash: 10.into(),
|
||||||
}]);
|
}]);
|
||||||
|
@ -299,6 +299,49 @@ impl From<trace::Call> for Call {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reward type.
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub enum RewardType {
|
||||||
|
/// Block
|
||||||
|
#[serde(rename="block")]
|
||||||
|
Block,
|
||||||
|
/// Uncle
|
||||||
|
#[serde(rename="uncle")]
|
||||||
|
Uncle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<trace::RewardType> for RewardType {
|
||||||
|
fn from(c: trace::RewardType) -> Self {
|
||||||
|
match c {
|
||||||
|
trace::RewardType::Block => RewardType::Block,
|
||||||
|
trace::RewardType::Uncle => RewardType::Uncle,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Reward action
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct Reward {
|
||||||
|
/// Author's address.
|
||||||
|
pub author: H160,
|
||||||
|
/// Reward amount.
|
||||||
|
pub value: U256,
|
||||||
|
/// Reward type.
|
||||||
|
#[serde(rename="rewardType")]
|
||||||
|
pub reward_type: RewardType,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<trace::Reward> for Reward {
|
||||||
|
fn from(r: trace::Reward) -> Self {
|
||||||
|
Reward {
|
||||||
|
author: r.author.into(),
|
||||||
|
value: r.value.into(),
|
||||||
|
reward_type: r.reward_type.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Suicide
|
/// Suicide
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Suicide {
|
pub struct Suicide {
|
||||||
@ -330,6 +373,8 @@ pub enum Action {
|
|||||||
Create(Create),
|
Create(Create),
|
||||||
/// Suicide
|
/// Suicide
|
||||||
Suicide(Suicide),
|
Suicide(Suicide),
|
||||||
|
/// Reward
|
||||||
|
Reward(Reward),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<trace::Action> for Action {
|
impl From<trace::Action> for Action {
|
||||||
@ -338,6 +383,7 @@ impl From<trace::Action> for Action {
|
|||||||
trace::Action::Call(call) => Action::Call(call.into()),
|
trace::Action::Call(call) => Action::Call(call.into()),
|
||||||
trace::Action::Create(create) => Action::Create(create.into()),
|
trace::Action::Create(create) => Action::Create(create.into()),
|
||||||
trace::Action::Suicide(suicide) => Action::Suicide(suicide.into()),
|
trace::Action::Suicide(suicide) => Action::Suicide(suicide.into()),
|
||||||
|
trace::Action::Reward(reward) => Action::Reward(reward.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,9 +468,9 @@ pub struct LocalizedTrace {
|
|||||||
/// Subtraces
|
/// Subtraces
|
||||||
subtraces: usize,
|
subtraces: usize,
|
||||||
/// Transaction position
|
/// Transaction position
|
||||||
transaction_position: usize,
|
transaction_position: Option<usize>,
|
||||||
/// Transaction hash
|
/// Transaction hash
|
||||||
transaction_hash: H256,
|
transaction_hash: Option<H256>,
|
||||||
/// Block Number
|
/// Block Number
|
||||||
block_number: u64,
|
block_number: u64,
|
||||||
/// Block Hash
|
/// Block Hash
|
||||||
@ -449,6 +495,10 @@ impl Serialize for LocalizedTrace {
|
|||||||
struc.serialize_field("type", "suicide")?;
|
struc.serialize_field("type", "suicide")?;
|
||||||
struc.serialize_field("action", suicide)?;
|
struc.serialize_field("action", suicide)?;
|
||||||
},
|
},
|
||||||
|
Action::Reward(ref reward) => {
|
||||||
|
struc.serialize_field("type", "reward")?;
|
||||||
|
struc.serialize_field("action", reward)?;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.result {
|
match self.result {
|
||||||
@ -477,8 +527,8 @@ impl From<EthLocalizedTrace> for LocalizedTrace {
|
|||||||
result: t.result.into(),
|
result: t.result.into(),
|
||||||
trace_address: t.trace_address.into_iter().map(Into::into).collect(),
|
trace_address: t.trace_address.into_iter().map(Into::into).collect(),
|
||||||
subtraces: t.subtraces.into(),
|
subtraces: t.subtraces.into(),
|
||||||
transaction_position: t.transaction_number.into(),
|
transaction_position: t.transaction_number.map(Into::into),
|
||||||
transaction_hash: t.transaction_hash.into(),
|
transaction_hash: t.transaction_hash.map(Into::into),
|
||||||
block_number: t.block_number.into(),
|
block_number: t.block_number.into(),
|
||||||
block_hash: t.block_hash.into(),
|
block_hash: t.block_hash.into(),
|
||||||
}
|
}
|
||||||
@ -516,6 +566,10 @@ impl Serialize for Trace {
|
|||||||
struc.serialize_field("type", "suicide")?;
|
struc.serialize_field("type", "suicide")?;
|
||||||
struc.serialize_field("action", suicide)?;
|
struc.serialize_field("action", suicide)?;
|
||||||
},
|
},
|
||||||
|
Action::Reward(ref reward) => {
|
||||||
|
struc.serialize_field("type", "reward")?;
|
||||||
|
struc.serialize_field("action", reward)?;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.result {
|
match self.result {
|
||||||
@ -607,8 +661,8 @@ mod tests {
|
|||||||
}),
|
}),
|
||||||
trace_address: vec![10],
|
trace_address: vec![10],
|
||||||
subtraces: 1,
|
subtraces: 1,
|
||||||
transaction_position: 11,
|
transaction_position: Some(11),
|
||||||
transaction_hash: 12.into(),
|
transaction_hash: Some(12.into()),
|
||||||
block_number: 13,
|
block_number: 13,
|
||||||
block_hash: 14.into(),
|
block_hash: 14.into(),
|
||||||
};
|
};
|
||||||
@ -630,8 +684,8 @@ mod tests {
|
|||||||
result: Res::FailedCall(TraceError::OutOfGas),
|
result: Res::FailedCall(TraceError::OutOfGas),
|
||||||
trace_address: vec![10],
|
trace_address: vec![10],
|
||||||
subtraces: 1,
|
subtraces: 1,
|
||||||
transaction_position: 11,
|
transaction_position: Some(11),
|
||||||
transaction_hash: 12.into(),
|
transaction_hash: Some(12.into()),
|
||||||
block_number: 13,
|
block_number: 13,
|
||||||
block_hash: 14.into(),
|
block_hash: 14.into(),
|
||||||
};
|
};
|
||||||
@ -655,8 +709,8 @@ mod tests {
|
|||||||
}),
|
}),
|
||||||
trace_address: vec![10],
|
trace_address: vec![10],
|
||||||
subtraces: 1,
|
subtraces: 1,
|
||||||
transaction_position: 11,
|
transaction_position: Some(11),
|
||||||
transaction_hash: 12.into(),
|
transaction_hash: Some(12.into()),
|
||||||
block_number: 13,
|
block_number: 13,
|
||||||
block_hash: 14.into(),
|
block_hash: 14.into(),
|
||||||
};
|
};
|
||||||
@ -676,8 +730,8 @@ mod tests {
|
|||||||
result: Res::FailedCreate(TraceError::OutOfGas),
|
result: Res::FailedCreate(TraceError::OutOfGas),
|
||||||
trace_address: vec![10],
|
trace_address: vec![10],
|
||||||
subtraces: 1,
|
subtraces: 1,
|
||||||
transaction_position: 11,
|
transaction_position: Some(11),
|
||||||
transaction_hash: 12.into(),
|
transaction_hash: Some(12.into()),
|
||||||
block_number: 13,
|
block_number: 13,
|
||||||
block_hash: 14.into(),
|
block_hash: 14.into(),
|
||||||
};
|
};
|
||||||
@ -696,8 +750,8 @@ mod tests {
|
|||||||
result: Res::None,
|
result: Res::None,
|
||||||
trace_address: vec![10],
|
trace_address: vec![10],
|
||||||
subtraces: 1,
|
subtraces: 1,
|
||||||
transaction_position: 11,
|
transaction_position: Some(11),
|
||||||
transaction_hash: 12.into(),
|
transaction_hash: Some(12.into()),
|
||||||
block_number: 13,
|
block_number: 13,
|
||||||
block_hash: 14.into(),
|
block_hash: 14.into(),
|
||||||
};
|
};
|
||||||
@ -705,6 +759,26 @@ mod tests {
|
|||||||
assert_eq!(serialized, r#"{"type":"suicide","action":{"address":"0x0000000000000000000000000000000000000004","refundAddress":"0x0000000000000000000000000000000000000006","balance":"0x7"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
|
assert_eq!(serialized, r#"{"type":"suicide","action":{"address":"0x0000000000000000000000000000000000000004","refundAddress":"0x0000000000000000000000000000000000000006","balance":"0x7"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_trace_reward_serialize() {
|
||||||
|
let t = LocalizedTrace {
|
||||||
|
action: Action::Reward(Reward {
|
||||||
|
author: 4.into(),
|
||||||
|
value: 6.into(),
|
||||||
|
reward_type: RewardType::Block,
|
||||||
|
}),
|
||||||
|
result: Res::None,
|
||||||
|
trace_address: vec![10],
|
||||||
|
subtraces: 1,
|
||||||
|
transaction_position: None,
|
||||||
|
transaction_hash: None,
|
||||||
|
block_number: 13,
|
||||||
|
block_hash: 14.into(),
|
||||||
|
};
|
||||||
|
let serialized = serde_json::to_string(&t).unwrap();
|
||||||
|
assert_eq!(serialized, r#"{"type":"reward","action":{"author":"0x0000000000000000000000000000000000000004","value":"0x6","rewardType":"block"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":null,"transactionHash":null,"blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vmtrace_serialize() {
|
fn test_vmtrace_serialize() {
|
||||||
let t = VMTrace {
|
let t = VMTrace {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
use std::collections::{HashSet, VecDeque};
|
use std::collections::{HashSet, VecDeque};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use ethcore::views::{BlockView};
|
use ethcore::views::{BlockView};
|
||||||
|
@ -18,6 +18,7 @@ use std::collections::{HashSet, HashMap};
|
|||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use network::NetworkError;
|
use network::NetworkError;
|
||||||
|
@ -92,6 +92,7 @@
|
|||||||
use std::collections::{HashSet, HashMap};
|
use std::collections::{HashSet, HashMap};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
use util::*;
|
use util::*;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use network::*;
|
use network::*;
|
||||||
|
@ -24,9 +24,6 @@ use std::hash::{Hash, Hasher};
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use siphasher::sip::SipHasher;
|
use siphasher::sip::SipHasher;
|
||||||
|
|
||||||
// TODO [ToDr] Both hashers are exactly the same - no point to keep two.
|
|
||||||
const NUMBER_OF_HASHERS: usize = 2;
|
|
||||||
|
|
||||||
/// BitVec structure with journalling
|
/// BitVec structure with journalling
|
||||||
/// Every time any of the blocks is getting set it's index is tracked
|
/// Every time any of the blocks is getting set it's index is tracked
|
||||||
/// and can be then drained by `drain` method
|
/// and can be then drained by `drain` method
|
||||||
@ -80,8 +77,6 @@ pub struct Bloom {
|
|||||||
bitmap: BitVecJournal,
|
bitmap: BitVecJournal,
|
||||||
bitmap_bits: u64,
|
bitmap_bits: u64,
|
||||||
k_num: u32,
|
k_num: u32,
|
||||||
// TODO [ToDr] Both hashers are exactly the same - no point to keep two.
|
|
||||||
sips: [SipHasher; NUMBER_OF_HASHERS],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bloom {
|
impl Bloom {
|
||||||
@ -93,12 +88,10 @@ impl Bloom {
|
|||||||
let bitmap_bits = (bitmap_size as u64) * 8u64;
|
let bitmap_bits = (bitmap_size as u64) * 8u64;
|
||||||
let k_num = Bloom::optimal_k_num(bitmap_bits, items_count);
|
let k_num = Bloom::optimal_k_num(bitmap_bits, items_count);
|
||||||
let bitmap = BitVecJournal::new(bitmap_bits as usize);
|
let bitmap = BitVecJournal::new(bitmap_bits as usize);
|
||||||
let sips = [SipHasher::new(), SipHasher::new()];
|
|
||||||
Bloom {
|
Bloom {
|
||||||
bitmap: bitmap,
|
bitmap: bitmap,
|
||||||
bitmap_bits: bitmap_bits,
|
bitmap_bits: bitmap_bits,
|
||||||
k_num: k_num,
|
k_num: k_num,
|
||||||
sips: sips,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,12 +100,10 @@ impl Bloom {
|
|||||||
let bitmap_size = parts.len() * 8;
|
let bitmap_size = parts.len() * 8;
|
||||||
let bitmap_bits = (bitmap_size as u64) * 8u64;
|
let bitmap_bits = (bitmap_size as u64) * 8u64;
|
||||||
let bitmap = BitVecJournal::from_parts(parts);
|
let bitmap = BitVecJournal::from_parts(parts);
|
||||||
let sips = [SipHasher::new(), SipHasher::new()];
|
|
||||||
Bloom {
|
Bloom {
|
||||||
bitmap: bitmap,
|
bitmap: bitmap,
|
||||||
bitmap_bits: bitmap_bits,
|
bitmap_bits: bitmap_bits,
|
||||||
k_num: k_num,
|
k_num: k_num,
|
||||||
sips: sips,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,9 +130,9 @@ impl Bloom {
|
|||||||
pub fn set<T>(&mut self, item: T)
|
pub fn set<T>(&mut self, item: T)
|
||||||
where T: Hash
|
where T: Hash
|
||||||
{
|
{
|
||||||
let mut hashes = [0u64, 0u64];
|
let base_hash = Bloom::sip_hash(&item);
|
||||||
for k_i in 0..self.k_num {
|
for k_i in 0..self.k_num {
|
||||||
let bit_offset = (self.bloom_hash(&mut hashes, &item, k_i) % self.bitmap_bits) as usize;
|
let bit_offset = (Bloom::bloom_hash(base_hash, k_i) % self.bitmap_bits) as usize;
|
||||||
self.bitmap.set(bit_offset);
|
self.bitmap.set(bit_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,9 +142,9 @@ impl Bloom {
|
|||||||
pub fn check<T>(&self, item: T) -> bool
|
pub fn check<T>(&self, item: T) -> bool
|
||||||
where T: Hash
|
where T: Hash
|
||||||
{
|
{
|
||||||
let mut hashes = [0u64, 0u64];
|
let base_hash = Bloom::sip_hash(&item);
|
||||||
for k_i in 0..self.k_num {
|
for k_i in 0..self.k_num {
|
||||||
let bit_offset = (self.bloom_hash(&mut hashes, &item, k_i) % self.bitmap_bits) as usize;
|
let bit_offset = (Bloom::bloom_hash(base_hash, k_i) % self.bitmap_bits) as usize;
|
||||||
if !self.bitmap.get(bit_offset) {
|
if !self.bitmap.get(bit_offset) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -178,17 +169,20 @@ impl Bloom {
|
|||||||
cmp::max(k_num, 1)
|
cmp::max(k_num, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bloom_hash<T>(&self, hashes: &mut [u64; NUMBER_OF_HASHERS], item: &T, k_i: u32) -> u64
|
fn sip_hash<T>(item: &T) -> u64
|
||||||
where T: Hash
|
where T: Hash
|
||||||
{
|
{
|
||||||
if k_i < NUMBER_OF_HASHERS as u32 {
|
let mut sip = SipHasher::new();
|
||||||
let mut sip = self.sips[k_i as usize].clone();
|
item.hash(&mut sip);
|
||||||
item.hash(&mut sip);
|
let hash = sip.finish();
|
||||||
let hash = sip.finish();
|
hash
|
||||||
hashes[k_i as usize] = hash;
|
}
|
||||||
hash
|
|
||||||
|
fn bloom_hash(base_hash: u64, k_i: u32) -> u64 {
|
||||||
|
if k_i < 2 {
|
||||||
|
base_hash
|
||||||
} else {
|
} else {
|
||||||
hashes[0].wrapping_add((k_i as u64).wrapping_mul(hashes[1]) % 0xffffffffffffffc5)
|
base_hash.wrapping_add((k_i as u64).wrapping_mul(base_hash) % 0xffffffffffffffc5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +212,7 @@ pub struct BloomJournal {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Bloom;
|
use super::Bloom;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_set() {
|
fn get_set() {
|
||||||
@ -248,4 +243,16 @@ mod tests {
|
|||||||
// 2/8/64 = 0.00390625
|
// 2/8/64 = 0.00390625
|
||||||
assert!(full >= 0.0039f64 && full <= 0.004f64);
|
assert!(full >= 0.0039f64 && full <= 0.004f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hash_backward_compatibility() {
|
||||||
|
let ss = vec!["you", "should", "not", "break", "hash", "backward", "compatibility"];
|
||||||
|
let mut bloom = Bloom::new(16, 8);
|
||||||
|
for s in ss.iter() {
|
||||||
|
bloom.set(&s);
|
||||||
|
}
|
||||||
|
let drained_elems: HashSet<u64> = bloom.drain_journal().entries.into_iter().map(|t| t.1).collect();
|
||||||
|
let expected: HashSet<u64> = [2094615114573771027u64, 244675582389208413u64].iter().cloned().collect();
|
||||||
|
assert_eq!(drained_elems, expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,6 @@ pub use bigint::prelude::*;
|
|||||||
pub use bigint::hash;
|
pub use bigint::hash;
|
||||||
|
|
||||||
pub use ansi_term::{Colour, Style};
|
pub use ansi_term::{Colour, Style};
|
||||||
pub use heapsize::HeapSizeOf;
|
|
||||||
pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||||
|
|
||||||
/// 160-bit integer representing account address
|
/// 160-bit integer representing account address
|
||||||
|
Loading…
Reference in New Issue
Block a user