-
Notifications
You must be signed in to change notification settings - Fork 377
Hook into EVM execution using tracing-like events #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sorpaas
merged 16 commits into
rust-ethereum:master
from
moonbeam-foundation:jeremy-environmental-hook
May 26, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ad79c30
gasometer tracing
nanocryk 94eb563
use trait methods and macro
nanocryk cc54484
fix macro
nanocryk baebf70
change back to enums
nanocryk dccd219
add StepResult event
nanocryk 1f47c18
more data in events
nanocryk c58502d
EVM events
nanocryk 6c2569a
add snapshot of gasometer state in events
nanocryk e1ac47c
add create address + suicide event
nanocryk 0b13548
Merge remote-tracking branch 'origin/master' into jeremy-environmenta…
nanocryk 5dfb3bd
runtime: use macro
nanocryk e3695a1
update all events to macros
nanocryk 29b1d27
editorconfig
nanocryk d248b17
fmt
nanocryk fbc7e86
fmt
nanocryk 3e37447
Update Cargo.toml
nanocryk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Allows to listen to gasometer events. | ||
|
||
use super::Snapshot; | ||
|
||
environmental::environmental!(listener: dyn EventListener + 'static); | ||
|
||
pub trait EventListener { | ||
fn event( | ||
&mut self, | ||
event: Event | ||
); | ||
} | ||
|
||
impl Snapshot { | ||
pub fn gas(&self) -> u64 { | ||
self.gas_limit - self.used_gas - self.memory_gas | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum Event { | ||
RecordCost { | ||
cost: u64, | ||
snapshot: Snapshot, | ||
}, | ||
RecordRefund { | ||
refund: i64, | ||
snapshot: Snapshot, | ||
}, | ||
RecordStipend { | ||
stipend: u64, | ||
snapshot: Snapshot, | ||
}, | ||
RecordDynamicCost { | ||
gas_cost: u64, | ||
memory_gas: u64, | ||
gas_refund: i64, | ||
snapshot: Snapshot, | ||
}, | ||
RecordTransaction { | ||
cost: u64, | ||
snapshot: Snapshot, | ||
}, | ||
} | ||
|
||
impl Event { | ||
pub(crate) fn emit(self) { | ||
listener::with(|listener| listener.event(self)); | ||
} | ||
} | ||
|
||
/// Run closure with provided listener. | ||
pub fn using<R, F: FnOnce() -> R>( | ||
new: &mut (dyn EventListener + 'static), | ||
f: F | ||
) -> R { | ||
listener::using(new, f) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! Allows to listen to runtime events. | ||
|
||
use crate::{Context, Opcode, Stack, Memory, Capture, ExitReason, Trap}; | ||
use primitive_types::{H160, H256}; | ||
|
||
environmental::environmental!(listener: dyn EventListener + 'static); | ||
|
||
pub trait EventListener { | ||
fn event( | ||
&mut self, | ||
event: Event | ||
); | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum Event<'a> { | ||
Step { | ||
context: &'a Context, | ||
opcode: Opcode, | ||
position: &'a Result<usize, ExitReason>, | ||
stack: &'a Stack, | ||
memory: &'a Memory | ||
}, | ||
StepResult { | ||
result: &'a Result<(), Capture<ExitReason, Trap>>, | ||
return_value: &'a [u8], | ||
}, | ||
SLoad { | ||
address: H160, | ||
index: H256, | ||
value: H256 | ||
}, | ||
SStore { | ||
address: H160, | ||
index: H256, | ||
value: H256 | ||
}, | ||
} | ||
|
||
impl<'a> Event<'a> { | ||
pub(crate) fn emit(self) { | ||
listener::with(|listener| listener.event(self)); | ||
} | ||
} | ||
|
||
/// Run closure with provided listener. | ||
pub fn using<R, F: FnOnce() -> R>( | ||
new: &mut (dyn EventListener + 'static), | ||
f: F | ||
) -> R { | ||
listener::using(new, f) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add back
unused_improts
warning here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It prevented to use
environmental
macro :/ Tried to allow it locally for the macro call but Rust complained.