diff --git a/src/bin/electrs.rs b/src/bin/electrs.rs index 8b09f568d..8e52a4758 100644 --- a/src/bin/electrs.rs +++ b/src/bin/electrs.rs @@ -154,7 +154,9 @@ fn main_() { } #[cfg(not(feature = "otlp-tracing"))] -fn main() { main_() } +fn main() { + main_() +} #[cfg(feature = "otlp-tracing")] #[tokio::main] diff --git a/src/bin/tx-fingerprint-stats.rs b/src/bin/tx-fingerprint-stats.rs index 94a3821ab..5be313d77 100644 --- a/src/bin/tx-fingerprint-stats.rs +++ b/src/bin/tx-fingerprint-stats.rs @@ -83,13 +83,15 @@ fn main() { //info!("{:?},{:?}", txid, blockid); - let prevouts = chain.lookup_txos( - tx.input - .iter() - .filter(|txin| has_prevout(txin)) - .map(|txin| txin.previous_output) - .collect(), - ).unwrap(); + let prevouts = chain + .lookup_txos( + tx.input + .iter() + .filter(|txin| has_prevout(txin)) + .map(|txin| txin.previous_output) + .collect(), + ) + .unwrap(); let total_out: u64 = tx.output.iter().map(|out| out.value.to_sat()).sum(); let small_out = tx diff --git a/src/daemon.rs b/src/daemon.rs index 34d935830..33f7e7c62 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -43,7 +43,7 @@ lazy_static! { const MAX_ATTEMPTS: u32 = 5; const RETRY_WAIT_DURATION: Duration = Duration::from_secs(1); -#[instrument(skip_all, name="Daemon::parse_hash")] +#[instrument(skip_all, name = "Daemon::parse_hash")] fn parse_hash(value: &Value) -> Result where T: FromStr, @@ -57,7 +57,7 @@ where .chain_err(|| format!("non-hex value: {}", value))?) } -#[instrument(skip_all, name="Daemon::header_from_value")] +#[instrument(skip_all, name = "Daemon::header_from_value")] fn header_from_value(value: Value) -> Result { let header_hex = value .as_str() @@ -149,7 +149,7 @@ struct Connection { signal: Waiter, } -#[instrument(skip_all, name="Daemon::tcp_connect")] +#[instrument(skip_all, name = "Daemon::tcp_connect")] fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result { loop { match TcpStream::connect_timeout(&addr, *DAEMON_CONNECTION_TIMEOUT) { @@ -172,7 +172,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result { } impl Connection { - #[instrument(skip_all, name="Daemon::Connection::new")] + #[instrument(skip_all, name = "Daemon::Connection::new")] fn new( addr: SocketAddr, cookie_getter: Arc, @@ -197,7 +197,7 @@ impl Connection { Connection::new(self.addr, self.cookie_getter.clone(), self.signal.clone()) } - #[instrument(skip_all, name="Daemon::Connection::send")] + #[instrument(skip_all, name = "Daemon::Connection::send")] fn send(&mut self, request: &str) -> Result<()> { let cookie = &self.cookie_getter.get()?; let msg = format!( @@ -211,7 +211,7 @@ impl Connection { }) } - #[instrument(skip_all, name="Daemon::Connection::recv")] + #[instrument(skip_all, name = "Daemon::Connection::recv")] fn recv(&mut self) -> Result { // TODO: use proper HTTP parser. let mut in_header = true; @@ -392,7 +392,7 @@ impl Daemon { }) } - #[instrument(skip_all, name="Daemon::list_blk_files")] + #[instrument(skip_all, name = "Daemon::list_blk_files")] pub fn list_blk_files(&self) -> Result> { let path = self.blocks_dir.join("blk*.dat"); debug!("listing block files at {:?}", path); @@ -408,7 +408,7 @@ impl Daemon { self.network.magic() } - #[instrument(skip_all, name="Daemon::call_jsonrpc")] + #[instrument(skip_all, name = "Daemon::call_jsonrpc")] 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(); @@ -426,7 +426,7 @@ impl Daemon { Ok(result) } - #[instrument(skip_all, name="Daemon::handle_request")] + #[instrument(skip_all, name = "Daemon::handle_request")] fn handle_request(&self, method: &str, params: &Value) -> Result { let id = self.message_id.next(); let req = json!({"method": method, "params": params, "id": id}); @@ -434,7 +434,7 @@ impl Daemon { parse_jsonrpc_reply(reply, method, id) } - #[instrument(skip_all, name="Daemon::retry_request")] + #[instrument(skip_all, name = "Daemon::retry_request")] fn retry_request(&self, method: &str, params: &Value) -> Result { loop { match self.handle_request(method, ¶ms) { @@ -450,7 +450,7 @@ impl Daemon { } } - #[instrument(skip_all, name="Daemon::request")] + #[instrument(skip_all, name = "Daemon::request")] fn request(&self, method: &str, params: Value) -> Result { self.retry_request(method, ¶ms) } @@ -467,7 +467,7 @@ impl Daemon { } } - #[instrument(skip_all, name="Daemon::requests")] + #[instrument(skip_all, name = "Daemon::requests")] // 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. fn requests(&self, method: &str, params_list: Vec) -> Result> { @@ -498,29 +498,29 @@ impl Daemon { // bitcoind JSONRPC API: - #[instrument(skip_all, name="Daemon::getblockchaininfo")] + #[instrument(skip_all, name = "Daemon::getblockchaininfo")] pub fn getblockchaininfo(&self) -> Result { let info: Value = self.request("getblockchaininfo", json!([]))?; Ok(from_value(info).chain_err(|| "invalid blockchain info")?) } - #[instrument(skip_all, name="Daemon::getnetworkinfo")] + #[instrument(skip_all, name = "Daemon::getnetworkinfo")] fn getnetworkinfo(&self) -> Result { let info: Value = self.request("getnetworkinfo", json!([]))?; Ok(from_value(info).chain_err(|| "invalid network info")?) } - #[instrument(skip_all, name="Daemon::getbestblockhash")] + #[instrument(skip_all, name = "Daemon::getbestblockhash")] pub fn getbestblockhash(&self) -> Result { parse_hash(&self.request("getbestblockhash", json!([]))?) } - #[instrument(skip_all, name="Daemon::getblockheader")] + #[instrument(skip_all, name = "Daemon::getblockheader")] pub fn getblockheader(&self, blockhash: &BlockHash) -> Result { header_from_value(self.request("getblockheader", json!([blockhash, /*verbose=*/ false]))?) } - #[instrument(skip_all, name="Daemon::getblockheaders")] + #[instrument(skip_all, name = "Daemon::getblockheaders")] pub fn getblockheaders(&self, heights: &[usize]) -> Result> { let heights: Vec = heights.iter().map(|height| json!([height])).collect(); let params_list: Vec = self @@ -535,7 +535,7 @@ impl Daemon { Ok(result) } - #[instrument(skip_all, name="Daemon::getblock")] + #[instrument(skip_all, name = "Daemon::getblock")] pub fn getblock(&self, blockhash: &BlockHash) -> Result { let block = block_from_value(self.request("getblock", json!([blockhash, /*verbose=*/ false]))?)?; @@ -543,12 +543,12 @@ impl Daemon { Ok(block) } - #[instrument(skip_all, name="Daemon::getblock_raw")] + #[instrument(skip_all, name = "Daemon::getblock_raw")] pub fn getblock_raw(&self, blockhash: &BlockHash, verbose: u32) -> Result { self.request("getblock", json!([blockhash, verbose])) } - #[instrument(skip_all, name="Daemon::getblocks")] + #[instrument(skip_all, name = "Daemon::getblocks")] pub fn getblocks(&self, blockhashes: &[BlockHash]) -> Result> { let params_list: Vec = blockhashes .iter() @@ -585,7 +585,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, name="Daemon::gettransactions_available")] + #[instrument(skip_all, name = "Daemon::gettransactions_available")] pub fn gettransactions_available(&self, txids: &[&Txid]) -> Result> { const RPC_INVALID_ADDRESS_OR_KEY: i64 = -5; @@ -610,7 +610,7 @@ impl Daemon { .collect() } - #[instrument(skip_all, name="Daemon::gettransaction_raw")] + #[instrument(skip_all, name = "Daemon::gettransaction_raw")] pub fn gettransaction_raw( &self, txid: &Txid, @@ -620,24 +620,24 @@ impl Daemon { self.request("getrawtransaction", json!([txid, verbose, blockhash])) } - #[instrument(skip_all, name="getmempooltx")] + #[instrument(skip_all, name = "getmempooltx")] pub fn getmempooltx(&self, txhash: &Txid) -> Result { let value = self.request("getrawtransaction", json!([txhash, /*verbose=*/ false]))?; tx_from_value(value) } - #[instrument(skip_all, name="getmempooltxids")] + #[instrument(skip_all, name = "getmempooltxids")] 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, name="broadcast")] + #[instrument(skip_all, name = "broadcast")] pub fn broadcast(&self, tx: &Transaction) -> Result { self.broadcast_raw(&serialize_hex(tx)) } - #[instrument(skip_all, name="broadcast_raw")] + #[instrument(skip_all, name = "broadcast_raw")] pub fn broadcast_raw(&self, txhex: &str) -> Result { let txid = self.request("sendrawtransaction", json!([txhex]))?; Ok( @@ -649,7 +649,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, name="Daemon::estimatesmartfee_batch")] + #[instrument(skip_all, name = "Daemon::estimatesmartfee_batch")] pub fn estimatesmartfee_batch(&self, conf_targets: &[u16]) -> Result> { let params_list: Vec = conf_targets .iter() @@ -684,7 +684,7 @@ impl Daemon { .collect()) } - #[instrument(skip_all, name="Daemon::get_all_headers")] + #[instrument(skip_all, name = "Daemon::get_all_headers")] fn get_all_headers(&self, tip: &BlockHash) -> Result> { let info: Value = self.request("getblockheader", json!([tip]))?; let tip_height = info @@ -712,7 +712,7 @@ impl Daemon { } // Returns a list of BlockHeaders in ascending height (i.e. the tip is last). - #[instrument(skip_all, name="Daemon::get_new_headers")] + #[instrument(skip_all, name = "Daemon::get_new_headers")] pub fn get_new_headers( &self, indexed_headers: &HeaderList, @@ -745,7 +745,7 @@ impl Daemon { Ok(new_headers) } - #[instrument(skip_all, name="Daemon::get_relayfee")] + #[instrument(skip_all, name = "Daemon::get_relayfee")] pub fn get_relayfee(&self) -> Result { let relayfee = self.getnetworkinfo()?.relayfee; diff --git a/src/electrum/discovery.rs b/src/electrum/discovery.rs index cf70221f6..f5bb85588 100644 --- a/src/electrum/discovery.rs +++ b/src/electrum/discovery.rs @@ -547,23 +547,33 @@ mod tests { false, None, )); - discovery.add_default_server( - "electrum.blockstream.info".into(), - vec![Service::Tcp(60001)], - ).unwrap(); - discovery.add_default_server("testnet.hsmiths.com".into(), vec![Service::Ssl(53012)]).unwrap(); - discovery.add_default_server( - "tn.not.fyi".into(), - vec![Service::Tcp(55001), Service::Ssl(55002)], - ).unwrap(); - discovery.add_default_server( - "electrum.blockstream.info".into(), - vec![Service::Tcp(60001), Service::Ssl(60002)], - ).unwrap(); - discovery.add_default_server( - "explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion".into(), - vec![Service::Tcp(143)], - ).unwrap(); + discovery + .add_default_server( + "electrum.blockstream.info".into(), + vec![Service::Tcp(60001)], + ) + .unwrap(); + discovery + .add_default_server("testnet.hsmiths.com".into(), vec![Service::Ssl(53012)]) + .unwrap(); + discovery + .add_default_server( + "tn.not.fyi".into(), + vec![Service::Tcp(55001), Service::Ssl(55002)], + ) + .unwrap(); + discovery + .add_default_server( + "electrum.blockstream.info".into(), + vec![Service::Tcp(60001), Service::Ssl(60002)], + ) + .unwrap(); + discovery + .add_default_server( + "explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion".into(), + vec![Service::Tcp(143)], + ) + .unwrap(); debug!("{:#?}", discovery); diff --git a/src/electrum/server.rs b/src/electrum/server.rs index b2cfe7274..196916712 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -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, name="electrum::server::get_status_hash")] +#[instrument(skip_all, name = "electrum::server::get_status_hash")] fn get_status_hash(txs: Vec<(Txid, Option)>, query: &Query) -> Option { if txs.is_empty() { None @@ -206,7 +206,7 @@ impl Connection { Ok(json!(&self.query.mempool().backlog_stats().fee_histogram)) } - #[instrument(skip_all, name="electrum::server::blockchain_block_header")] + #[instrument(skip_all, name = "electrum::server::blockchain_block_header")] fn blockchain_block_header(&self, params: &[Value]) -> Result { let height = usize_from_value(params.get(0), "height")?; let cp_height = usize_from_value_or(params.get(1), "cp_height", 0)?; @@ -230,7 +230,7 @@ impl Connection { })) } - #[instrument(skip_all, name="electrum::serer::blockchain_block_headers")] + #[instrument(skip_all, name = "electrum::serer::blockchain_block_headers")] fn blockchain_block_headers(&self, params: &[Value]) -> Result { let start_height = usize_from_value(params.get(0), "start_height")?; let count = MAX_HEADERS.min(usize_from_value(params.get(1), "count")?); @@ -266,7 +266,7 @@ impl Connection { })) } - #[instrument(skip_all, name="electrum::server::blockchain_estimatefee")] + #[instrument(skip_all, name = "electrum::server::blockchain_estimatefee")] fn blockchain_estimatefee(&self, params: &[Value]) -> Result { let conf_target = usize_from_value(params.get(0), "blocks_count")?; let fee_rate = self @@ -277,14 +277,14 @@ impl Connection { Ok(json!(fee_rate / 100_000f64)) } - #[instrument(skip_all, name="electrum::server::blockchain_relayfee")] + #[instrument(skip_all, name = "electrum::server::blockchain_relayfee")] fn blockchain_relayfee(&self) -> Result { let relayfee = self.query.get_relayfee()?; // convert from sat/b to BTC/kB, as expected by Electrum clients Ok(json!(relayfee / 100_000f64)) } - #[instrument(skip_all, name="electrum::server::blockchain_scripthash_subscribe")] + #[instrument(skip_all, name = "electrum::server::blockchain_scripthash_subscribe")] fn blockchain_scripthash_subscribe(&mut self, params: &[Value]) -> Result { let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; @@ -311,7 +311,7 @@ impl Connection { } #[cfg(not(feature = "liquid"))] - #[instrument(skip_all, name="electrum::server::blockchain_scripthash_get_balance")] + #[instrument(skip_all, name = "electrum::server::blockchain_scripthash_get_balance")] fn blockchain_scripthash_get_balance(&self, params: &[Value]) -> Result { let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; let (chain_stats, mempool_stats) = self.query.stats(&script_hash[..]); @@ -322,7 +322,7 @@ impl Connection { })) } - #[instrument(skip_all, name="electrum::server::blockchain_scripthash_get_history")] + #[instrument(skip_all, name = "electrum::server::blockchain_scripthash_get_history")] fn blockchain_scripthash_get_history(&self, params: &[Value]) -> Result { let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; let history_txids = get_history(&self.query, &script_hash[..], self.txs_limit)?; @@ -341,7 +341,7 @@ impl Connection { .collect::>())) } - #[instrument(skip_all, name="electrum::server::blockchain_scripthash_listunspent")] + #[instrument(skip_all, name = "electrum::server::blockchain_scripthash_listunspent")] fn blockchain_scripthash_listunspent(&self, params: &[Value]) -> Result { let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; let utxos = self.query.utxo(&script_hash[..])?; @@ -370,7 +370,7 @@ impl Connection { ))) } - #[instrument(skip_all, name="electrum::server::blockchain_transaction_broadcast")] + #[instrument(skip_all, name = "electrum::server::blockchain_transaction_broadcast")] fn blockchain_transaction_broadcast(&self, params: &[Value]) -> Result { let tx = params.get(0).chain_err(|| "missing tx")?; let tx = tx.as_str().chain_err(|| "non-string tx")?.to_string(); @@ -381,7 +381,7 @@ impl Connection { Ok(json!(txid)) } - #[instrument(skip_all, name="electrum::server::blockchain_transaction_get")] + #[instrument(skip_all, name = "electrum::server::blockchain_transaction_get")] fn blockchain_transaction_get(&self, params: &[Value]) -> Result { let tx_hash = Txid::from(hash_from_value(params.get(0)).chain_err(|| "bad tx_hash")?); let verbose = match params.get(1) { @@ -401,7 +401,7 @@ impl Connection { Ok(json!(rawtx.to_lower_hex_string())) } - #[instrument(skip_all, name="electrum::server::blockchain_transaction_get_merkle")] + #[instrument(skip_all, name = "electrum::server::blockchain_transaction_get_merkle")] 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")?; @@ -422,7 +422,10 @@ impl Connection { })) } - #[instrument(skip_all, name="electrum::server::blockchain_transaction_id_from_pos")] + #[instrument( + skip_all, + name = "electrum::server::blockchain_transaction_id_from_pos" + )] fn blockchain_transaction_id_from_pos(&self, params: &[Value]) -> Result { let height = usize_from_value(params.get(0), "height")?; let tx_pos = usize_from_value(params.get(1), "tx_pos")?; @@ -440,7 +443,7 @@ impl Connection { })) } - #[instrument(skip(self, params, id), name="electrum::server::handle_command")] + #[instrument(skip(self, params, id), name = "electrum::server::handle_command")] fn handle_command(&mut self, method: &str, params: &[Value], id: &Value) -> Result { let timer = self .stats @@ -496,7 +499,7 @@ impl Connection { }) } - #[instrument(skip_all, name="electrum::server::update_subscriptions")] + #[instrument(skip_all, name = "electrum::server::update_subscriptions")] fn update_subscriptions(&mut self) -> Result> { let timer = self .stats @@ -554,7 +557,7 @@ impl Connection { Ok(()) } - #[instrument(skip_all, name="electrum::server::handle_replies")] + #[instrument(skip_all, name = "electrum::server::handle_replies")] fn handle_replies(&mut self, receiver: Receiver) -> Result<()> { let empty_params = json!([]); loop { @@ -619,7 +622,7 @@ impl Connection { } } - #[instrument(skip_all, name="electrum::server::parse_requests")] + #[instrument(skip_all, name = "electrum::server::parse_requests")] fn parse_requests(mut reader: BufReader, tx: &SyncSender) -> Result<()> { loop { let mut line = Vec::::new(); @@ -682,7 +685,7 @@ impl Connection { } } -#[instrument(skip_all, name="electrum::server::get_history")] +#[instrument(skip_all, name = "electrum::server::get_history")] fn get_history( query: &Query, scripthash: &[u8], diff --git a/src/new_index/fetch.rs b/src/new_index/fetch.rs index ac3c6a8ab..fa85e8a55 100644 --- a/src/new_index/fetch.rs +++ b/src/new_index/fetch.rs @@ -70,7 +70,7 @@ impl Fetcher { } } -#[instrument(skip_all, name="fetch::bitcoind_fetcher")] +#[instrument(skip_all, name = "fetch::bitcoind_fetcher")] fn bitcoind_fetcher( daemon: &Daemon, new_headers: Vec, @@ -109,7 +109,7 @@ fn bitcoind_fetcher( )) } -#[instrument(skip_all, name="fetch::blkfiles_fetcher")] +#[instrument(skip_all, name = "fetch::blkfiles_fetcher")] fn blkfiles_fetcher( daemon: &Daemon, new_headers: Vec, @@ -156,7 +156,7 @@ fn blkfiles_fetcher( )) } -#[instrument(skip_all, name="fetch::blkfiles_reader")] +#[instrument(skip_all, name = "fetch::blkfiles_reader")] fn blkfiles_reader(blk_files: Vec) -> Fetcher> { let chan = SyncChannel::new(1); let sender = chan.sender(); @@ -176,7 +176,7 @@ fn blkfiles_reader(blk_files: Vec) -> Fetcher> { ) } -#[instrument(skip_all, name="fetch::blkfiles_parser")] +#[instrument(skip_all, name = "fetch::blkfiles_parser")] fn blkfiles_parser(blobs: Fetcher>, magic: u32) -> Fetcher> { let chan = SyncChannel::new(1); let sender = chan.sender(); @@ -195,7 +195,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 4ef87a0e8..96472f60b 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -11,7 +11,6 @@ use std::iter::FromIterator; use std::sync::{Arc, RwLock}; use std::time::{Duration, Instant}; -use tracing::instrument; use crate::chain::{deserialize, BlockHash, Network, OutPoint, Transaction, TxOut, Txid}; use crate::config::Config; use crate::daemon::Daemon; @@ -23,6 +22,7 @@ use crate::new_index::{ }; use crate::util::fees::{make_fee_histogram, TxFeeInfo}; use crate::util::{extract_tx_prevouts, full_hash, get_prev_outpoints, is_spendable, Bytes}; +use tracing::instrument; #[cfg(feature = "liquid")] use crate::elements::asset; @@ -108,7 +108,7 @@ impl Mempool { self.txstore.get(txid).map(serialize) } - #[instrument(skip_all, name="Mempool::lookup_spend")] + #[instrument(skip_all, name = "Mempool::lookup_spend")] 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, name="Mempool::has_unconfirmed_parents")] + #[instrument(skip_all, name = "Mempool::has_unconfirmed_parents")] 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, name="Mempool::history")] + #[instrument(skip_all, name = "Mempool::history")] 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, name="Mempool::_history")] + #[instrument(skip_all, name = "Mempool::_history")] fn _history(&self, entries: &[TxHistoryInfo], limit: usize) -> Vec { entries .iter() @@ -156,7 +156,7 @@ impl Mempool { .collect() } - #[instrument(skip_all, name="Mempool::history_txids")] + #[instrument(skip_all, name = "Mempool::history_txids")] pub fn history_txids(&self, scripthash: &[u8], limit: usize) -> Vec { let _timer = self .latency @@ -173,7 +173,7 @@ impl Mempool { } } - #[instrument(skip_all, name="Mempool::utxo")] + #[instrument(skip_all, name = "Mempool::utxo")] 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, name="Mempool::stats")] + #[instrument(skip_all, name = "Mempool::stats")] // @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, name="Mempool::txids")] + #[instrument(skip_all, name = "Mempool::txids")] // 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, name="Mempool::recent_txs_overview")] + #[instrument(skip_all, name = "Mempool::recent_txs_overview")] // 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, name="Mempool::backlog_stats")] + #[instrument(skip_all, name = "Mempool::backlog_stats")] pub fn backlog_stats(&self) -> &BacklogStats { &self.backlog_stats.0 } - #[instrument(skip_all, name="Mempool::txids_set")] + #[instrument(skip_all, name = "Mempool::txids_set")] pub fn txids_set(&self) -> HashSet { return HashSet::from_iter(self.txstore.keys().cloned()); } - #[instrument(skip_all, name="Mempool::update_backlog_stats")] + #[instrument(skip_all, name = "Mempool::update_backlog_stats")] 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, name="Mempool::add_by_txid")] + #[instrument(skip_all, name = "Mempool::add_by_txid")] 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, name="Mempool::add")] + #[instrument(skip_all, name = "Mempool::add")] fn add(&mut self, txs_map: HashMap) -> Result<()> { self.delta .with_label_values(&["add"]) @@ -429,14 +429,14 @@ impl Mempool { Ok(()) } - #[instrument(skip_all, name="Mempool::lookup_txo")] + #[instrument(skip_all, name = "Mempool::lookup_txo")] 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, name="Mempool::lookup_txos")] + #[instrument(skip_all, name = "Mempool::lookup_txos")] pub fn lookup_txos(&self, outpoints: BTreeSet) -> Result> { let _timer = self .latency @@ -444,12 +444,13 @@ impl Mempool { .start_timer(); // Get the txos available in the mempool, skipping over (and collecting) missing ones - let (mut txos, remain_outpoints): (HashMap<_, _>, _) = outpoints - .into_iter() - .partition_map(|outpoint| match self.lookup_txo(&outpoint) { - Some(txout) => Either::Left((outpoint, txout)), - None => Either::Right(outpoint), - }); + let (mut txos, remain_outpoints): (HashMap<_, _>, _) = + outpoints + .into_iter() + .partition_map(|outpoint| match self.lookup_txo(&outpoint) { + Some(txout) => Either::Left((outpoint, txout)), + None => Either::Right(outpoint), + }); // Get the remaining txos from the chain (fails if any are missing) txos.extend(self.chain.lookup_txos(remain_outpoints)?); @@ -457,7 +458,7 @@ impl Mempool { Ok(txos) } - #[instrument(skip_all, name="Mempool::remove")] + #[instrument(skip_all, name = "Mempool::remove")] fn remove(&mut self, to_remove: HashSet<&Txid>) { self.delta .with_label_values(&["remove"]) @@ -493,7 +494,7 @@ impl Mempool { } #[cfg(feature = "liquid")] - #[instrument(skip_all, name="Mempool::remove")] + #[instrument(skip_all, name = "Mempool::remove")] pub fn asset_history(&self, asset_id: &AssetId, limit: usize) -> Vec { let _timer = self .latency @@ -506,13 +507,18 @@ 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, name="Mempool::update")] + #[instrument(skip_all, name = "Mempool::update")] pub fn update( mempool: &Arc>, daemon: &Daemon, tip: &BlockHash, ) -> Result { - let _timer = mempool.read().unwrap().latency.with_label_values(&["update"]).start_timer(); + let _timer = mempool + .read() + .unwrap() + .latency + .with_label_values(&["update"]) + .start_timer(); // Continuously attempt to fetch mempool transactions until we're able to get them in full let mut fetched_txs = HashMap::::new(); @@ -609,7 +615,7 @@ impl BacklogStats { } } - #[instrument(skip_all, name="Mempool::new")] + #[instrument(skip_all, name = "Mempool::new")] 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 f94e91115..de78757d9 100644 --- a/src/new_index/precache.rs +++ b/src/new_index/precache.rs @@ -13,10 +13,9 @@ use std::io; use std::io::prelude::*; use std::str::FromStr; - use tracing::instrument; -#[instrument(skip_all, name="precache::precache")] +#[instrument(skip_all, name = "precache::precache")] pub fn precache(chain: &ChainQuery, scripthashes: Vec) { let total = scripthashes.len(); info!("Pre-caching stats and utxo set for {} scripthashes", total); @@ -40,7 +39,7 @@ pub fn precache(chain: &ChainQuery, scripthashes: Vec) { }); } -#[instrument(skip_all, name="precache::scripthashes_from_file")] +#[instrument(skip_all, name = "precache::scripthashes_from_file")] 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 9ffa43bff..30b0c3e2a 100644 --- a/src/new_index/query.rs +++ b/src/new_index/query.rs @@ -71,7 +71,7 @@ impl Query { self.mempool.read().unwrap() } - #[instrument(skip_all, name="query::Query::broadcast_raw")] + #[instrument(skip_all, name = "query::Query::broadcast_raw")] 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, name="query::Query::utxo")] + #[instrument(skip_all, name = "query::Query::utxo")] 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, name="query::Query::history_txids")] + #[instrument(skip_all, name = "query::Query::history_txids")] 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, name="query::Query::lookup_txn")] + #[instrument(skip_all, name = "query::Query::lookup_txn")] pub fn lookup_txn(&self, txid: &Txid) -> Option { self.chain .lookup_txn(txid, None) .or_else(|| self.mempool().lookup_txn(txid)) } - #[instrument(skip_all, name="query::Query::lookup_raw_txn")] + #[instrument(skip_all, name = "query::Query::lookup_raw_txn")] 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, name="query::Query::lookup_txos")] + #[instrument(skip_all, name = "query::Query::lookup_txos")] 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, name="query::Query::lookup_spend")] + #[instrument(skip_all, name = "query::Query::lookup_spend")] pub fn lookup_spend(&self, outpoint: &OutPoint) -> Option { self.chain .lookup_spend(outpoint) .or_else(|| self.mempool().lookup_spend(outpoint)) } - #[instrument(skip_all, name="query::Query::lookup_tx_spends")] + #[instrument(skip_all, name = "query::Query::lookup_tx_spends")] pub fn lookup_tx_spends(&self, tx: Transaction) -> Vec> { let txid = tx.txid(); @@ -162,22 +162,22 @@ impl Query { .collect() } - #[instrument(skip_all, name="query::Query::get_tx_status")] + #[instrument(skip_all, name = "query::Query::get_tx_status")] pub fn get_tx_status(&self, txid: &Txid) -> TransactionStatus { TransactionStatus::from(self.chain.tx_confirming_block(txid)) } - #[instrument(skip_all, name="query::Query::get_mempool_tx_fee")] + #[instrument(skip_all, name = "query::Query::get_mempool_tx_fee")] pub fn get_mempool_tx_fee(&self, txid: &Txid) -> Option { self.mempool().get_tx_fee(txid) } - #[instrument(skip_all, name="query::Query::has_unconfirmed_parents")] + #[instrument(skip_all, name = "query::Query::has_unconfirmed_parents")] pub fn has_unconfirmed_parents(&self, txid: &Txid) -> bool { self.mempool().has_unconfirmed_parents(txid) } - #[instrument(skip_all, name="query::Query::estimate_fee")] + #[instrument(skip_all, name = "query::Query::estimate_fee")] 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, name="query::Query::estimate_fee_map")] + #[instrument(skip_all, name = "query::Query::estimate_fee_map")] 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, name="query::Query::update_fee_estimates")] + #[instrument(skip_all, name = "query::Query::update_fee_estimates")] fn update_fee_estimates(&self) { match self.daemon.estimatesmartfee_batch(&CONF_TARGETS) { Ok(estimates) => { @@ -221,7 +221,7 @@ impl Query { } } - #[instrument(skip_all, name="query::Query::get_relayfee")] + #[instrument(skip_all, name = "query::Query::get_relayfee")] 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, name="query::Query::lookup_asset")] + #[instrument(skip_all, name = "query::Query::lookup_asset")] 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, name="query::Query::list_registry_assets")] + #[instrument(skip_all, name = "query::Query::list_registry_assets")] pub fn list_registry_assets( &self, start_index: usize, diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index 2afebdf0c..6f12fc8fc 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -222,7 +222,7 @@ impl Indexer { self.duration.with_label_values(&[name]).start_timer() } - #[instrument(skip_all, name="schema::Indexer::headers_to_add")] + #[instrument(skip_all, name = "schema::Indexer::headers_to_add")] fn headers_to_add(&self, new_headers: &[HeaderEntry]) -> Vec { let added_blockhashes = self.store.added_blockhashes.read().unwrap(); new_headers @@ -232,7 +232,7 @@ impl Indexer { .collect() } - #[instrument(skip_all, name="schema::Indexer::headers_to_index")] + #[instrument(skip_all, name = "schema::Indexer::headers_to_index")] fn headers_to_index(&self, new_headers: &[HeaderEntry]) -> Vec { let indexed_blockhashes = self.store.indexed_blockhashes.read().unwrap(); new_headers @@ -242,7 +242,7 @@ impl Indexer { .collect() } - #[instrument(skip_all, name="schema::start_auto_compactions")] + #[instrument(skip_all, name = "schema::start_auto_compactions")] fn start_auto_compactions(&self, db: &DB) { let key = b"F".to_vec(); if db.get(&key).is_none() { @@ -253,7 +253,7 @@ impl Indexer { db.enable_auto_compaction(); } - #[instrument(skip_all, name="schema::get_new_headers")] + #[instrument(skip_all, name = "schema::get_new_headers")] fn get_new_headers(&self, daemon: &Daemon, tip: &BlockHash) -> Result> { let headers = self.store.indexed_headers.read().unwrap(); let new_headers = daemon.get_new_headers(&headers, &tip)?; @@ -265,7 +265,7 @@ impl Indexer { Ok(result) } - #[instrument(skip_all, name="schema::update")] + #[instrument(skip_all, name = "schema::update")] pub fn update(&mut self, daemon: &Daemon) -> Result { let daemon = daemon.reconnect()?; let tip = daemon.getbestblockhash()?; @@ -313,7 +313,7 @@ impl Indexer { Ok(tip) } - #[instrument(skip_all, name="schema::add")] + #[instrument(skip_all, name = "schema::add")] fn add(&self, blocks: &[BlockEntry]) { // TODO: skip orphaned blocks? let rows = { @@ -332,7 +332,7 @@ impl Indexer { .extend(blocks.iter().map(|b| b.entry.hash())); } - #[instrument(skip_all, name="schema::index")] + #[instrument(skip_all, name = "schema::index")] fn index(&self, blocks: &[BlockEntry]) { let previous_txos_map = { let _timer = self.start_timer("index_lookup"); @@ -384,7 +384,7 @@ impl ChainQuery { self.duration.with_label_values(&[name]).start_timer() } - #[instrument(skip_all, name="sdchema::Indexer::get_block_txids")] + #[instrument(skip_all, name = "sdchema::Indexer::get_block_txids")] pub fn get_block_txids(&self, hash: &BlockHash) -> Option> { let _timer = self.start_timer("get_block_txids"); if self.light_mode { @@ -399,7 +399,7 @@ impl ChainQuery { } } - #[instrument(skip_all, name="schema::ChainQuery::get_block_meta")] + #[instrument(skip_all, name = "schema::ChainQuery::get_block_meta")] pub fn get_block_meta(&self, hash: &BlockHash) -> Option { let _timer = self.start_timer("get_block_meta"); @@ -414,7 +414,7 @@ impl ChainQuery { } } - #[instrument(skip_all, name="schema::ChainQuery::get_block_raw")] + #[instrument(skip_all, name = "schema::ChainQuery::get_block_raw")] pub fn get_block_raw(&self, hash: &BlockHash) -> Option> { let _timer = self.start_timer("get_block_raw"); @@ -443,19 +443,19 @@ impl ChainQuery { } } - #[instrument(skip_all, name="schema::ChainQuery::get_block_header")] + #[instrument(skip_all, name = "schema::ChainQuery::get_block_header")] pub fn get_block_header(&self, hash: &BlockHash) -> Option { let _timer = self.start_timer("get_block_header"); Some(self.header_by_hash(hash)?.header().clone()) } - #[instrument(skip_all, name="schema::ChainQuery::get_mtp")] + #[instrument(skip_all, name = "schema::ChainQuery::get_mtp")] pub fn get_mtp(&self, height: usize) -> u32 { let _timer = self.start_timer("get_block_mtp"); self.store.indexed_headers.read().unwrap().get_mtp(height) } - #[instrument(skip_all, name="schema::ChainQuery::get_block_with_meta")] + #[instrument(skip_all, name = "schema::ChainQuery::get_block_with_meta")] pub fn get_block_with_meta(&self, hash: &BlockHash) -> Option { let _timer = self.start_timer("get_block_with_meta"); let header_entry = self.header_by_hash(hash)?; @@ -466,7 +466,7 @@ impl ChainQuery { }) } - #[instrument(skip_all, name="schema::ChainQuery::history_iter_scan")] + #[instrument(skip_all, name = "schema::ChainQuery::history_iter_scan")] pub fn history_iter_scan(&self, code: u8, hash: &[u8], start_height: usize) -> ScanIterator { self.store.history_db.iter_scan_from( &TxHistoryRow::filter(code, &hash[..]), @@ -474,7 +474,7 @@ impl ChainQuery { ) } - #[instrument(skip_all, name="schema::ChainQuery::history_iter_scan_reverse")] + #[instrument(skip_all, name = "schema::ChainQuery::history_iter_scan_reverse")] fn history_iter_scan_reverse(&self, code: u8, hash: &[u8]) -> ReverseScanIterator { self.store.history_db.iter_scan_reverse( &TxHistoryRow::filter(code, &hash[..]), @@ -482,7 +482,7 @@ impl ChainQuery { ) } - #[instrument(skip_all, name="schema::ChainQuery::history")] + #[instrument(skip_all, name = "schema::ChainQuery::history")] pub fn history( &self, scripthash: &[u8], @@ -493,7 +493,7 @@ impl ChainQuery { self._history(b'H', scripthash, last_seen_txid, limit) } - #[instrument(skip_all, name="schema::ChainQuery::_history")] + #[instrument(skip_all, name = "schema::ChainQuery::_history")] fn _history( &self, code: u8, @@ -528,13 +528,13 @@ impl ChainQuery { .collect() } - #[instrument(skip_all, name="schema::ChainQuery::history_txids")] + #[instrument(skip_all, name = "schema::ChainQuery::history_txids")] pub fn history_txids(&self, scripthash: &[u8], limit: usize) -> Vec<(Txid, BlockId)> { // scripthash lookup self._history_txids(b'H', scripthash, limit) } - #[instrument(skip_all, name="schema::ChainQuery::_history_txids")] + #[instrument(skip_all, name = "schema::ChainQuery::_history_txids")] fn _history_txids(&self, code: u8, hash: &[u8], limit: usize) -> Vec<(Txid, BlockId)> { let _timer = self.start_timer("history_txids"); self.history_iter_scan(code, hash, 0) @@ -546,7 +546,7 @@ impl ChainQuery { } // TODO: avoid duplication with stats/stats_delta? - #[instrument(skip_all, name="schema::ChainQuery::utxo")] + #[instrument(skip_all, name = "schema::ChainQuery::utxo")] pub fn utxo(&self, scripthash: &[u8], limit: usize) -> Result> { let _timer = self.start_timer("utxo"); @@ -607,7 +607,7 @@ impl ChainQuery { .collect()) } - #[instrument(skip_all, name="schema::ChainQuery::utxo_delta")] + #[instrument(skip_all, name = "schema::ChainQuery::utxo_delta")] fn utxo_delta( &self, scripthash: &[u8], @@ -653,7 +653,7 @@ impl ChainQuery { Ok((utxos, lastblock, processed_items)) } - #[instrument(skip_all, name="schema::ChainQuery::stats")] + #[instrument(skip_all, name = "schema::ChainQuery::stats")] pub fn stats(&self, scripthash: &[u8]) -> ScriptStats { let _timer = self.start_timer("stats"); @@ -688,7 +688,7 @@ impl ChainQuery { newstats } - #[instrument(skip_all, name="schema::ChainQuery::stats_delta")] + #[instrument(skip_all, name = "schema::ChainQuery::stats_delta")] fn stats_delta( &self, scripthash: &[u8], @@ -756,7 +756,7 @@ impl ChainQuery { (stats, lastblock) } - #[instrument(skip_all, name="schema::ChainQuery::address_search")] + #[instrument(skip_all, name = "schema::ChainQuery::address_search")] pub fn address_search(&self, prefix: &str, limit: usize) -> Vec { let _timer_scan = self.start_timer("address_search"); self.store @@ -767,7 +767,7 @@ impl ChainQuery { .collect() } - #[instrument(skip_all, name="schema::ChainQuery::header_by_hash")] + #[instrument(skip_all, name = "schema::ChainQuery::header_by_hash")] fn header_by_hash(&self, hash: &BlockHash) -> Option { self.store .indexed_headers @@ -777,7 +777,7 @@ impl ChainQuery { .cloned() } - #[instrument(skip_all, name="schema::ChainQuery::height_by_hash")] + #[instrument(skip_all, name = "schema::ChainQuery::height_by_hash")] // Get the height of a blockhash, only if its part of the best chain pub fn height_by_hash(&self, hash: &BlockHash) -> Option { self.store @@ -788,7 +788,7 @@ impl ChainQuery { .map(|header| header.height()) } - #[instrument(skip_all, name="schema::ChainQuery::header_by_height")] + #[instrument(skip_all, name = "schema::ChainQuery::header_by_height")] pub fn header_by_height(&self, height: usize) -> Option { self.store .indexed_headers @@ -798,7 +798,7 @@ impl ChainQuery { .cloned() } - #[instrument(skip_all, name="schema::ChainQuery::hash_by_height")] + #[instrument(skip_all, name = "schema::ChainQuery::hash_by_height")] pub fn hash_by_height(&self, height: usize) -> Option { self.store .indexed_headers @@ -808,7 +808,7 @@ impl ChainQuery { .map(|entry| *entry.hash()) } - #[instrument(skip_all, name="schema::ChainQuery::blockid_by_height")] + #[instrument(skip_all, name = "schema::ChainQuery::blockid_by_height")] pub fn blockid_by_height(&self, height: usize) -> Option { self.store .indexed_headers @@ -818,7 +818,7 @@ impl ChainQuery { .map(BlockId::from) } - #[instrument(skip_all, name="schema::ChainQuery::blockid_by_hash")] + #[instrument(skip_all, name = "schema::ChainQuery::blockid_by_hash")] // returns None for orphaned blocks pub fn blockid_by_hash(&self, hash: &BlockHash) -> Option { self.store @@ -829,17 +829,17 @@ impl ChainQuery { .map(BlockId::from) } - #[instrument(skip_all, name="schema::ChainQuery::bests_height")] + #[instrument(skip_all, name = "schema::ChainQuery::bests_height")] pub fn best_height(&self) -> usize { self.store.indexed_headers.read().unwrap().len() - 1 } - #[instrument(skip_all, name="schema::ChainQuery::best_hash")] + #[instrument(skip_all, name = "schema::ChainQuery::best_hash")] pub fn best_hash(&self) -> BlockHash { *self.store.indexed_headers.read().unwrap().tip() } - #[instrument(skip_all, name="schema::ChainQuery::best_header")] + #[instrument(skip_all, name = "schema::ChainQuery::best_header")] pub fn best_header(&self) -> HeaderEntry { let headers = self.store.indexed_headers.read().unwrap(); headers @@ -850,7 +850,7 @@ impl ChainQuery { // TODO: can we pass txids as a "generic iterable"? // TODO: should also use a custom ThreadPoolBuilder? - #[instrument(skip_all, name="schema::ChainQuery::lookup_txns")] + #[instrument(skip_all, name = "schema::ChainQuery::lookup_txns")] pub fn lookup_txns(&self, txids: &[(Txid, BlockId)]) -> Result> { let _timer = self.start_timer("lookup_txns"); txids @@ -862,7 +862,7 @@ impl ChainQuery { .collect::>>() } - #[instrument(skip_all, name="schema::ChainQuery::lookup_txn")] + #[instrument(skip_all, name = "schema::ChainQuery::lookup_txn")] pub fn lookup_txn(&self, txid: &Txid, blockhash: Option<&BlockHash>) -> Option { let _timer = self.start_timer("lookup_txn"); self.lookup_raw_txn(txid, blockhash).map(|rawtx| { @@ -872,7 +872,7 @@ impl ChainQuery { }) } - #[instrument(skip_all, name="schema::ChainQuery::lookup_raw_txn")] + #[instrument(skip_all, name = "schema::ChainQuery::lookup_raw_txn")] pub fn lookup_raw_txn(&self, txid: &Txid, blockhash: Option<&BlockHash>) -> Option { let _timer = self.start_timer("lookup_raw_txn"); @@ -892,19 +892,19 @@ impl ChainQuery { } } - #[instrument(skip_all, name="schema::ChainQuery::lookup_txo")] + #[instrument(skip_all, name = "schema::ChainQuery::lookup_txo")] pub fn lookup_txo(&self, outpoint: &OutPoint) -> Option { let _timer = self.start_timer("lookup_txo"); lookup_txo(&self.store.txstore_db, outpoint) } - #[instrument(skip_all, name="schema::ChainQuery::lookup_txos")] + #[instrument(skip_all, name = "schema::ChainQuery::lookup_txos")] pub fn lookup_txos(&self, outpoints: BTreeSet) -> Result> { let _timer = self.start_timer("lookup_txos"); lookup_txos(&self.store.txstore_db, outpoints) } - #[instrument(skip_all, name="schema::ChainQuery::lookup_spend")] + #[instrument(skip_all, name = "schema::ChainQuery::lookup_spend")] pub fn lookup_spend(&self, outpoint: &OutPoint) -> Option { let _timer = self.start_timer("lookup_spend"); self.store @@ -921,7 +921,7 @@ impl ChainQuery { }) } - #[instrument(skip_all, name="schema::ChainQuery::tx_confirming_blocks")] + #[instrument(skip_all, name = "schema::ChainQuery::tx_confirming_blocks")] pub fn tx_confirming_block(&self, txid: &Txid) -> Option { let _timer = self.start_timer("tx_confirming_block"); let headers = self.store.indexed_headers.read().unwrap(); @@ -938,7 +938,7 @@ impl ChainQuery { .map(BlockId::from) } - #[instrument(skip_all, name="schema::ChainQuery::get_block_status")] + #[instrument(skip_all, name = "schema::ChainQuery::get_block_status")] pub fn get_block_status(&self, hash: &BlockHash) -> BlockStatus { // TODO differentiate orphaned and non-existing blocks? telling them apart requires // an additional db read. @@ -960,7 +960,7 @@ impl ChainQuery { } #[cfg(not(feature = "liquid"))] - #[instrument(skip_all, name="schema::ChainQuery::get_merkleblock_proof")] + #[instrument(skip_all, name = "schema::ChainQuery::get_merkleblock_proof")] pub fn get_merkleblock_proof(&self, txid: &Txid) -> Option { let _timer = self.start_timer("get_merkleblock_proof"); let blockid = self.tx_confirming_block(txid)?; @@ -975,7 +975,7 @@ impl ChainQuery { } #[cfg(feature = "liquid")] - #[instrument(skip_all, name="schema::ChainQuery::asset_history")] + #[instrument(skip_all, name = "schema::ChainQuery::asset_history")] pub fn asset_history( &self, asset_id: &AssetId, @@ -986,13 +986,13 @@ impl ChainQuery { } #[cfg(feature = "liquid")] - #[instrument(skip_all, name="schema::ChainQuery::assets_history_txids")] + #[instrument(skip_all, name = "schema::ChainQuery::assets_history_txids")] pub fn asset_history_txids(&self, asset_id: &AssetId, limit: usize) -> Vec<(Txid, BlockId)> { self._history_txids(b'I', &asset_id.into_inner()[..], limit) } } -#[instrument(skip_all, name="schema::ChainQuery::load_blockhashes")] +#[instrument(skip_all, name = "schema::ChainQuery::load_blockhashes")] fn load_blockhashes(db: &DB, prefix: &[u8]) -> HashSet { db.iter_scan(prefix) .map(BlockRow::from_row) @@ -1000,7 +1000,7 @@ fn load_blockhashes(db: &DB, prefix: &[u8]) -> HashSet { .collect() } -#[instrument(skip_all, name="schema::ChainQuery::load_blockheaders")] +#[instrument(skip_all, name = "schema::ChainQuery::load_blockheaders")] fn load_blockheaders(db: &DB) -> HashMap { db.iter_scan(&BlockRow::header_filter()) .map(BlockRow::from_row) @@ -1012,7 +1012,7 @@ fn load_blockheaders(db: &DB) -> HashMap { .collect() } -#[instrument(skip_all, name="schema::add_blocks")] +#[instrument(skip_all, name = "schema::add_blocks")] fn add_blocks(block_entries: &[BlockEntry], iconfig: &IndexerConfig) -> Vec { // persist individual transactions: // T{txid} → {rawtx} @@ -1066,7 +1066,7 @@ fn add_transaction( } } -#[instrument(skip_all, name="schema::get_previous_txos")] +#[instrument(skip_all, name = "schema::get_previous_txos")] fn get_previous_txos(block_entries: &[BlockEntry]) -> BTreeSet { block_entries .iter() @@ -1102,7 +1102,7 @@ fn lookup_txo(txstore_db: &DB, outpoint: &OutPoint) -> Option { .map(|val| deserialize(&val).expect("failed to parse TxOut")) } -#[instrument(skip_all, name="schema::index_blocks")] +#[instrument(skip_all, name = "schema::index_blocks")] fn index_blocks( block_entries: &[BlockEntry], previous_txos_map: &HashMap, @@ -1124,7 +1124,7 @@ fn index_blocks( } // TODO: return an iterator? -#[instrument(skip_all, name="schema::index_transaction")] +#[instrument(skip_all, name = "schema::index_transaction")] fn index_transaction( tx: &Transaction, confirmed_height: u32, @@ -1199,7 +1199,7 @@ fn index_transaction( ); } -#[instrument(skip_all, name="schema::addr_search_row")] +#[instrument(skip_all, name = "schema::addr_search_row")] fn addr_search_row(spk: &Script, network: Network) -> Option { spk.to_address_str(network).map(|address| DBRow { key: [b"a", address.as_bytes()].concat(), @@ -1654,7 +1654,7 @@ impl UtxoCacheRow { } } -#[instrument(skip_all, name="schema::make_utxo_cache")] +#[instrument(skip_all, name = "schema::make_utxo_cache")] // keep utxo cache with just the block height (the hash/timestamp are read later from the headers to reconstruct BlockId) // and use a (txid,vout) tuple instead of OutPoints (they don't play nicely with bincode serialization) fn make_utxo_cache(utxos: &UtxoMap) -> CachedUtxoMap { @@ -1669,7 +1669,7 @@ fn make_utxo_cache(utxos: &UtxoMap) -> CachedUtxoMap { .collect() } -#[instrument(skip_all, name="schema::from_utxo_cache")] +#[instrument(skip_all, name = "schema::from_utxo_cache")] fn from_utxo_cache(utxos_cache: CachedUtxoMap, chain: &ChainQuery) -> UtxoMap { utxos_cache .into_iter() diff --git a/src/otlp_trace.rs b/src/otlp_trace.rs index dcc23a553..834d56737 100644 --- a/src/otlp_trace.rs +++ b/src/otlp_trace.rs @@ -14,7 +14,7 @@ use opentelemetry_semantic_conventions::{ use std::env::var; use std::time::Duration; use tracing_opentelemetry::OpenTelemetryLayer; -use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; fn init_tracer(resource: Resource, endpoint: &str) -> Tracer { let export_config = ExportConfig { @@ -55,12 +55,12 @@ fn init_tracing_subscriber(service_name: &str) -> OtelGuard { let env_filter = EnvFilter::from_default_env(); - let reg = tracing_subscriber::registry() - .with(env_filter) - .with(tracing_subscriber::fmt::layer() + let reg = tracing_subscriber::registry().with(env_filter).with( + tracing_subscriber::fmt::layer() .with_thread_ids(true) .with_ansi(false) - .compact()); + .compact(), + ); let _ = if let Ok(endpoint) = var("OTLP_ENDPOINT") { reg.with(OpenTelemetryLayer::new(init_tracer(resource, &endpoint))) .try_init() diff --git a/src/rest.rs b/src/rest.rs index 7567bff81..928d90f74 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -24,7 +24,6 @@ use tokio::sync::oneshot; use std::fs; use std::str::FromStr; - use tracing::instrument; #[cfg(feature = "liquid")] @@ -582,7 +581,7 @@ impl Handle { } } -#[instrument(skip_all, name="rest::handle_request")] +#[instrument(skip_all, name = "rest::handle_request")] fn handle_request( method: Method, uri: hyper::Uri, @@ -1158,7 +1157,7 @@ fn json_response(value: T, ttl: u32) -> Result, Htt .unwrap()) } -#[instrument(skip_all, name="rest::blocks")] +#[instrument(skip_all, name = "rest::blocks")] 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 19e54dd87..9ea61daa8 100644 --- a/src/util/block.rs +++ b/src/util/block.rs @@ -94,7 +94,7 @@ impl HeaderList { } } - #[instrument(skip_all, name="block::new")] + #[instrument(skip_all, name = "block::new")] pub fn new( mut headers_map: HashMap, tip_hash: BlockHash, @@ -132,7 +132,7 @@ impl HeaderList { headers } - #[instrument(skip_all, name="block::HeaderList::order")] + #[instrument(skip_all, name = "block::HeaderList::order")] 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, name="block::HeaderList::apply")] + #[instrument(skip_all, name = "block::HeaderList::apply")] 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, name="block::HeaderList::header_by_blockhash")] + #[instrument(skip_all, name = "block::HeaderList::header_by_blockhash")] 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, name="block::HeaderList::header_by_height")] + #[instrument(skip_all, name = "block::HeaderList::header_by_height")] 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 f26c5578e..ef4a0e936 100644 --- a/src/util/electrum_merkle.rs +++ b/src/util/electrum_merkle.rs @@ -3,10 +3,9 @@ use crate::errors::*; use crate::new_index::ChainQuery; use bitcoin::hashes::{sha256d::Hash as Sha256dHash, Hash}; - use tracing::instrument; -#[instrument(skip_all, name="electrum_merkle::get_tx_merkleproof")] +#[instrument(skip_all, name = "electrum_merkle::get_tx_merkleproof")] pub fn get_tx_merkle_proof( chain: &ChainQuery, tx_hash: &Txid, @@ -25,7 +24,7 @@ pub fn get_tx_merkle_proof( Ok((branch, pos)) } -#[instrument(skip_all, name="electrum_merkle::get_header_merkle_proof")] +#[instrument(skip_all, name = "electrum_merkle::get_header_merkle_proof")] pub fn get_header_merkle_proof( chain: &ChainQuery, height: usize, @@ -54,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, name="electrum_merkle::get_id_from_pos")] +#[instrument(skip_all, name = "electrum_merkle::get_id_from_pos")] pub fn get_id_from_pos( chain: &ChainQuery, height: usize, diff --git a/src/util/fees.rs b/src/util/fees.rs index 213dc7194..5827dd751 100644 --- a/src/util/fees.rs +++ b/src/util/fees.rs @@ -48,7 +48,7 @@ pub fn get_tx_fee(tx: &Transaction, _prevouts: &HashMap, network: N tx.fee_in(*network.native_asset()) } -#[instrument(skip_all, name="fees::make_fee_histogram")] +#[instrument(skip_all, name = "fees::make_fee_histogram")] 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());