Skip to content

Commit 2008c9c

Browse files
stevenjMr-Leshiyno30bit
authored
fix(rust): Update Mithril Crate Dependency (#313)
* bump to the latest mithril-client version 0.12.0 * wip * fix * remove commented out code * fix * fix comments * fix: restore original logic * fix: Make minimum necessary changes to use new mithril crate version * fix: * Update rust/cardano-chain-follower/src/mithril_turbo_downloader.rs Co-authored-by: Artur Helmanau <[email protected]> * Update rust/cardano-chain-follower/src/mithril_turbo_downloader.rs Co-authored-by: Artur Helmanau <[email protected]> --------- Co-authored-by: Mr-Leshiy <[email protected]> Co-authored-by: Artur Helmanau <[email protected]>
1 parent cc7edbe commit 2008c9c

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

rust/cardano-chain-follower/Cargo.toml

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalys
1515
pallas-hardano = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
1616
pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
1717

18-
mithril-client = { version = "0.10.4", default-features = false, features = [
18+
mithril-client = { version = "0.12.2", default-features = false, features = [
1919
"full",
2020
"num-integer-backend",
2121
] }
@@ -24,7 +24,7 @@ catalyst-types = { version = "0.0.3", path = "../catalyst-types" }
2424

2525

2626
thiserror = "1.0.69"
27-
tokio = { version = "1.42.0", features = [
27+
tokio = { version = "1.45.0", features = [
2828
"macros",
2929
"rt",
3030
"net",
@@ -58,14 +58,6 @@ hickory-resolver = { version = "0.24.2", features = ["dns-over-rustls"] }
5858
moka = { version = "0.12.9", features = ["sync"] }
5959
cpu-time = "1.0.0"
6060

61-
# Its a transitive dependency of the "mithril-client" crate,
62-
# but its breaks API after version "0.2.21".
63-
mithril-build-script = { version = "=0.2.19" }
64-
65-
[package.metadata.cargo-machete]
66-
# remove that after fixing issues with latest crates
67-
ignored = ["mithril-build-script"]
68-
6961
[dev-dependencies]
7062
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
7163
test-log = { version = "0.2.16", default-features = false, features = [

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl MithrilSnapshotConfig {
353353
.map_err(|e| Error::MithrilClient(self.chain, url.clone(), e))?;
354354

355355
let snapshots = client
356-
.snapshot()
356+
.cardano_database()
357357
.list()
358358
.await
359359
.map_err(|e| Error::MithrilClient(self.chain, url.clone(), e))?;

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async fn get_latest_snapshots(
5252
client: &Client, network: Network,
5353
) -> Option<(SnapshotListItem, SnapshotListItem)> {
5454
// Get current latest snapshot from the aggregator
55-
let snapshots = match client.snapshot().list().await {
55+
let snapshots = match client.cardano_database().list().await {
5656
Ok(s) => s,
5757
Err(e) => {
5858
error!("Unexpected Error [{}]: Unable to get Snapshot List from Aggregator for {}. Mithril Snapshots can not update. Sleeping.", network, e);
@@ -75,7 +75,7 @@ async fn get_latest_snapshots(
7575
async fn get_snapshot_by_id(
7676
client: &Client, network: Network, snapshot_id: &SnapshotId,
7777
) -> Option<SnapshotListItem> {
78-
let snapshots = match client.snapshot().list().await {
78+
let snapshots = match client.cardano_database().list().await {
7979
Ok(s) => s,
8080
Err(e) => {
8181
error!("Unexpected Error [{}]: Unable to get Snapshot List from Aggregator for {}. Mithril Snapshots can not update. Sleeping.", network, e);
@@ -105,7 +105,7 @@ fn create_client(cfg: &MithrilSnapshotConfig) -> Option<(Client, Arc<MithrilTurb
105105
&cfg.genesis_key,
106106
)
107107
//.add_feedback_receiver(receiver)
108-
.with_snapshot_downloader(downloader.clone())
108+
.with_http_file_downloader(downloader.clone())
109109
.build()
110110
{
111111
Ok(c) => c,
@@ -165,7 +165,7 @@ async fn get_snapshot(
165165
client: &Client, snapshot_item: &SnapshotListItem, network: Network,
166166
) -> Option<Snapshot> {
167167
let latest_digest = snapshot_item.digest.as_ref();
168-
let snapshot = match client.snapshot().get(latest_digest).await {
168+
let snapshot = match client.cardano_database().get(latest_digest).await {
169169
Ok(snapshot) => {
170170
if let Some(snapshot) = snapshot {
171171
snapshot
@@ -598,7 +598,7 @@ async fn download_and_validate_snapshot(
598598

599599
// Download and unpack the actual snapshot archive.
600600
if let Err(error) = client
601-
.snapshot()
601+
.cardano_database()
602602
.download_unpack(snapshot, &cfg.tmp_path())
603603
.await
604604
{
@@ -612,7 +612,7 @@ async fn download_and_validate_snapshot(
612612
cfg.chain
613613
);
614614

615-
if let Err(error) = client.snapshot().add_statistics(snapshot).await {
615+
if let Err(error) = client.cardano_database().add_statistics(snapshot).await {
616616
// Just log not fatal to anything.
617617
error!(
618618
"Could not increment snapshot download statistics for {}: {error}",

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

+32-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use catalyst_types::{conversion::from_saturating, mmap_file::MemoryMapFile};
1818
use dashmap::DashSet;
1919
use memx::memcmp;
2020
use mithril_client::{
21-
common::CompressionAlgorithm, snapshot_downloader::SnapshotDownloader, MithrilResult,
21+
common::CompressionAlgorithm,
22+
file_downloader::{DownloadEvent, FileDownloader, FileDownloaderUri},
23+
MithrilResult,
2224
};
2325
use tar::{Archive, EntryType};
2426
use tokio::{fs::create_dir_all, task::spawn_blocking};
@@ -323,11 +325,13 @@ impl MithrilTurboDownloader {
323325
})
324326
.await;
325327

328+
// Must always be called when download ends, regardless of the reason.
329+
stats::mithril_dl_finished(self.inner.cfg.chain, None);
330+
326331
if let Ok(result) = result {
327332
return result;
328333
}
329334

330-
stats::mithril_dl_finished(self.inner.cfg.chain, None);
331335
bail!("Download and Dedup task failed");
332336
}
333337
}
@@ -341,11 +345,30 @@ fn get_file_size_sync(file: &Path) -> Option<u64> {
341345
}
342346

343347
#[async_trait]
344-
impl SnapshotDownloader for MithrilTurboDownloader {
348+
impl FileDownloader for MithrilTurboDownloader {
345349
async fn download_unpack(
346-
&self, location: &str, target_dir: &Path, _compression_algorithm: CompressionAlgorithm,
347-
_download_id: &str, _snapshot_size: u64,
350+
&self, location: &FileDownloaderUri, file_size: u64, target_dir: &Path,
351+
compression_algorithm: Option<CompressionAlgorithm>, download_event_type: DownloadEvent,
348352
) -> MithrilResult<()> {
353+
debug!(
354+
?location,
355+
file_size,
356+
?target_dir,
357+
?compression_algorithm,
358+
?download_event_type,
359+
"Download And Unpack Mithril."
360+
);
361+
362+
// We only support full downloads for now.
363+
if !matches!(download_event_type, DownloadEvent::Full { .. }) {
364+
bail!("Unsupported Download Event Type: {:?}", download_event_type);
365+
}
366+
367+
let location = location.as_str();
368+
369+
// Probe was removed in FileDownloader, so call it directly
370+
self.probe(location).await?;
371+
349372
self.create_directories(target_dir).await?;
350373

351374
// DL Start stats set after DL actually started inside the probe call.
@@ -370,7 +393,11 @@ impl SnapshotDownloader for MithrilTurboDownloader {
370393

371394
Ok(())
372395
}
396+
}
373397

398+
impl MithrilTurboDownloader {
399+
/// Set up the download.
400+
/// Called `probe` as this used to exist in an earlier trait which was removed.
374401
async fn probe(&self, location: &str) -> MithrilResult<()> {
375402
debug!("Probe Snapshot location='{location}'.");
376403
let dl_config = self.inner.cfg.dl_config.clone().unwrap_or_default();

0 commit comments

Comments
 (0)