@@ -20,7 +20,7 @@ use bitcoin::consensus::encode::{deserialize, serialize_hex};
20
20
#[ cfg( feature = "liquid" ) ]
21
21
use elements:: encode:: { deserialize, serialize_hex} ;
22
22
23
- use tracing :: instrument ;
23
+ use instrumented_macro :: instrumented ;
24
24
25
25
use crate :: chain:: { Block , BlockHash , BlockHeader , Network , Transaction , Txid } ;
26
26
use crate :: metrics:: { HistogramOpts , HistogramVec , Metrics } ;
@@ -44,7 +44,7 @@ lazy_static! {
44
44
const MAX_ATTEMPTS : u32 = 5 ;
45
45
const RETRY_WAIT_DURATION : Duration = Duration :: from_secs ( 1 ) ;
46
46
47
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
47
+ #[ instrumented ]
48
48
fn parse_hash < T > ( value : & Value ) -> Result < T >
49
49
where
50
50
T : FromStr ,
58
58
. chain_err ( || format ! ( "non-hex value: {}" , value) ) ?)
59
59
}
60
60
61
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
61
+ #[ instrumented ]
62
62
fn header_from_value ( value : Value ) -> Result < BlockHeader > {
63
63
let header_hex = value
64
64
. as_str ( )
@@ -153,7 +153,7 @@ struct Connection {
153
153
signal : Waiter ,
154
154
}
155
155
156
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
156
+ #[ instrumented ]
157
157
fn tcp_connect ( addr : SocketAddr , signal : & Waiter ) -> Result < TcpStream > {
158
158
loop {
159
159
match TcpStream :: connect_timeout ( & addr, * DAEMON_CONNECTION_TIMEOUT ) {
@@ -176,7 +176,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
176
176
}
177
177
178
178
impl Connection {
179
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
179
+ #[ instrumented ]
180
180
fn new (
181
181
addr : SocketAddr ,
182
182
cookie_getter : Arc < dyn CookieGetter > ,
@@ -196,12 +196,12 @@ impl Connection {
196
196
} )
197
197
}
198
198
199
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
199
+ #[ instrumented ]
200
200
fn reconnect ( & self ) -> Result < Connection > {
201
201
Connection :: new ( self . addr , self . cookie_getter . clone ( ) , self . signal . clone ( ) )
202
202
}
203
203
204
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
204
+ #[ instrumented ]
205
205
fn send ( & mut self , request : & str ) -> Result < ( ) > {
206
206
let cookie = & self . cookie_getter . get ( ) ?;
207
207
let msg = format ! (
@@ -215,7 +215,7 @@ impl Connection {
215
215
} )
216
216
}
217
217
218
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
218
+ #[ instrumented ]
219
219
fn recv ( & mut self ) -> Result < String > {
220
220
// TODO: use proper HTTP parser.
221
221
let mut in_header = true ;
@@ -381,7 +381,7 @@ impl Daemon {
381
381
Ok ( daemon)
382
382
}
383
383
384
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
384
+ #[ instrumented ]
385
385
pub fn reconnect ( & self ) -> Result < Daemon > {
386
386
Ok ( Daemon {
387
387
daemon_dir : self . daemon_dir . clone ( ) ,
@@ -396,7 +396,7 @@ impl Daemon {
396
396
} )
397
397
}
398
398
399
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
399
+ #[ instrumented ]
400
400
pub fn list_blk_files ( & self ) -> Result < Vec < PathBuf > > {
401
401
let path = self . blocks_dir . join ( "blk*.dat" ) ;
402
402
debug ! ( "listing block files at {:?}" , path) ;
@@ -432,7 +432,7 @@ impl Daemon {
432
432
self . network . magic ( )
433
433
}
434
434
435
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
435
+ #[ instrumented ]
436
436
fn call_jsonrpc ( & self , method : & str , request : & Value ) -> Result < Value > {
437
437
let mut conn = self . conn . lock ( ) . unwrap ( ) ;
438
438
let timer = self . latency . with_label_values ( & [ method] ) . start_timer ( ) ;
@@ -450,7 +450,7 @@ impl Daemon {
450
450
Ok ( result)
451
451
}
452
452
453
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) , method = %method) ) ]
453
+ #[ instrumented ( method = %method) ]
454
454
fn handle_request ( & self , method : & str , params : & Value ) -> Result < Value > {
455
455
let id = self . message_id . next ( ) ;
456
456
let req = json ! ( { "method" : method, "params" : params, "id" : id} ) ;
@@ -473,12 +473,12 @@ impl Daemon {
473
473
}
474
474
}
475
475
476
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
476
+ #[ instrumented ]
477
477
fn request ( & self , method : & str , params : Value ) -> Result < Value > {
478
478
self . retry_request ( method, & params)
479
479
}
480
480
481
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
481
+ #[ instrumented ]
482
482
fn retry_reconnect ( & self ) -> Daemon {
483
483
// XXX add a max reconnection attempts limit?
484
484
loop {
@@ -493,14 +493,14 @@ impl Daemon {
493
493
494
494
// Send requests in parallel over multiple RPC connections as individual JSON-RPC requests (with no JSON-RPC batching),
495
495
// buffering the replies into a vector. If any of the requests fail, processing is terminated and an Err is returned.
496
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
496
+ #[ instrumented ]
497
497
fn requests ( & self , method : & str , params_list : Vec < Value > ) -> Result < Vec < Value > > {
498
498
self . requests_iter ( method, params_list) . collect ( )
499
499
}
500
500
501
501
// Send requests in parallel over multiple RPC connections, iterating over the results without buffering them.
502
502
// Errors are included in the iterator and do not terminate other pending requests.
503
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
503
+ #[ instrumented ]
504
504
fn requests_iter < ' a > (
505
505
& ' a self ,
506
506
method : & ' a str ,
@@ -523,29 +523,29 @@ impl Daemon {
523
523
524
524
// bitcoind JSONRPC API:
525
525
526
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
526
+ #[ instrumented ]
527
527
pub fn getblockchaininfo ( & self ) -> Result < BlockchainInfo > {
528
528
let info: Value = self . request ( "getblockchaininfo" , json ! ( [ ] ) ) ?;
529
529
Ok ( from_value ( info) . chain_err ( || "invalid blockchain info" ) ?)
530
530
}
531
531
532
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
532
+ #[ instrumented ]
533
533
fn getnetworkinfo ( & self ) -> Result < NetworkInfo > {
534
534
let info: Value = self . request ( "getnetworkinfo" , json ! ( [ ] ) ) ?;
535
535
Ok ( from_value ( info) . chain_err ( || "invalid network info" ) ?)
536
536
}
537
537
538
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
538
+ #[ instrumented ]
539
539
pub fn getbestblockhash ( & self ) -> Result < BlockHash > {
540
540
parse_hash ( & self . request ( "getbestblockhash" , json ! ( [ ] ) ) ?)
541
541
}
542
542
543
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
543
+ #[ instrumented ]
544
544
pub fn getblockheader ( & self , blockhash : & BlockHash ) -> Result < BlockHeader > {
545
545
header_from_value ( self . request ( "getblockheader" , json ! ( [ blockhash, /*verbose=*/ false ] ) ) ?)
546
546
}
547
547
548
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
548
+ #[ instrumented ]
549
549
pub fn getblockheaders ( & self , heights : & [ usize ] ) -> Result < Vec < BlockHeader > > {
550
550
let heights: Vec < Value > = heights. iter ( ) . map ( |height| json ! ( [ height] ) ) . collect ( ) ;
551
551
let params_list: Vec < Value > = self
@@ -560,20 +560,20 @@ impl Daemon {
560
560
Ok ( result)
561
561
}
562
562
563
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
563
+ #[ instrumented ]
564
564
pub fn getblock ( & self , blockhash : & BlockHash ) -> Result < Block > {
565
565
let block =
566
566
block_from_value ( self . request ( "getblock" , json ! ( [ blockhash, /*verbose=*/ false ] ) ) ?) ?;
567
567
assert_eq ! ( block. block_hash( ) , * blockhash) ;
568
568
Ok ( block)
569
569
}
570
570
571
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
571
+ #[ instrumented ]
572
572
pub fn getblock_raw ( & self , blockhash : & BlockHash , verbose : u32 ) -> Result < Value > {
573
573
self . request ( "getblock" , json ! ( [ blockhash, verbose] ) )
574
574
}
575
575
576
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
576
+ #[ instrumented ]
577
577
pub fn getblocks ( & self , blockhashes : & [ BlockHash ] ) -> Result < Vec < Block > > {
578
578
let params_list: Vec < Value > = blockhashes
579
579
. iter ( )
@@ -610,7 +610,7 @@ impl Daemon {
610
610
611
611
/// Fetch the given transactions in parallel over multiple threads and RPC connections,
612
612
/// ignoring any missing ones and returning whatever is available.
613
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
613
+ #[ instrumented ]
614
614
pub fn gettransactions_available ( & self , txids : & [ & Txid ] ) -> Result < Vec < ( Txid , Transaction ) > > {
615
615
const RPC_INVALID_ADDRESS_OR_KEY : i64 = -5 ;
616
616
@@ -635,7 +635,7 @@ impl Daemon {
635
635
. collect ( )
636
636
}
637
637
638
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
638
+ #[ instrumented ]
639
639
pub fn gettransaction_raw (
640
640
& self ,
641
641
txid : & Txid ,
@@ -645,24 +645,24 @@ impl Daemon {
645
645
self . request ( "getrawtransaction" , json ! ( [ txid, verbose, blockhash] ) )
646
646
}
647
647
648
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
648
+ #[ instrumented ]
649
649
pub fn getmempooltx ( & self , txhash : & Txid ) -> Result < Transaction > {
650
650
let value = self . request ( "getrawtransaction" , json ! ( [ txhash, /*verbose=*/ false ] ) ) ?;
651
651
tx_from_value ( value)
652
652
}
653
653
654
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
654
+ #[ instrumented ]
655
655
pub fn getmempooltxids ( & self ) -> Result < HashSet < Txid > > {
656
656
let res = self . request ( "getrawmempool" , json ! ( [ /*verbose=*/ false ] ) ) ?;
657
657
Ok ( serde_json:: from_value ( res) . chain_err ( || "invalid getrawmempool reply" ) ?)
658
658
}
659
659
660
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
660
+ #[ instrumented ]
661
661
pub fn broadcast ( & self , tx : & Transaction ) -> Result < Txid > {
662
662
self . broadcast_raw ( & serialize_hex ( tx) )
663
663
}
664
664
665
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
665
+ #[ instrumented ]
666
666
pub fn broadcast_raw ( & self , txhex : & str ) -> Result < Txid > {
667
667
let txid = self . request ( "sendrawtransaction" , json ! ( [ txhex] ) ) ?;
668
668
Ok (
@@ -674,7 +674,7 @@ impl Daemon {
674
674
// Get estimated feerates for the provided confirmation targets using a batch RPC request
675
675
// Missing estimates are logged but do not cause a failure, whatever is available is returned
676
676
#[ allow( clippy:: float_cmp) ]
677
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
677
+ #[ instrumented ]
678
678
pub fn estimatesmartfee_batch ( & self , conf_targets : & [ u16 ] ) -> Result < HashMap < u16 , f64 > > {
679
679
let params_list: Vec < Value > = conf_targets
680
680
. iter ( )
@@ -709,7 +709,7 @@ impl Daemon {
709
709
. collect ( ) )
710
710
}
711
711
712
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
712
+ #[ instrumented ]
713
713
fn get_all_headers ( & self , tip : & BlockHash ) -> Result < Vec < BlockHeader > > {
714
714
let info: Value = self . request ( "getblockheader" , json ! ( [ tip] ) ) ?;
715
715
let tip_height = info
@@ -737,7 +737,7 @@ impl Daemon {
737
737
}
738
738
739
739
// Returns a list of BlockHeaders in ascending height (i.e. the tip is last).
740
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
740
+ #[ instrumented ]
741
741
pub fn get_new_headers (
742
742
& self ,
743
743
indexed_headers : & HeaderList ,
@@ -770,7 +770,7 @@ impl Daemon {
770
770
Ok ( new_headers)
771
771
}
772
772
773
- #[ instrument ( skip_all , fields ( module = module_path! ( ) , file = file! ( ) , line = line! ( ) ) ) ]
773
+ #[ instrumented ]
774
774
pub fn get_relayfee ( & self ) -> Result < f64 > {
775
775
let relayfee = self . getnetworkinfo ( ) ?. relayfee ;
776
776
0 commit comments