Skip to content
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

chore: add evm::traces target to tracing #7167

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/evm/traces/src/identifier/etherscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl TraceIdentifier for EtherscanIdentifier {
where
A: Iterator<Item = (&'a Address, Option<&'a [u8]>)>,
{
trace!("identify {:?} addresses", addresses.size_hint().1);
trace!(target: "evm::traces", "identify {:?} addresses", addresses.size_hint().1);

let Some(client) = self.client.clone() else {
// no client was configured
Expand Down
12 changes: 6 additions & 6 deletions crates/evm/traces/src/identifier/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> LocalTraceIdentifier<'a> {
let (abi, known_code) = self.known_contracts.get(id)?;
let score = bytecode_diff_score(known_code, code);
if score == 0.0 {
trace!("found exact match");
trace!(target: "evm::traces", "found exact match");
return Some((id, abi));
}
if score < min_score {
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a> LocalTraceIdentifier<'a> {
}
}

trace!(%min_score, "no exact match found");
trace!(target: "evm::traces", %min_score, "no exact match found");

// Note: the diff score can be inaccurate for small contracts so we're using a relatively
// high threshold here to avoid filtering out too many contracts.
Expand Down Expand Up @@ -106,15 +106,15 @@ impl TraceIdentifier for LocalTraceIdentifier<'_> {
where
A: Iterator<Item = (&'a Address, Option<&'a [u8]>)>,
{
trace!("identify {:?} addresses", addresses.size_hint().1);
trace!(target: "evm::traces", "identify {:?} addresses", addresses.size_hint().1);

addresses
.filter_map(|(address, code)| {
let _span = trace_span!("identify", %address).entered();
let _span = trace_span!(target: "evm::traces", "identify", %address).entered();

trace!("identifying");
trace!(target: "evm::traces", "identifying");
let (id, abi) = self.identify_code(code?)?;
trace!(id=%id.identifier(), "identified");
trace!(target: "evm::traces", id=%id.identifier(), "identified");

Some(AddressIdentity {
address: *address,
Expand Down
16 changes: 8 additions & 8 deletions crates/evm/traces/src/identifier/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct SignaturesIdentifier {
}

impl SignaturesIdentifier {
#[instrument(target = "forge::signatures")]
#[instrument(target = "evm::traces")]
pub fn new(
cache_path: Option<PathBuf>,
offline: bool,
Expand All @@ -43,14 +43,14 @@ impl SignaturesIdentifier {

let identifier = if let Some(cache_path) = cache_path {
let path = cache_path.join("signatures");
trace!(?path, "reading signature cache");
trace!(target: "evm::traces", ?path, "reading signature cache");
let cached = if path.is_file() {
fs::read_json_file(&path)
.map_err(|err| warn!(?path, ?err, "failed to read cache file"))
.map_err(|err| warn!(target: "evm::traces", ?path, ?err, "failed to read cache file"))
.unwrap_or_default()
} else {
if let Err(err) = std::fs::create_dir_all(cache_path) {
warn!("could not create signatures cache dir: {:?}", err);
warn!(target: "evm::traces", "could not create signatures cache dir: {:?}", err);
}
CachedSignatures::default()
};
Expand All @@ -74,18 +74,18 @@ impl SignaturesIdentifier {
Ok(Arc::new(RwLock::new(identifier)))
}

#[instrument(target = "forge::signatures", skip(self))]
#[instrument(target = "evm::traces", skip(self))]
pub fn save(&self) {
if let Some(cached_path) = &self.cached_path {
if let Some(parent) = cached_path.parent() {
if let Err(err) = std::fs::create_dir_all(parent) {
warn!(?parent, ?err, "failed to create cache");
warn!(target: "evm::traces", ?parent, ?err, "failed to create cache");
}
}
if let Err(err) = fs::write_json_file(cached_path, &self.cached) {
warn!(?cached_path, ?err, "failed to flush signature cache");
warn!(target: "evm::traces", ?cached_path, ?err, "failed to flush signature cache");
} else {
trace!(?cached_path, "flushed signature cache")
trace!(target: "evm::traces", ?cached_path, "flushed signature cache")
}
}
}
Expand Down
Loading