@@ -7,6 +7,7 @@ use pallas_network::{
77 miniprotocols:: chainsync:: { BlockContent , NextResponse } ,
88} ;
99use pallas_traverse:: MultiEraBlock ;
10+ use slog:: { debug, Logger } ;
1011
1112use crate :: { cardano_block_scanner:: ScannedBlock , entities:: ChainPoint , CardanoNetwork , StdResult } ;
1213
@@ -17,15 +18,17 @@ pub struct PallasChainReader {
1718 socket : PathBuf ,
1819 network : CardanoNetwork ,
1920 client : Option < NodeClient > ,
21+ logger : Logger ,
2022}
2123
2224impl PallasChainReader {
2325 /// 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 {
2527 Self {
2628 socket : socket. to_owned ( ) ,
2729 network,
2830 client : None ,
31+ logger,
2932 }
3033 }
3134
@@ -42,6 +45,7 @@ impl PallasChainReader {
4245 async fn get_client ( & mut self ) -> StdResult < & mut NodeClient > {
4346 if self . client . is_none ( ) {
4447 self . client = Some ( self . new_client ( ) . await ?) ;
48+ debug ! ( self . logger, "PallasChainReader connected to a new client" ) ;
4549 }
4650
4751 self . client
@@ -51,13 +55,17 @@ impl PallasChainReader {
5155
5256 /// Intersects the point of the chain with the given point.
5357 async fn find_intersect_point ( & mut self , point : & ChainPoint ) -> StdResult < ( ) > {
58+ let logger = self . logger . clone ( ) ;
5459 let client = self . get_client ( ) . await ?;
5560 let chainsync = client. chainsync ( ) ;
5661
5762 if chainsync. has_agency ( ) {
63+ debug ! ( logger, "PallasChainReader has agency, finding intersect point..." ; "point" => ?point) ;
5864 chainsync
5965 . find_intersect ( vec ! [ point. to_owned( ) . into( ) ] )
6066 . await ?;
67+ } else {
68+ debug ! ( logger, "PallasChainReader doesn't have agency, no need to find intersect point" ; ) ;
6169 }
6270
6371 Ok ( ( ) )
@@ -130,6 +138,7 @@ mod tests {
130138
131139 use super :: * ;
132140
141+ use crate :: test_utils:: TestLogger ;
133142 use crate :: { entities:: BlockNumber , test_utils:: TempDir } ;
134143
135144 /// Enum representing the action to be performed by the server.
@@ -253,8 +262,11 @@ mod tests {
253262 )
254263 . await ;
255264 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+ ) ;
258270
259271 chain_reader
260272 . set_chain_point ( & ChainPoint :: from ( known_point. clone ( ) ) )
@@ -285,8 +297,11 @@ mod tests {
285297 )
286298 . await ;
287299 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+ ) ;
290305
291306 chain_reader
292307 . set_chain_point ( & ChainPoint :: from ( known_point. clone ( ) ) )
@@ -317,8 +332,11 @@ mod tests {
317332 )
318333 . await ;
319334 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+ ) ;
322340
323341 chain_reader
324342 . set_chain_point ( & ChainPoint :: from ( known_point. clone ( ) ) )
0 commit comments