Skip to content

Commit 2ca4e5d

Browse files
authored
fix(rust/cardano-chain-follower): cardano-chain-follower turbo downloader load small mithril snapshot archives (#609)
* add devnet configuration for follow chains * wip * wip * wip * fix * add logging * wip * wip * wip * fix * cleanup * cleanup * wip * fix
1 parent 8e1eb8f commit 2ca4e5d

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use tracing_subscriber::EnvFilter;
3131
fn process_argument() -> (Vec<Network>, ArgMatches) {
3232
let matches = Command::new("follow_chains")
3333
.args(&[
34+
arg!(--devnet "Follow Devnet network").action(ArgAction::SetTrue),
3435
arg!(--preprod "Follow Preprod network").action(ArgAction::SetTrue),
3536
arg!(--preview "Follow Preview network").action(ArgAction::SetTrue),
3637
arg!(--mainnet "Follow Mainnet network").action(ArgAction::SetTrue),
@@ -90,6 +91,23 @@ fn process_argument() -> (Vec<Network>, ArgMatches) {
9091
if matches.get_flag("mainnet") || matches.get_flag("all") {
9192
networks.push(Network::Mainnet);
9293
}
94+
if matches.get_flag("devnet") || matches.get_flag("all") {
95+
networks.push(Network::Devnet {
96+
genesis_key: "5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c3235322c3138302c37322c3133342c3133372c3234372c3136312c36385d".to_string(),
97+
magic: 42,
98+
network_id: 42,
99+
byron_epoch_length: 100_000,
100+
byron_slot_length: 1000,
101+
byron_known_slot: 0,
102+
byron_known_hash: "8f8602837f7c6f8b8867dd1cbc1842cf51a27eaed2c70ef48325d00f8efb320f".to_string(),
103+
byron_known_time: 1_564_010_416,
104+
shelley_epoch_length: 100,
105+
shelley_slot_length: 1,
106+
shelley_known_slot: 1_598_400,
107+
shelley_known_hash: "02b1c561715da9e540411123a6135ee319b02f60b9a11a603d3305556c04329f".to_string(),
108+
shelley_known_time: 1_595_967_616,
109+
});
110+
}
93111

94112
(networks, matches)
95113
}

rust/cardano-chain-follower/src/turbo_downloader/mod.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,20 @@ impl ParallelDownloadProcessorInner {
359359
.set(RANGE.as_str(), &range_header)
360360
.call()
361361
.context("GET ranged request failed")?;
362+
362363
// let addr = get_range_response.remote_addr();
363364
// debug!("Chunk {chunk} from {addr:?}");
364-
if get_range_response.status() != StatusCode::PARTIAL_CONTENT {
365-
bail!(
366-
"Response to range request has an unexpected status code (expected {}, found {})",
367-
StatusCode::PARTIAL_CONTENT,
368-
get_range_response.status()
369-
)
370-
}
365+
anyhow::ensure!(
366+
(get_range_response.status() == StatusCode::PARTIAL_CONTENT)
367+
|| (get_range_response.status() == StatusCode::OK),
368+
"Response to range request has an unexpected status code (expected [{}], found {})",
369+
[
370+
StatusCode::PARTIAL_CONTENT.to_string(),
371+
StatusCode::OK.to_string()
372+
]
373+
.join(","),
374+
get_range_response.status()
375+
);
371376

372377
let range_size = range_end_inclusive
373378
.saturating_sub(range_start)
@@ -508,6 +513,8 @@ impl ParallelDownloadProcessor {
508513
work_queue: &crossbeam_channel::Receiver<DlWorkOrder>,
509514
chain: &Network,
510515
) {
516+
const GET_RANGE_NUM_OF_TRIES: u8 = 5;
517+
511518
debug!("Worker {worker_id} started");
512519

513520
// Each worker has its own http_client, so there is no cross worker pathology
@@ -531,23 +538,23 @@ impl ParallelDownloadProcessor {
531538
error!("Next chunk delay overflow");
532539
}
533540
}
534-
let mut retries = 0u8;
535-
let mut block;
541+
let mut block = None;
536542
// debug!("Worker {worker_id} DL chunk {next_chunk}");
537-
loop {
543+
for attempt in 1u8..=GET_RANGE_NUM_OF_TRIES {
538544
block = match params.get_range(&http_agent, next_chunk) {
539545
Ok(block) => Some(block),
540546
Err(error) => {
541-
error!("Error getting chunk: {:?}, error: {:?}", next_chunk, error);
547+
error!(
548+
"Error getting chunk: {next_chunk:?}, error: {error:?}, attempt: {attempt}",
549+
);
542550
None
543551
},
544552
};
545553

546554
// Quickly retry on error, in case its transient.
547-
if block.is_some() || retries > 3 {
555+
if block.is_some() {
548556
break;
549557
}
550-
retries = retries.saturating_add(1);
551558
}
552559
// debug!("Worker {worker_id} DL chunk done {next_chunk}: {retries}");
553560

0 commit comments

Comments
 (0)