@@ -43,7 +43,7 @@ use crate::shim::fvm_shared_latest::address::Network;
4343use crate :: shim:: machine:: GLOBAL_MULTI_ENGINE ;
4444use crate :: state_manager:: { NO_CALLBACK , StateOutput , apply_block_messages} ;
4545use anyhow:: { Context as _, bail} ;
46- use chrono:: { DateTime , NaiveDateTime } ;
46+ use chrono:: DateTime ;
4747use cid:: Cid ;
4848use clap:: Subcommand ;
4949use dialoguer:: { Confirm , theme:: ColorfulTheme } ;
@@ -619,46 +619,52 @@ fn steps_in_range(
619619 . take_while ( move |& x| x <= range. end )
620620}
621621
622- fn epoch_to_date ( network : & str , epoch : ChainEpoch ) -> anyhow:: Result < String > {
623- let genesis_timestamp = match network {
624- "mainnet" => 1598306400 ,
625- "calibnet" => 1667326380 ,
626- _ => bail ! ( "unsupported network" ) ,
627- } ;
628-
629- Ok ( NaiveDateTime :: from_timestamp_opt (
630- ( genesis_timestamp + epoch * EPOCH_DURATION_SECONDS ) as i64 ,
622+ fn epoch_to_date ( genesis_timestamp : u64 , epoch : ChainEpoch ) -> anyhow:: Result < String > {
623+ Ok ( DateTime :: from_timestamp (
624+ ( genesis_timestamp as i64 + epoch * EPOCH_DURATION_SECONDS ) as i64 ,
631625 0 ,
632626 )
633627 . unwrap_or_default ( )
634628 . format ( "%Y-%m-%d" )
635629 . to_string ( ) )
636630}
637631
638- fn format_lite_snapshot ( network : & str , epoch : ChainEpoch ) -> anyhow:: Result < String > {
632+ fn format_lite_snapshot (
633+ network : & str ,
634+ genesis_timestamp : u64 ,
635+ epoch : ChainEpoch ,
636+ ) -> anyhow:: Result < String > {
639637 Ok ( format ! (
640638 "forest_snapshot_{network}_{date}_height_{epoch}.forest.car.zst" ,
641- date = epoch_to_date( network , epoch) ?,
639+ date = epoch_to_date( genesis_timestamp , epoch) ?,
642640 epoch = epoch
643641 ) )
644642}
645643
646- fn format_diff_snapshot ( network : & str , epoch : ChainEpoch ) -> anyhow:: Result < String > {
644+ fn format_diff_snapshot (
645+ network : & str ,
646+ genesis_timestamp : u64 ,
647+ epoch : ChainEpoch ,
648+ ) -> anyhow:: Result < String > {
647649 Ok ( format ! (
648650 "forest_diff_{network}_{date}_height_{epoch}+3000.forest.car.zst" ,
649- date = epoch_to_date( network , epoch) ?,
651+ date = epoch_to_date( genesis_timestamp , epoch) ?,
650652 epoch = epoch - 3000
651653 ) )
652654}
653655
654656// Check if
655657// forest-archive.chainsafe.dev/list/network/lite/forest_snapshot_{network}_{date}_height_{epoch}.forest.car.zst
656658// exists.
657- async fn bucket_has_lite_snapshot ( network : & str , epoch : ChainEpoch ) -> anyhow:: Result < bool > {
659+ async fn bucket_has_lite_snapshot (
660+ network : & str ,
661+ genesis_timestamp : u64 ,
662+ epoch : ChainEpoch ,
663+ ) -> anyhow:: Result < bool > {
658664 let url = format ! (
659665 "https://forest-internal.chainsafe.dev/{}/lite/{}" ,
660666 network,
661- format_lite_snapshot( network, epoch) ?
667+ format_lite_snapshot( network, genesis_timestamp , epoch) ?
662668 ) ;
663669 let response = reqwest:: Client :: new ( ) . get ( url) . send ( ) . await ?;
664670 Ok ( response. status ( ) . is_success ( ) )
@@ -667,11 +673,15 @@ async fn bucket_has_lite_snapshot(network: &str, epoch: ChainEpoch) -> anyhow::R
667673// Check if
668674// forest-archive.chainsafe.dev/list/network/lite/forest_snapshot_{network}_{date}_height_{epoch}.forest.car.zst
669675// exists.
670- async fn bucket_has_diff_snapshot ( network : & str , epoch : ChainEpoch ) -> anyhow:: Result < bool > {
676+ async fn bucket_has_diff_snapshot (
677+ network : & str ,
678+ genesis_timestamp : u64 ,
679+ epoch : ChainEpoch ,
680+ ) -> anyhow:: Result < bool > {
671681 let url = format ! (
672682 "https://forest-internal.chainsafe.dev/{}/diff/{}" ,
673683 network,
674- format_diff_snapshot( network, epoch) ?
684+ format_diff_snapshot( network, genesis_timestamp , epoch) ?
675685 ) ;
676686 let response = reqwest:: Client :: new ( ) . head ( url) . send ( ) . await ?;
677687 Ok ( response. status ( ) . is_success ( ) )
@@ -737,9 +747,10 @@ async fn export_lite_snapshot(
737747 store : Arc < impl Blockstore + Send + Sync + ' static > ,
738748 root : Tipset ,
739749 network : & str ,
750+ genesis_timestamp : u64 ,
740751 epoch : ChainEpoch ,
741752) -> anyhow:: Result < PathBuf > {
742- let output_path: PathBuf = format_lite_snapshot ( network, epoch) ?. into ( ) ;
753+ let output_path: PathBuf = format_lite_snapshot ( network, genesis_timestamp , epoch) ?. into ( ) ;
743754
744755 // Skip if file already exists
745756 if output_path. exists ( ) {
@@ -768,9 +779,10 @@ async fn export_diff_snapshot(
768779 store : Arc < impl Blockstore + Send + Sync + ' static > ,
769780 root : Tipset ,
770781 network : & str ,
782+ genesis_timestamp : u64 ,
771783 epoch : ChainEpoch ,
772784) -> anyhow:: Result < PathBuf > {
773- let output_path: PathBuf = format_diff_snapshot ( network, epoch) ?. into ( ) ;
785+ let output_path: PathBuf = format_diff_snapshot ( network, genesis_timestamp , epoch) ?. into ( ) ;
774786
775787 // Skip if file already exists
776788 if output_path. exists ( ) {
@@ -808,7 +820,7 @@ async fn sync_bucket(snapshot_files: Vec<PathBuf>, endpoint: String) -> anyhow::
808820
809821 let info = ArchiveInfo :: from_store ( & store, "ManyCAR" . to_string ( ) , heaviest_tipset. clone ( ) ) ?;
810822
811- let genesis = heaviest_tipset. genesis ( & store) ?. timestamp ;
823+ let genesis_timestamp = heaviest_tipset. genesis ( & store) ?. timestamp ;
812824
813825 let range = info. epoch_range ( ) ;
814826
@@ -819,34 +831,44 @@ async fn sync_bucket(snapshot_files: Vec<PathBuf>, endpoint: String) -> anyhow::
819831 println ! (
820832 " {}: {}" ,
821833 epoch,
822- bucket_has_lite_snapshot( & info. network, epoch) . await ?
834+ bucket_has_lite_snapshot( & info. network, genesis_timestamp , epoch) . await ?
823835 ) ;
824836 }
825837 println ! ( "Diffs:" ) ;
826838 for epoch in steps_in_range ( & range, 3_000 , 3_800 ) {
827839 println ! (
828840 " {}: {}" ,
829841 epoch,
830- bucket_has_diff_snapshot( & info. network, epoch) . await ?
842+ bucket_has_diff_snapshot( & info. network, genesis_timestamp , epoch) . await ?
831843 ) ;
832844 }
833845
834846 for epoch in steps_in_range ( & range, 30_000 , 800 ) {
835- if !bucket_has_lite_snapshot ( & info. network , epoch) . await ? {
847+ if !bucket_has_lite_snapshot ( & info. network , genesis_timestamp , epoch) . await ? {
836848 println ! ( " {}: Exporting lite snapshot" , epoch, ) ;
837- let output_path =
838- export_lite_snapshot ( store. clone ( ) , heaviest_tipset. clone ( ) , & info. network , epoch)
839- . await ?;
849+ let output_path = export_lite_snapshot (
850+ store. clone ( ) ,
851+ heaviest_tipset. clone ( ) ,
852+ & info. network ,
853+ genesis_timestamp,
854+ epoch,
855+ )
856+ . await ?;
840857 upload_to_forest_bucket ( output_path, & info. network , "lite" ) ?;
841858 }
842859 }
843860
844861 for epoch in steps_in_range ( & range, 3_000 , 3_800 ) {
845- if !bucket_has_diff_snapshot ( & info. network , epoch) . await ? {
862+ if !bucket_has_diff_snapshot ( & info. network , genesis_timestamp , epoch) . await ? {
846863 println ! ( " {}: Exporting diff snapshot" , epoch, ) ;
847- let output_path =
848- export_diff_snapshot ( store. clone ( ) , heaviest_tipset. clone ( ) , & info. network , epoch)
849- . await ?;
864+ let output_path = export_diff_snapshot (
865+ store. clone ( ) ,
866+ heaviest_tipset. clone ( ) ,
867+ & info. network ,
868+ genesis_timestamp,
869+ epoch,
870+ )
871+ . await ?;
850872 upload_to_forest_bucket ( output_path, & info. network , "diff" ) ?;
851873 }
852874 }
0 commit comments