From a579e79c6a044f8901c2cf505eef0b9134cd98b3 Mon Sep 17 00:00:00 2001 From: Mariusz Reichert Date: Mon, 13 Jan 2025 12:26:21 +0100 Subject: [PATCH] instrumented macro usage --- src/daemon.rs | 68 ++++++++++++++++++------------------- src/electrum/server.rs | 18 +++++----- src/lib.rs | 1 - src/new_index/fetch.rs | 14 ++++---- src/new_index/mempool.rs | 42 +++++++++++------------ src/new_index/precache.rs | 6 ++-- src/new_index/query.rs | 36 ++++++++++---------- src/rest.rs | 6 ++-- src/util/block.rs | 12 +++---- src/util/electrum_merkle.rs | 8 ++--- src/util/fees.rs | 4 +-- 11 files changed, 107 insertions(+), 108 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index 1dfe02212..8cef8feaa 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -20,7 +20,7 @@ use bitcoin::consensus::encode::{deserialize, serialize_hex}; #[cfg(feature = "liquid")] use elements::encode::{deserialize, serialize_hex}; -use tracing::instrument; +use instrumented_macro::instrumented; use crate::chain::{Block, BlockHash, BlockHeader, Network, Transaction, Txid}; use crate::metrics::{HistogramOpts, HistogramVec, Metrics}; @@ -44,7 +44,7 @@ lazy_static! { const MAX_ATTEMPTS: u32 = 5; const RETRY_WAIT_DURATION: Duration = Duration::from_secs(1); -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn parse_hash(value: &Value) -> Result where T: FromStr, @@ -58,7 +58,7 @@ where .chain_err(|| format!("non-hex value: {}", value))?) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn header_from_value(value: Value) -> Result { let header_hex = value .as_str() @@ -153,7 +153,7 @@ struct Connection { signal: Waiter, } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result { loop { match TcpStream::connect_timeout(&addr, *DAEMON_CONNECTION_TIMEOUT) { @@ -176,7 +176,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result { } impl Connection { - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn new( addr: SocketAddr, cookie_getter: Arc, @@ -196,12 +196,12 @@ impl Connection { }) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn reconnect(&self) -> Result { Connection::new(self.addr, self.cookie_getter.clone(), self.signal.clone()) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn send(&mut self, request: &str) -> Result<()> { let cookie = &self.cookie_getter.get()?; let msg = format!( @@ -215,7 +215,7 @@ impl Connection { }) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn recv(&mut self) -> Result { // TODO: use proper HTTP parser. let mut in_header = true; @@ -381,7 +381,7 @@ impl Daemon { Ok(daemon) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn reconnect(&self) -> Result { Ok(Daemon { daemon_dir: self.daemon_dir.clone(), @@ -396,7 +396,7 @@ impl Daemon { }) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn list_blk_files(&self) -> Result> { let path = self.blocks_dir.join("blk*.dat"); debug!("listing block files at {:?}", path); @@ -432,7 +432,7 @@ impl Daemon { self.network.magic() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn call_jsonrpc(&self, method: &str, request: &Value) -> Result { let mut conn = self.conn.lock().unwrap(); let timer = self.latency.with_label_values(&[method]).start_timer(); @@ -450,7 +450,7 @@ impl Daemon { Ok(result) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!(), method = %method))] + #[instrumented(method = %method)] fn handle_request(&self, method: &str, params: &Value) -> Result { let id = self.message_id.next(); let req = json!({"method": method, "params": params, "id": id}); @@ -473,12 +473,12 @@ impl Daemon { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn request(&self, method: &str, params: Value) -> Result { self.retry_request(method, ¶ms) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn retry_reconnect(&self) -> Daemon { // XXX add a max reconnection attempts limit? loop { @@ -493,14 +493,14 @@ impl Daemon { // Send requests in parallel over multiple RPC connections as individual JSON-RPC requests (with no JSON-RPC batching), // buffering the replies into a vector. If any of the requests fail, processing is terminated and an Err is returned. - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn requests(&self, method: &str, params_list: Vec) -> Result> { self.requests_iter(method, params_list).collect() } // Send requests in parallel over multiple RPC connections, iterating over the results without buffering them. // Errors are included in the iterator and do not terminate other pending requests. - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn requests_iter<'a>( &'a self, method: &'a str, @@ -523,29 +523,29 @@ impl Daemon { // bitcoind JSONRPC API: - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getblockchaininfo(&self) -> Result { let info: Value = self.request("getblockchaininfo", json!([]))?; Ok(from_value(info).chain_err(|| "invalid blockchain info")?) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn getnetworkinfo(&self) -> Result { let info: Value = self.request("getnetworkinfo", json!([]))?; Ok(from_value(info).chain_err(|| "invalid network info")?) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getbestblockhash(&self) -> Result { parse_hash(&self.request("getbestblockhash", json!([]))?) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getblockheader(&self, blockhash: &BlockHash) -> Result { header_from_value(self.request("getblockheader", json!([blockhash, /*verbose=*/ false]))?) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getblockheaders(&self, heights: &[usize]) -> Result> { let heights: Vec = heights.iter().map(|height| json!([height])).collect(); let params_list: Vec = self @@ -560,7 +560,7 @@ impl Daemon { Ok(result) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getblock(&self, blockhash: &BlockHash) -> Result { let block = block_from_value(self.request("getblock", json!([blockhash, /*verbose=*/ false]))?)?; @@ -568,12 +568,12 @@ impl Daemon { Ok(block) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getblock_raw(&self, blockhash: &BlockHash, verbose: u32) -> Result { self.request("getblock", json!([blockhash, verbose])) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getblocks(&self, blockhashes: &[BlockHash]) -> Result> { let params_list: Vec = blockhashes .iter() @@ -610,7 +610,7 @@ impl Daemon { /// Fetch the given transactions in parallel over multiple threads and RPC connections, /// ignoring any missing ones and returning whatever is available. - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn gettransactions_available(&self, txids: &[&Txid]) -> Result> { const RPC_INVALID_ADDRESS_OR_KEY: i64 = -5; @@ -635,7 +635,7 @@ impl Daemon { .collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn gettransaction_raw( &self, txid: &Txid, @@ -645,24 +645,24 @@ impl Daemon { self.request("getrawtransaction", json!([txid, verbose, blockhash])) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getmempooltx(&self, txhash: &Txid) -> Result { let value = self.request("getrawtransaction", json!([txhash, /*verbose=*/ false]))?; tx_from_value(value) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn getmempooltxids(&self) -> Result> { let res = self.request("getrawmempool", json!([/*verbose=*/ false]))?; Ok(serde_json::from_value(res).chain_err(|| "invalid getrawmempool reply")?) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn broadcast(&self, tx: &Transaction) -> Result { self.broadcast_raw(&serialize_hex(tx)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn broadcast_raw(&self, txhex: &str) -> Result { let txid = self.request("sendrawtransaction", json!([txhex]))?; Ok( @@ -674,7 +674,7 @@ impl Daemon { // Get estimated feerates for the provided confirmation targets using a batch RPC request // Missing estimates are logged but do not cause a failure, whatever is available is returned #[allow(clippy::float_cmp)] - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn estimatesmartfee_batch(&self, conf_targets: &[u16]) -> Result> { let params_list: Vec = conf_targets .iter() @@ -709,7 +709,7 @@ impl Daemon { .collect()) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn get_all_headers(&self, tip: &BlockHash) -> Result> { let info: Value = self.request("getblockheader", json!([tip]))?; let tip_height = info @@ -737,7 +737,7 @@ impl Daemon { } // Returns a list of BlockHeaders in ascending height (i.e. the tip is last). - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn get_new_headers( &self, indexed_headers: &HeaderList, @@ -770,7 +770,7 @@ impl Daemon { Ok(new_headers) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn get_relayfee(&self) -> Result { let relayfee = self.getnetworkinfo()?.relayfee; diff --git a/src/electrum/server.rs b/src/electrum/server.rs index dac8b4636..f5403ad98 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -13,7 +13,7 @@ use error_chain::ChainedError; use hex::{self, DisplayHex}; use serde_json::{from_str, Value}; -use tracing::instrument; +use instrumented_macro::instrumented; #[cfg(not(feature = "liquid"))] use bitcoin::consensus::encode::serialize_hex; @@ -71,7 +71,7 @@ fn bool_from_value_or(val: Option<&Value>, name: &str, default: bool) -> Result< } // TODO: implement caching and delta updates -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn get_status_hash(txs: Vec<(Txid, Option)>, query: &Query) -> Option { if txs.is_empty() { None @@ -264,7 +264,7 @@ impl Connection { })) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn blockchain_estimatefee(&self, params: &[Value]) -> Result { let conf_target = usize_from_value(params.get(0), "blocks_count")?; let fee_rate = self @@ -392,7 +392,7 @@ impl Connection { Ok(json!(rawtx.to_lower_hex_string())) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn blockchain_transaction_get_merkle(&self, params: &[Value]) -> Result { let txid = Txid::from(hash_from_value(params.get(0)).chain_err(|| "bad tx_hash")?); let height = usize_from_value(params.get(1), "height")?; @@ -430,7 +430,7 @@ impl Connection { })) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!(), method = %method))] + #[instrumented(method = %method)] fn handle_command(&mut self, method: &str, params: &[Value], id: &Value) -> Result { let timer = self .stats @@ -487,7 +487,7 @@ impl Connection { }) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn update_subscriptions(&mut self) -> Result> { let timer = self .stats @@ -545,7 +545,7 @@ impl Connection { Ok(()) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn handle_replies(&mut self, receiver: Receiver) -> Result<()> { let empty_params = json!([]); loop { @@ -610,7 +610,7 @@ impl Connection { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn parse_requests(mut reader: BufReader, tx: &SyncSender) -> Result<()> { loop { let mut line = Vec::::new(); @@ -673,7 +673,7 @@ impl Connection { } } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn get_history( query: &Query, scripthash: &[u8], diff --git a/src/lib.rs b/src/lib.rs index a2c6e0a28..1bdad259e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,6 @@ extern crate log; extern crate serde_derive; #[macro_use] extern crate serde_json; - #[macro_use] extern crate lazy_static; diff --git a/src/new_index/fetch.rs b/src/new_index/fetch.rs index 7bcdc6d33..d7aaae5fb 100644 --- a/src/new_index/fetch.rs +++ b/src/new_index/fetch.rs @@ -14,7 +14,7 @@ use std::path::PathBuf; use std::sync::mpsc::Receiver; use std::thread; -use tracing::instrument; +use instrumented_macro::instrumented; use crate::chain::{Block, BlockHash}; use crate::daemon::Daemon; @@ -27,7 +27,7 @@ pub enum FetchFrom { BlkFiles, } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn start_fetcher( from: FetchFrom, daemon: &Daemon, @@ -70,7 +70,7 @@ impl Fetcher { } } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn bitcoind_fetcher( daemon: &Daemon, new_headers: Vec, @@ -109,7 +109,7 @@ fn bitcoind_fetcher( )) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn blkfiles_fetcher( daemon: &Daemon, new_headers: Vec, @@ -157,7 +157,7 @@ fn blkfiles_fetcher( )) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn blkfiles_reader(blk_files: Vec, xor_key: Option<[u8; 8]>) -> Fetcher> { let chan = SyncChannel::new(1); let sender = chan.sender(); @@ -188,7 +188,7 @@ fn blkfile_apply_xor_key(xor_key: [u8; 8], blob: &mut [u8]) { } } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn blkfiles_parser(blobs: Fetcher>, magic: u32) -> Fetcher> { let chan = SyncChannel::new(1); let sender = chan.sender(); @@ -207,7 +207,7 @@ fn blkfiles_parser(blobs: Fetcher>, magic: u32) -> Fetcher, magic: u32) -> Result> { let mut cursor = Cursor::new(&blob); let mut slices = vec![]; diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index f768fb8d9..3d1b328f2 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -11,7 +11,7 @@ use std::iter::FromIterator; use std::sync::{Arc, RwLock}; use std::time::{Duration, Instant}; -use tracing::instrument; +use instrumented_macro::instrumented; use crate::chain::{deserialize, BlockHash, Network, OutPoint, Transaction, TxOut, Txid}; use crate::config::Config; use crate::daemon::Daemon; @@ -108,7 +108,7 @@ impl Mempool { self.txstore.get(txid).map(serialize) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_spend(&self, outpoint: &OutPoint) -> Option { self.edges.get(outpoint).map(|(txid, vin)| SpendingInput { txid: *txid, @@ -125,7 +125,7 @@ impl Mempool { Some(self.feeinfo.get(txid)?.fee) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn has_unconfirmed_parents(&self, txid: &Txid) -> bool { let tx = match self.txstore.get(txid) { Some(tx) => tx, @@ -136,7 +136,7 @@ impl Mempool { .any(|txin| self.txstore.contains_key(&txin.previous_output.txid)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn history(&self, scripthash: &[u8], limit: usize) -> Vec { let _timer = self.latency.with_label_values(&["history"]).start_timer(); self.history @@ -144,7 +144,7 @@ impl Mempool { .map_or_else(|| vec![], |entries| self._history(entries, limit)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn _history(&self, entries: &[TxHistoryInfo], limit: usize) -> Vec { entries .iter() @@ -156,7 +156,7 @@ impl Mempool { .collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn history_txids(&self, scripthash: &[u8], limit: usize) -> Vec { let _timer = self .latency @@ -173,7 +173,7 @@ impl Mempool { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn utxo(&self, scripthash: &[u8]) -> Vec { let _timer = self.latency.with_label_values(&["utxo"]).start_timer(); let entries = match self.history.get(scripthash) { @@ -216,7 +216,7 @@ impl Mempool { .collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] // @XXX avoid code duplication with ChainQuery::stats()? pub fn stats(&self, scripthash: &[u8]) -> ScriptStats { let _timer = self.latency.with_label_values(&["stats"]).start_timer(); @@ -266,14 +266,14 @@ impl Mempool { stats } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] // Get all txids in the mempool pub fn txids(&self) -> Vec<&Txid> { let _timer = self.latency.with_label_values(&["txids"]).start_timer(); self.txstore.keys().collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] // Get an overview of the most recent transactions pub fn recent_txs_overview(&self) -> Vec<&TxOverview> { // We don't bother ever deleting elements from the recent list. @@ -282,17 +282,17 @@ impl Mempool { self.recent.iter().collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn backlog_stats(&self) -> &BacklogStats { &self.backlog_stats.0 } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn txids_set(&self) -> HashSet { return HashSet::from_iter(self.txstore.keys().cloned()); } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn update_backlog_stats(&mut self) { let _timer = self .latency @@ -301,7 +301,7 @@ impl Mempool { self.backlog_stats = (BacklogStats::new(&self.feeinfo), Instant::now()); } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn add_by_txid(&mut self, daemon: &Daemon, txid: Txid) -> Result<()> { if self.txstore.get(&txid).is_none() { if let Ok(tx) = daemon.getmempooltx(&txid) { @@ -316,7 +316,7 @@ impl Mempool { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn add(&mut self, txs_map: HashMap) -> Result<()> { self.delta .with_label_values(&["add"]) @@ -429,14 +429,14 @@ impl Mempool { Ok(()) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn lookup_txo(&self, outpoint: &OutPoint) -> Option { self.txstore .get(&outpoint.txid) .and_then(|tx| tx.output.get(outpoint.vout as usize).cloned()) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_txos(&self, outpoints: BTreeSet) -> Result> { let _timer = self .latency @@ -458,7 +458,7 @@ impl Mempool { Ok(txos) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn remove(&mut self, to_remove: HashSet<&Txid>) { self.delta .with_label_values(&["remove"]) @@ -494,7 +494,7 @@ impl Mempool { } #[cfg(feature = "liquid")] - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn asset_history(&self, asset_id: &AssetId, limit: usize) -> Vec { let _timer = self .latency @@ -507,7 +507,7 @@ impl Mempool { /// Sync our local view of the mempool with the bitcoind Daemon RPC. If the chain tip moves before /// the mempool is fetched in full, syncing is aborted and an Ok(false) is returned. - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn update( mempool: &Arc>, daemon: &Daemon, @@ -619,7 +619,7 @@ impl BacklogStats { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn new(feeinfo: &HashMap) -> Self { let (count, vsize, total_fee) = feeinfo .values() diff --git a/src/new_index/precache.rs b/src/new_index/precache.rs index 402f107dd..a439c355b 100644 --- a/src/new_index/precache.rs +++ b/src/new_index/precache.rs @@ -13,9 +13,9 @@ use std::io; use std::io::prelude::*; use std::str::FromStr; -use tracing::instrument; +use instrumented_macro::instrumented; -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn precache(chain: &ChainQuery, scripthashes: Vec) { let total = scripthashes.len(); info!("Pre-caching stats and utxo set for {} scripthashes", total); @@ -39,7 +39,7 @@ pub fn precache(chain: &ChainQuery, scripthashes: Vec) { }); } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn scripthashes_from_file(path: String) -> Result> { let reader = io::BufReader::new(File::open(path).chain_err(|| "cannot open precache scripthash file")?); diff --git a/src/new_index/query.rs b/src/new_index/query.rs index d10c468e4..b5da380f8 100644 --- a/src/new_index/query.rs +++ b/src/new_index/query.rs @@ -11,7 +11,7 @@ use crate::errors::*; use crate::new_index::{ChainQuery, Mempool, ScriptStats, SpendingInput, Utxo}; use crate::util::{is_spendable, BlockId, Bytes, TransactionStatus}; -use tracing::instrument; +use instrumented_macro::instrumented; #[cfg(feature = "liquid")] use crate::{ @@ -71,7 +71,7 @@ impl Query { self.mempool.read().unwrap() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn broadcast_raw(&self, txhex: &str) -> Result { let txid = self.daemon.broadcast_raw(txhex)?; let _ = self @@ -82,7 +82,7 @@ impl Query { Ok(txid) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn utxo(&self, scripthash: &[u8]) -> Result> { let mut utxos = self.chain.utxo(scripthash, self.config.utxos_limit)?; let mempool = self.mempool(); @@ -91,7 +91,7 @@ impl Query { Ok(utxos) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn history_txids(&self, scripthash: &[u8], limit: usize) -> Vec<(Txid, Option)> { let confirmed_txids = self.chain.history_txids(scripthash, limit); let confirmed_len = confirmed_txids.len(); @@ -113,21 +113,21 @@ impl Query { ) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_txn(&self, txid: &Txid) -> Option { self.chain .lookup_txn(txid, None) .or_else(|| self.mempool().lookup_txn(txid)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_raw_txn(&self, txid: &Txid) -> Option { self.chain .lookup_raw_txn(txid, None) .or_else(|| self.mempool().lookup_raw_txn(txid)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_txos(&self, outpoints: BTreeSet) -> HashMap { // the mempool lookup_txos() internally looks up confirmed txos as well self.mempool() @@ -135,14 +135,14 @@ impl Query { .expect("failed loading txos") } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_spend(&self, outpoint: &OutPoint) -> Option { self.chain .lookup_spend(outpoint) .or_else(|| self.mempool().lookup_spend(outpoint)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_tx_spends(&self, tx: Transaction) -> Vec> { let txid = tx.txid(); @@ -162,22 +162,22 @@ impl Query { .collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn get_tx_status(&self, txid: &Txid) -> TransactionStatus { TransactionStatus::from(self.chain.tx_confirming_block(txid)) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn get_mempool_tx_fee(&self, txid: &Txid) -> Option { self.mempool().get_tx_fee(txid) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn has_unconfirmed_parents(&self, txid: &Txid) -> bool { self.mempool().has_unconfirmed_parents(txid) } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn estimate_fee(&self, conf_target: u16) -> Option { if self.config.network_type.is_regtest() { return self.get_relayfee().ok(); @@ -197,7 +197,7 @@ impl Query { .copied() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn estimate_fee_map(&self) -> HashMap { if let (ref cache, Some(cache_time)) = *self.cached_estimates.read().unwrap() { if cache_time.elapsed() < Duration::from_secs(FEE_ESTIMATES_TTL) { @@ -209,7 +209,7 @@ impl Query { self.cached_estimates.read().unwrap().0.clone() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] fn update_fee_estimates(&self) { match self.daemon.estimatesmartfee_batch(&CONF_TARGETS) { Ok(estimates) => { @@ -221,7 +221,7 @@ impl Query { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn get_relayfee(&self) -> Result { if let Some(cached) = *self.cached_relayfee.read().unwrap() { return Ok(cached); @@ -252,13 +252,13 @@ impl Query { } #[cfg(feature = "liquid")] - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn lookup_asset(&self, asset_id: &AssetId) -> Result> { lookup_asset(&self, self.asset_db.as_ref(), asset_id, None) } #[cfg(feature = "liquid")] - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn list_registry_assets( &self, start_index: usize, diff --git a/src/rest.rs b/src/rest.rs index d38dcb0a3..471395912 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -24,7 +24,7 @@ use tokio::sync::oneshot; use std::fs; use std::str::FromStr; -use tracing::instrument; +use instrumented_macro::instrumented; #[cfg(feature = "liquid")] use { @@ -581,7 +581,7 @@ impl Handle { } } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn handle_request( method: Method, uri: hyper::Uri, @@ -1155,7 +1155,7 @@ fn json_response(value: T, ttl: u32) -> Result, Htt .unwrap()) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] fn blocks(query: &Query, start_height: Option) -> Result, HttpError> { let mut values = Vec::new(); let mut current_hash = match start_height { diff --git a/src/util/block.rs b/src/util/block.rs index bbd219895..a8a6aee03 100644 --- a/src/util/block.rs +++ b/src/util/block.rs @@ -9,7 +9,7 @@ use std::slice; use time::format_description::well_known::Rfc3339; use time::OffsetDateTime as DateTime; -use tracing::instrument; +use instrumented_macro::instrumented; const MTP_SPAN: usize = 11; @@ -94,7 +94,7 @@ impl HeaderList { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn new( mut headers_map: HashMap, tip_hash: BlockHash, @@ -132,7 +132,7 @@ impl HeaderList { headers } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn order(&self, new_headers: Vec) -> Vec { // header[i] -> header[i-1] (i.e. header.last() is the tip) struct HashedHeader { @@ -172,7 +172,7 @@ impl HeaderList { .collect() } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn apply(&mut self, new_headers: Vec) { // new_headers[i] -> new_headers[i - 1] (i.e. new_headers.last() is the tip) for i in 1..new_headers.len() { @@ -210,7 +210,7 @@ impl HeaderList { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn header_by_blockhash(&self, blockhash: &BlockHash) -> Option<&HeaderEntry> { let height = self.heights.get(blockhash)?; let header = self.headers.get(*height)?; @@ -221,7 +221,7 @@ impl HeaderList { } } - #[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] + #[instrumented] pub fn header_by_height(&self, height: usize) -> Option<&HeaderEntry> { self.headers.get(height).map(|entry| { assert_eq!(entry.height(), height); diff --git a/src/util/electrum_merkle.rs b/src/util/electrum_merkle.rs index 0ad6eeae0..8b146705e 100644 --- a/src/util/electrum_merkle.rs +++ b/src/util/electrum_merkle.rs @@ -3,9 +3,9 @@ use crate::errors::*; use crate::new_index::ChainQuery; use bitcoin::hashes::{sha256d::Hash as Sha256dHash, Hash}; -use tracing::instrument; +use instrumented_macro::instrumented; -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn get_tx_merkle_proof( chain: &ChainQuery, tx_hash: &Txid, @@ -24,7 +24,7 @@ pub fn get_tx_merkle_proof( Ok((branch, pos)) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn get_header_merkle_proof( chain: &ChainQuery, height: usize, @@ -53,7 +53,7 @@ pub fn get_header_merkle_proof( let header_hashes = header_hashes.into_iter().map(Sha256dHash::from).collect(); Ok(create_merkle_branch_and_root(header_hashes, height)) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn get_id_from_pos( chain: &ChainQuery, height: usize, diff --git a/src/util/fees.rs b/src/util/fees.rs index a3f62c351..eb3d61b15 100644 --- a/src/util/fees.rs +++ b/src/util/fees.rs @@ -1,7 +1,7 @@ use crate::chain::{Network, Transaction, TxOut}; use std::collections::HashMap; -use tracing::instrument; +use instrumented_macro::instrumented; const VSIZE_BIN_WIDTH: u64 = 50_000; // in vbytes @@ -48,7 +48,7 @@ pub fn get_tx_fee(tx: &Transaction, _prevouts: &HashMap, network: N tx.fee_in(*network.native_asset()) } -#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))] +#[instrumented] pub fn make_fee_histogram(mut entries: Vec<&TxFeeInfo>) -> Vec<(f64, u64)> { entries.sort_unstable_by(|e1, e2| e1.fee_per_vbyte.partial_cmp(&e2.fee_per_vbyte).unwrap());