Tracing for rewards added. Without tests for now
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
use util::{Bytes, Address, U256};
|
||||
use evm::action_params::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};
|
||||
|
||||
/// Simple executive tracer. Traces all calls and creates. Ignores delegatecalls.
|
||||
@@ -162,6 +162,21 @@ impl Tracer for ExecutiveTracer {
|
||||
debug!(target: "trace", "Traced failed suicide {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
}
|
||||
|
||||
fn trace_reward(&mut self, miner: Address, value: U256, reward_type: RewardType) {
|
||||
let trace = FlatTrace {
|
||||
subtraces: 0,
|
||||
action: Action::Reward(Reward {
|
||||
miner: miner,
|
||||
value: value,
|
||||
reward_type: reward_type,
|
||||
}),
|
||||
result: Res::None,
|
||||
trace_address: Default::default(),
|
||||
};
|
||||
debug!(target: "trace", "Traced failed reward {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
}
|
||||
|
||||
fn subtracer(&self) -> Self {
|
||||
ExecutiveTracer::default()
|
||||
|
||||
@@ -33,7 +33,7 @@ pub use self::localized::LocalizedTrace;
|
||||
|
||||
pub use self::types::{filter, flat, localized, trace};
|
||||
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::filter::{Filter, AddressesFilter};
|
||||
|
||||
@@ -81,6 +81,9 @@ pub trait Tracer: Send {
|
||||
/// Stores suicide info.
|
||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address);
|
||||
|
||||
/// Stores reward info.
|
||||
fn trace_reward(&mut self, miner: Address, value: U256, reward_type: RewardType);
|
||||
|
||||
/// Spawn subtracer which will be used to trace deeper levels of execution.
|
||||
fn subtracer(&self) -> Self where Self: Sized;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use util::{Bytes, Address, U256};
|
||||
use evm::action_params::ActionParams;
|
||||
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.
|
||||
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_reward(&mut self, miner: Address, value: U256, reward_type: RewardType) {
|
||||
}
|
||||
|
||||
fn subtracer(&self) -> Self {
|
||||
NoopTracer
|
||||
}
|
||||
|
||||
@@ -128,6 +128,10 @@ impl Filter {
|
||||
let from_matches = self.from_address.matches(&suicide.address);
|
||||
let to_matches = self.to_address.matches(&suicide.refund_address);
|
||||
from_matches && to_matches
|
||||
},
|
||||
Action::Reward(ref reward) => {
|
||||
let to_matches = self.to_address.matches(&reward.miner);
|
||||
to_matches
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +218,81 @@ impl Create {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reward type.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[cfg_attr(feature = "ipc", binary)]
|
||||
pub enum RewardType {
|
||||
/// None
|
||||
None,
|
||||
/// Block
|
||||
Block,
|
||||
/// Uncle
|
||||
Uncle,
|
||||
}
|
||||
|
||||
impl Encodable for RewardType {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
let v = match *self {
|
||||
RewardType::None => 0u32,
|
||||
RewardType::Block => 1,
|
||||
RewardType::Uncle => 2,
|
||||
};
|
||||
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::None,
|
||||
1 => RewardType::Block,
|
||||
2 => 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 {
|
||||
/// Miner's address.
|
||||
pub miner: 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(&self.miner.sha3())
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for Reward {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(2);
|
||||
s.append(&self.miner);
|
||||
s.append(&self.value);
|
||||
s.append(&self.reward_type);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Reward {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
let res = Reward {
|
||||
miner: rlp.val_at(0)?,
|
||||
value: rlp.val_at(1)?,
|
||||
reward_type: rlp.val_at(2)?,
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Suicide action.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "ipc", binary)]
|
||||
@@ -260,7 +335,7 @@ impl Decodable for Suicide {
|
||||
}
|
||||
|
||||
|
||||
/// Description of an action that we trace; will be either a call or a create.
|
||||
/// Description of an action that we trace.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "ipc", binary)]
|
||||
pub enum Action {
|
||||
@@ -270,6 +345,8 @@ pub enum Action {
|
||||
Create(Create),
|
||||
/// Suicide.
|
||||
Suicide(Suicide),
|
||||
/// Reward
|
||||
Reward(Reward),
|
||||
}
|
||||
|
||||
impl Encodable for Action {
|
||||
@@ -287,7 +364,12 @@ impl Encodable for Action {
|
||||
Action::Suicide(ref suicide) => {
|
||||
s.append(&2u8);
|
||||
s.append(suicide);
|
||||
},
|
||||
Action::Reward(ref reward) => {
|
||||
s.append(&3u8);
|
||||
s.append(reward);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,6 +381,7 @@ impl Decodable for Action {
|
||||
0 => rlp.val_at(1).map(Action::Call),
|
||||
1 => rlp.val_at(1).map(Action::Create),
|
||||
2 => rlp.val_at(1).map(Action::Suicide),
|
||||
3 => rlp.val_at(1).map(Action::Reward),
|
||||
_ => Err(DecoderError::Custom("Invalid action type.")),
|
||||
}
|
||||
}
|
||||
@@ -311,6 +394,7 @@ impl Action {
|
||||
Action::Call(ref call) => call.bloom(),
|
||||
Action::Create(ref create) => create.bloom(),
|
||||
Action::Suicide(ref suicide) => suicide.bloom(),
|
||||
Action::Reward(ref reward) => reward.bloom(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user