|
1 | 1 | use std::{
|
2 | 2 | fmt::Write,
|
| 3 | + fs::File, |
3 | 4 | path::{Path, PathBuf},
|
4 | 5 | sync::Arc,
|
5 | 6 | time::Duration,
|
@@ -252,6 +253,14 @@ impl SnapshotService for MithrilClientSnapshotService {
|
252 | 253 | let unpacker = unpacker.unpack_snapshot(&snapshot_path, &db_dir);
|
253 | 254 | self.wait_spinner(&progress_bar, unpacker).await?;
|
254 | 255 |
|
| 256 | + // Append 'clean' file to speedup node bootstrap |
| 257 | + if let Err(error) = File::create(db_dir.join("clean")) { |
| 258 | + warn!( |
| 259 | + "Could not create clean shutdown marker file in directory {}: {error}", |
| 260 | + db_dir.display() |
| 261 | + ); |
| 262 | + }; |
| 263 | + |
255 | 264 | progress_bar.println("6/7 - Computing the snapshot digest…")?;
|
256 | 265 | let unpacked_snapshot_digest = self
|
257 | 266 | .immutable_digester
|
@@ -551,6 +560,51 @@ mod tests {
|
551 | 560 | assert_eq!(Some(OsStr::new("db")), filepath.file_name());
|
552 | 561 | }
|
553 | 562 |
|
| 563 | + #[tokio::test] |
| 564 | + async fn test_download_snapshot_ok_add_clean_file_allowing_node_bootstrap_speedup() { |
| 565 | + let test_path = std::env::temp_dir() |
| 566 | + .join("test_download_snapshot_ok_add_clean_file_allowing_node_bootstrap_speedup"); |
| 567 | + let _ = std::fs::remove_dir_all(&test_path); |
| 568 | + |
| 569 | + let (http_client, certificate_verifier, digester) = |
| 570 | + get_mocks_for_snapshot_service_configured_to_make_download_succeed(); |
| 571 | + |
| 572 | + let mut builder = get_dep_builder(Arc::new(http_client)); |
| 573 | + builder.certificate_verifier = Some(Arc::new(certificate_verifier)); |
| 574 | + builder.immutable_digester = Some(Arc::new(digester)); |
| 575 | + let snapshot_service = builder.get_snapshot_service().await.unwrap(); |
| 576 | + |
| 577 | + let snapshot = FromSnapshotMessageAdapter::adapt(get_snapshot_message()); |
| 578 | + build_dummy_snapshot( |
| 579 | + "digest-10.tar.gz", |
| 580 | + "1234567890".repeat(124).as_str(), |
| 581 | + &test_path, |
| 582 | + ); |
| 583 | + |
| 584 | + let (_, verifier) = setup_genesis(); |
| 585 | + let genesis_verification_key = verifier.to_verification_key(); |
| 586 | + |
| 587 | + let filepath = snapshot_service |
| 588 | + .download( |
| 589 | + &snapshot, |
| 590 | + &test_path, |
| 591 | + &key_encode_hex(genesis_verification_key).unwrap(), |
| 592 | + ProgressDrawTarget::hidden(), |
| 593 | + ) |
| 594 | + .await |
| 595 | + .expect("Snapshot download should succeed."); |
| 596 | + |
| 597 | + let clean_file = filepath.join("clean"); |
| 598 | + |
| 599 | + assert!( |
| 600 | + clean_file.is_file(), |
| 601 | + "'clean' file should exist and be a file" |
| 602 | + ); |
| 603 | + |
| 604 | + let clean_file_metadata = clean_file.metadata().unwrap(); |
| 605 | + assert_eq!(clean_file_metadata.len(), 0, "'clean' file should be empty") |
| 606 | + } |
| 607 | + |
554 | 608 | #[tokio::test]
|
555 | 609 | async fn test_download_snapshot_invalid_digest() {
|
556 | 610 | let test_path = std::env::temp_dir().join("test_download_snapshot_invalid_digest");
|
|
0 commit comments