@@ -7,6 +7,7 @@ use pallas_network::{
7
7
miniprotocols:: chainsync:: { BlockContent , NextResponse } ,
8
8
} ;
9
9
use pallas_traverse:: MultiEraBlock ;
10
+ use slog:: { debug, Logger } ;
10
11
11
12
use crate :: { cardano_block_scanner:: ScannedBlock , entities:: ChainPoint , CardanoNetwork , StdResult } ;
12
13
@@ -17,15 +18,17 @@ pub struct PallasChainReader {
17
18
socket : PathBuf ,
18
19
network : CardanoNetwork ,
19
20
client : Option < NodeClient > ,
21
+ logger : Logger ,
20
22
}
21
23
22
24
impl PallasChainReader {
23
25
/// Creates a new `PallasChainReader` with the specified socket and network.
24
- pub fn new ( socket : & Path , network : CardanoNetwork ) -> Self {
26
+ pub fn new ( socket : & Path , network : CardanoNetwork , logger : Logger ) -> Self {
25
27
Self {
26
28
socket : socket. to_owned ( ) ,
27
29
network,
28
30
client : None ,
31
+ logger,
29
32
}
30
33
}
31
34
@@ -42,6 +45,7 @@ impl PallasChainReader {
42
45
async fn get_client ( & mut self ) -> StdResult < & mut NodeClient > {
43
46
if self . client . is_none ( ) {
44
47
self . client = Some ( self . new_client ( ) . await ?) ;
48
+ debug ! ( self . logger, "PallasChainReader connected to a new client" ) ;
45
49
}
46
50
47
51
self . client
@@ -51,13 +55,17 @@ impl PallasChainReader {
51
55
52
56
/// Intersects the point of the chain with the given point.
53
57
async fn find_intersect_point ( & mut self , point : & ChainPoint ) -> StdResult < ( ) > {
58
+ let logger = self . logger . clone ( ) ;
54
59
let client = self . get_client ( ) . await ?;
55
60
let chainsync = client. chainsync ( ) ;
56
61
57
62
if chainsync. has_agency ( ) {
63
+ debug ! ( logger, "PallasChainReader has agency, finding intersect point..." ; "point" => ?point) ;
58
64
chainsync
59
65
. find_intersect ( vec ! [ point. to_owned( ) . into( ) ] )
60
66
. await ?;
67
+ } else {
68
+ debug ! ( logger, "PallasChainReader doesn't have agency, no need to find intersect point" ; ) ;
61
69
}
62
70
63
71
Ok ( ( ) )
@@ -130,6 +138,7 @@ mod tests {
130
138
131
139
use super :: * ;
132
140
141
+ use crate :: test_utils:: TestLogger ;
133
142
use crate :: { entities:: BlockNumber , test_utils:: TempDir } ;
134
143
135
144
/// Enum representing the action to be performed by the server.
@@ -253,8 +262,11 @@ mod tests {
253
262
)
254
263
. await ;
255
264
let client = tokio:: spawn ( async move {
256
- let mut chain_reader =
257
- PallasChainReader :: new ( socket_path. as_path ( ) , CardanoNetwork :: TestNet ( 10 ) ) ;
265
+ let mut chain_reader = PallasChainReader :: new (
266
+ socket_path. as_path ( ) ,
267
+ CardanoNetwork :: TestNet ( 10 ) ,
268
+ TestLogger :: stdout ( ) ,
269
+ ) ;
258
270
259
271
chain_reader
260
272
. set_chain_point ( & ChainPoint :: from ( known_point. clone ( ) ) )
@@ -285,8 +297,11 @@ mod tests {
285
297
)
286
298
. await ;
287
299
let client = tokio:: spawn ( async move {
288
- let mut chain_reader =
289
- PallasChainReader :: new ( socket_path. as_path ( ) , CardanoNetwork :: TestNet ( 10 ) ) ;
300
+ let mut chain_reader = PallasChainReader :: new (
301
+ socket_path. as_path ( ) ,
302
+ CardanoNetwork :: TestNet ( 10 ) ,
303
+ TestLogger :: stdout ( ) ,
304
+ ) ;
290
305
291
306
chain_reader
292
307
. set_chain_point ( & ChainPoint :: from ( known_point. clone ( ) ) )
@@ -317,8 +332,11 @@ mod tests {
317
332
)
318
333
. await ;
319
334
let client = tokio:: spawn ( async move {
320
- let mut chain_reader =
321
- PallasChainReader :: new ( socket_path. as_path ( ) , CardanoNetwork :: TestNet ( 10 ) ) ;
335
+ let mut chain_reader = PallasChainReader :: new (
336
+ socket_path. as_path ( ) ,
337
+ CardanoNetwork :: TestNet ( 10 ) ,
338
+ TestLogger :: stdout ( ) ,
339
+ ) ;
322
340
323
341
chain_reader
324
342
. set_chain_point ( & ChainPoint :: from ( known_point. clone ( ) ) )
0 commit comments