Skip to content

Commit 59f817f

Browse files
authored
fix(rust/cardano-chain-follower): cardano-chain-follower WASM refinement (#480)
* fix: deps Signed-off-by: bkioshn <[email protected]> * fix: import Signed-off-by: bkioshn <[email protected]> * fix: bump cat-type, rbac-reg, and cardano-bc-type Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]>
1 parent 15c5b0d commit 59f817f

File tree

8 files changed

+60
-57
lines changed

8 files changed

+60
-57
lines changed

rust/cardano-chain-follower/Cargo.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-chain-follower"
3-
version = "0.0.12"
3+
version = "0.0.13"
44
edition.workspace = true
55
authors.workspace = true
66
homepage.workspace = true
@@ -11,18 +11,13 @@ license.workspace = true
1111
workspace = true
1212

1313
[dependencies]
14-
pallas = { version = "0.33.0" }
15-
pallas-hardano = { version = "0.33.0" }
16-
pallas-crypto = { version = "0.33.0" }
17-
1814
mithril-client = { version = "0.12.2", default-features = false, features = [
1915
"full",
2016
"num-integer-backend",
2117
] }
2218

23-
cardano-blockchain-types = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-blockchain-types-v0.0.5" }
24-
catalyst-types = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types-v0.0.5" }
25-
19+
cardano-blockchain-types = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-blockchain-types/v0.0.6" }
20+
catalyst-types = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.6" }
2621

2722
thiserror = "1.0.69"
2823
tokio = { version = "1.45.0", features = [
@@ -65,7 +60,7 @@ test-log = { version = "0.2.16", default-features = false, features = [
6560
"trace",
6661
] }
6762
clap = "4.5.23"
68-
rbac-registration = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration-v0.0.6" }
63+
rbac-registration = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.8" }
6964
minicbor = { version = "2.0.0", features = ["alloc","half"]}
7065

7166
# Note, these features are for support of features exposed by dependencies.

rust/cardano-chain-follower/examples/follow_chains.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//#![allow(clippy::unwrap_used)]
77

88
use cardano_blockchain_types::{
9-
Cip36, Fork, MetadatumLabel, MultiEraBlock, Network, Point, Slot, TransactionId, TxnIndex,
9+
hashes::TransactionId, pallas_crypto, pallas_traverse, Cip36, Fork, MetadatumLabel,
10+
MultiEraBlock, Network, Point, Slot, TxnIndex,
1011
};
1112
#[cfg(feature = "mimalloc")]
1213
use mimalloc::MiMalloc;
13-
use pallas::ledger::traverse::MultiEraTx;
14+
use pallas_traverse::MultiEraTx;
1415
use rbac_registration::cardano::cip509::Cip509;
1516

1617
/// Use Mimalloc for the global allocator.
@@ -502,23 +503,23 @@ fn update_largest_metadata(
502503

503504
/// Helper function for logging the raw box auxiliary data.
504505
fn raw_aux_info(
505-
block: &pallas::ledger::traverse::MultiEraBlock,
506+
block: &pallas_traverse::MultiEraBlock,
506507
network: Network,
507508
) {
508509
match block {
509-
pallas::ledger::traverse::MultiEraBlock::AlonzoCompatible(b, _) => {
510+
pallas_traverse::MultiEraBlock::AlonzoCompatible(b, _) => {
510511
info!(
511512
chain = network.to_string(),
512513
"Raw Aux Data: {:02x?}", b.auxiliary_data_set
513514
);
514515
},
515-
pallas::ledger::traverse::MultiEraBlock::Babbage(b) => {
516+
pallas_traverse::MultiEraBlock::Babbage(b) => {
516517
info!(
517518
chain = network.to_string(),
518519
"Raw Aux Data: {:02x?}", b.auxiliary_data_set
519520
);
520521
},
521-
pallas::ledger::traverse::MultiEraBlock::Conway(b) => {
522+
pallas_traverse::MultiEraBlock::Conway(b) => {
522523
info!(
523524
chain = network.to_string(),
524525
"Raw Aux Data: {:02x?}", b.auxiliary_data_set
@@ -530,12 +531,12 @@ fn raw_aux_info(
530531

531532
/// Helper function for updating the largest auxiliary data.
532533
fn update_largest_aux(
533-
block: &pallas::ledger::traverse::MultiEraBlock,
534+
block: &pallas_traverse::MultiEraBlock,
534535
network: Network,
535536
largest_metadata_size: &mut usize,
536537
) {
537538
match block {
538-
pallas::ledger::traverse::MultiEraBlock::AlonzoCompatible(ref b, _) => {
539+
pallas_traverse::MultiEraBlock::AlonzoCompatible(ref b, _) => {
539540
b.auxiliary_data_set.iter().for_each(|(txn_idx, aux_data)| {
540541
compare_and_log_aux(
541542
aux_data.raw_cbor().len(),
@@ -546,7 +547,7 @@ fn update_largest_aux(
546547
);
547548
});
548549
},
549-
pallas::ledger::traverse::MultiEraBlock::Babbage(ref b) => {
550+
pallas_traverse::MultiEraBlock::Babbage(ref b) => {
550551
b.auxiliary_data_set.iter().for_each(|(txn_idx, aux_data)| {
551552
compare_and_log_aux(
552553
aux_data.raw_cbor().len(),
@@ -557,7 +558,7 @@ fn update_largest_aux(
557558
);
558559
});
559560
},
560-
pallas::ledger::traverse::MultiEraBlock::Conway(ref b) => {
561+
pallas_traverse::MultiEraBlock::Conway(ref b) => {
561562
b.auxiliary_data_set.iter().for_each(|(txn_idx, aux_data)| {
562563
compare_and_log_aux(
563564
aux_data.raw_cbor().len(),

rust/cardano-chain-follower/src/chain_sync.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
use std::time::Duration;
77

88
use anyhow::Context;
9-
use cardano_blockchain_types::{Fork, MultiEraBlock, Network, Point};
10-
use pallas::{
11-
ledger::traverse::MultiEraHeader,
12-
network::{
13-
facades::PeerClient,
9+
use cardano_blockchain_types::{
10+
pallas_network::{
11+
facades,
1412
miniprotocols::chainsync::{self, HeaderContent, Tip},
1513
},
14+
pallas_traverse::MultiEraHeader,
15+
Fork, MultiEraBlock, Network, Point,
1616
};
1717
use tokio::{
1818
spawn,
@@ -51,12 +51,12 @@ const MAX_NODE_CONNECT_RETRIES: u64 = 5;
5151
async fn retry_connect(
5252
addr: &str,
5353
magic: u64,
54-
) -> std::result::Result<PeerClient, pallas::network::facades::Error> {
54+
) -> std::result::Result<facades::PeerClient, facades::Error> {
5555
let mut retries = MAX_NODE_CONNECT_RETRIES;
5656
loop {
5757
match timeout(
5858
Duration::from_secs(MAX_NODE_CONNECT_TIME_SECS),
59-
PeerClient::connect(addr, magic),
59+
facades::PeerClient::connect(addr, magic),
6060
)
6161
.await
6262
{
@@ -75,9 +75,9 @@ async fn retry_connect(
7575
Err(error) => {
7676
retries = retries.saturating_sub(1);
7777
if retries == 0 {
78-
return Err(pallas::network::facades::Error::ConnectFailure(
79-
tokio::io::Error::other(format!("failed to connect to {addr} : {error}")),
80-
));
78+
return Err(facades::Error::ConnectFailure(tokio::io::Error::other(
79+
format!("failed to connect to {addr} : {error}"),
80+
)));
8181
}
8282
debug!("retrying {retries} connect to {addr} : {error:?}");
8383
},
@@ -87,7 +87,7 @@ async fn retry_connect(
8787

8888
/// Purge the live chain, and intersect with TIP.
8989
async fn purge_and_intersect_tip(
90-
client: &mut PeerClient,
90+
client: &mut facades::PeerClient,
9191
chain: Network,
9292
) -> Result<Point> {
9393
if let Err(error) = purge_live_chain(chain, &Point::TIP) {
@@ -105,7 +105,7 @@ async fn purge_and_intersect_tip(
105105

106106
/// Resynchronize to the live tip in memory.
107107
async fn resync_live_tip(
108-
client: &mut PeerClient,
108+
client: &mut facades::PeerClient,
109109
chain: Network,
110110
) -> Result<Point> {
111111
let sync_points = get_intersect_points(chain);
@@ -127,7 +127,7 @@ async fn resync_live_tip(
127127

128128
/// Fetch a single block from the Peer, and decode it.
129129
async fn fetch_block_from_peer(
130-
peer: &mut PeerClient,
130+
peer: &mut facades::PeerClient,
131131
chain: Network,
132132
point: Point,
133133
previous_point: Point,
@@ -150,7 +150,7 @@ async fn fetch_block_from_peer(
150150
/// Fetch the rollback block, and try and insert it into the live-chain.
151151
/// If its a real rollback, it will purge the chain ahead of the block automatically.
152152
async fn process_rollback_actual(
153-
peer: &mut PeerClient,
153+
peer: &mut facades::PeerClient,
154154
chain: Network,
155155
point: Point,
156156
tip: &Tip,
@@ -198,7 +198,7 @@ async fn process_rollback_actual(
198198

199199
/// Process a rollback detected from the peer.
200200
async fn process_rollback(
201-
peer: &mut PeerClient,
201+
peer: &mut facades::PeerClient,
202202
chain: Network,
203203
point: Point,
204204
tip: &Tip,
@@ -230,7 +230,7 @@ async fn process_rollback(
230230

231231
/// Process a rollback detected from the peer.
232232
async fn process_next_block(
233-
peer: &mut PeerClient,
233+
peer: &mut facades::PeerClient,
234234
chain: Network,
235235
header: HeaderContent,
236236
tip: &Tip,
@@ -278,7 +278,7 @@ async fn process_next_block(
278278
///
279279
/// We take ownership of the client because of that.
280280
async fn follow_chain(
281-
peer: &mut PeerClient,
281+
peer: &mut facades::PeerClient,
282282
chain: Network,
283283
fork_count: &mut Fork,
284284
) -> anyhow::Result<()> {
@@ -341,7 +341,7 @@ const PEER_FAILURE_RECONNECT_DELAY: Duration = Duration::from_secs(10);
341341
async fn persistent_reconnect(
342342
addr: &str,
343343
chain: Network,
344-
) -> PeerClient {
344+
) -> facades::PeerClient {
345345
// Not yet connected to the peer.
346346
stats::peer_connected(chain, false, addr);
347347

rust/cardano-chain-follower/src/chain_sync_live_chains.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
time::Duration,
77
};
88

9-
use cardano_blockchain_types::{Fork, MultiEraBlock, Network, Point, Slot};
9+
use cardano_blockchain_types::{pallas_primitives, Fork, MultiEraBlock, Network, Point, Slot};
1010
use crossbeam_skiplist::SkipMap;
1111
use rayon::prelude::*;
1212
use strum::IntoEnumIterator;
@@ -364,7 +364,7 @@ impl ProtectedLiveChainBlockList {
364364
}
365365

366366
/// Get chain sync intersection points for communicating with peer node.
367-
fn get_intersect_points(&self) -> Vec<pallas::network::miniprotocols::Point> {
367+
fn get_intersect_points(&self) -> Vec<pallas_primitives::types::point::Point> {
368368
let mut intersect_points = Vec::new();
369369

370370
let Ok(chain) = self.0.read() else {
@@ -562,7 +562,7 @@ pub(crate) fn purge_live_chain(
562562

563563
/// Get intersection points to try and find best point to connect to the node on
564564
/// reconnect.
565-
pub(crate) fn get_intersect_points(chain: Network) -> Vec<pallas::network::miniprotocols::Point> {
565+
pub(crate) fn get_intersect_points(chain: Network) -> Vec<pallas_primitives::types::point::Point> {
566566
let live_chain = get_live_chain(chain);
567567
live_chain.get_intersect_points()
568568
}

rust/cardano-chain-follower/src/error.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
33
use std::{io, path::PathBuf};
44

5-
use cardano_blockchain_types::Network;
6-
use pallas::network::miniprotocols::chainsync;
5+
use cardano_blockchain_types::{
6+
pallas_hardano,
7+
pallas_network::{self, miniprotocols::chainsync},
8+
pallas_traverse, Network,
9+
};
710
use thiserror::Error;
811

912
/// Crate error type.
@@ -14,10 +17,10 @@ pub enum Error {
1417
Codec(String),
1518
/// Client connection error.
1619
#[error("Client error: {0:?}")]
17-
Client(pallas::network::facades::Error),
20+
Client(pallas_network::facades::Error),
1821
/// Blockfetch protocol error.
1922
#[error("Blockfetch error: {0:?}")]
20-
Blockfetch(pallas::network::miniprotocols::blockfetch::ClientError),
23+
Blockfetch(pallas_network::miniprotocols::blockfetch::ClientError),
2124
/// Chainsync protocol error.
2225
#[error("Chainsync error: {0:?}")]
2326
Chainsync(chainsync::ClientError),
@@ -47,7 +50,7 @@ pub enum Error {
4750
MithrilSnapshotChunk(pallas_hardano::storage::immutable::chunk::Error),
4851
/// Mithril snapshot traversal error.
4952
#[error("Failed to traverse block(s) from Mithril snapshot")]
50-
MithrilSnapshotTraverse(pallas::ledger::traverse::Error),
53+
MithrilSnapshotTraverse(pallas_traverse::Error),
5154
/// Failed to parse network error.
5255
#[error("Failed to parse network")]
5356
ParseNetwork,

rust/cardano-chain-follower/src/follow.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Cardano chain follow module.
22
3-
use cardano_blockchain_types::{Fork, MultiEraBlock, Network, Point};
4-
use pallas::network::miniprotocols::txmonitor::{TxBody, TxId};
3+
use cardano_blockchain_types::{
4+
pallas_network::miniprotocols::txmonitor::{TxBody, TxId},
5+
Fork, MultiEraBlock, Network, Point,
6+
};
57
use tokio::sync::broadcast::{self};
68
use tracing::{debug, error, warn};
79

@@ -409,13 +411,15 @@ impl ChainFollower {
409411

410412
#[cfg(test)]
411413
mod tests {
414+
use cardano_blockchain_types::pallas_traverse;
415+
412416
use super::*;
413417

414418
fn mock_block() -> MultiEraBlock {
415419
let raw_block = hex::decode(include_str!("./../test_data/shelley.block"))
416420
.expect("Failed to decode hex block.");
417421

418-
let pallas_block = pallas::ledger::traverse::MultiEraBlock::decode(raw_block.as_slice())
422+
let pallas_block = pallas_traverse::MultiEraBlock::decode(raw_block.as_slice())
419423
.expect("cannot decode block");
420424

421425
let previous_point = Point::new(

rust/cardano-chain-follower/src/mithril_query.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
33
use std::path::Path;
44

5-
use cardano_blockchain_types::{Network, Point};
6-
use pallas_hardano::storage::immutable::FallibleBlock;
5+
use cardano_blockchain_types::{
6+
pallas_hardano::{self},
7+
Network, Point,
8+
};
79
use tokio::task;
810

911
use crate::{
@@ -12,7 +14,8 @@ use crate::{
1214
};
1315

1416
/// Synchronous Immutable block iterator.
15-
pub(crate) type ImmutableBlockIterator = Box<dyn Iterator<Item = FallibleBlock> + Send + Sync>;
17+
pub(crate) type ImmutableBlockIterator =
18+
Box<dyn Iterator<Item = pallas_hardano::storage::immutable::FallibleBlock> + Send + Sync>;
1619

1720
/// Get a mithril snapshot iterator.
1821
pub(crate) async fn make_mithril_iterator(

rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
sync::{Arc, Mutex},
77
};
88

9-
use cardano_blockchain_types::{Fork, MultiEraBlock, Network, Point};
9+
use cardano_blockchain_types::{pallas_traverse, Fork, MultiEraBlock, Network, Point};
1010
use logcall::logcall;
1111
use tokio::task;
1212
use tracing::{debug, error};
@@ -104,8 +104,7 @@ impl MithrilSnapshotIterator {
104104

105105
match next {
106106
Some(Ok(raw_block)) => {
107-
let Ok(block) = pallas::ledger::traverse::MultiEraBlock::decode(&raw_block)
108-
else {
107+
let Ok(block) = pallas_traverse::MultiEraBlock::decode(&raw_block) else {
109108
return None;
110109
};
111110

@@ -267,9 +266,7 @@ impl Iterator for MithrilSnapshotIteratorInner {
267266

268267
// We cannot fully decode this block because we don't know its previous point,
269268
// So this MUST be the first block in iteration, so use it as the previous.
270-
if let Ok(raw_decoded_block) =
271-
pallas::ledger::traverse::MultiEraBlock::decode(&block)
272-
{
269+
if let Ok(raw_decoded_block) = pallas_traverse::MultiEraBlock::decode(&block) {
273270
// debug!("Pre Previous update 2 : {:?}", self.previous);
274271
self.previous = Point::new(
275272
raw_decoded_block.slot().into(),

0 commit comments

Comments
 (0)