Skip to content

Commit b96551f

Browse files
committed
fix: ChainReader fails on find intersect without agency
When the chain sync client does not have agency (i.e. is waiting for the server to callback), the find intersect point triggered is not allowed and is now skipped.
1 parent 9f8b589 commit b96551f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

mithril-common/src/chain_reader/pallas_chain_reader.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ impl PallasChainReader {
5454
let client = self.get_client().await?;
5555
let chainsync = client.chainsync();
5656

57-
chainsync
58-
.find_intersect(vec![point.to_owned().into()])
59-
.await?;
57+
if chainsync.has_agency() {
58+
chainsync
59+
.find_intersect(vec![point.to_owned().into()])
60+
.await?;
61+
}
6062

6163
Ok(())
6264
}
@@ -327,6 +329,19 @@ mod tests {
327329
let client = chain_reader.get_client().await.unwrap();
328330
client.chainsync().request_next().await.unwrap();
329331

332+
// make sure that the chainsync client returns an error when attempting to find intersection without agency
333+
client
334+
.chainsync()
335+
.find_intersect(vec![known_point.clone()])
336+
.await
337+
.expect_err("chainsync find_intersect without agency should fail");
338+
339+
// make sure that setting the chain point is harmless when the chainsync client does not have agency
340+
chain_reader
341+
.set_chain_point(&ChainPoint::from(known_point.clone()))
342+
.await
343+
.unwrap();
344+
330345
chain_reader.get_next_chain_block().await.unwrap().unwrap()
331346
});
332347

0 commit comments

Comments
 (0)