@@ -709,13 +709,43 @@ fn check_aws_config(endpoint: &str) -> anyhow::Result<()> {
709709 Ok ( ( ) )
710710}
711711
712+ fn upload_to_forest_bucket ( path : PathBuf , network : & str , tag : & str ) -> anyhow:: Result < ( ) > {
713+ let status = std:: process:: Command :: new ( "aws" )
714+ . args ( [
715+ "s3" ,
716+ "cp" ,
717+ "--acl" ,
718+ "public-read" ,
719+ path. to_str ( ) . unwrap ( ) ,
720+ & format ! ( "s3://forest-archive/{}/{}/" , network, tag) ,
721+ "--endpoint" ,
722+ FOREST_ARCHIVE_S3_ENDPOINT ,
723+ ] )
724+ . status ( )
725+ . map_err ( |e| anyhow:: anyhow!( "Failed to execute 'aws s3 cp': {}" , e) ) ?;
726+
727+ if !status. success ( ) {
728+ bail ! (
729+ "'aws s3 cp' failed with status code: {}. Upload failed." ,
730+ status
731+ ) ;
732+ }
733+ Ok ( ( ) )
734+ }
735+
712736async fn export_lite_snapshot (
713737 store : Arc < impl Blockstore + Send + Sync + ' static > ,
714738 root : Tipset ,
715739 network : & str ,
716740 epoch : ChainEpoch ,
717741) -> anyhow:: Result < PathBuf > {
718742 let output_path: PathBuf = format_lite_snapshot ( network, epoch) ?. into ( ) ;
743+
744+ // Skip if file already exists
745+ if output_path. exists ( ) {
746+ return Ok ( output_path) ;
747+ }
748+
719749 let depth = 900 ;
720750 let diff = None ;
721751 let diff_depth = None ;
@@ -734,6 +764,37 @@ async fn export_lite_snapshot(
734764 Ok ( output_path)
735765}
736766
767+ async fn export_diff_snapshot (
768+ store : Arc < impl Blockstore + Send + Sync + ' static > ,
769+ root : Tipset ,
770+ network : & str ,
771+ epoch : ChainEpoch ,
772+ ) -> anyhow:: Result < PathBuf > {
773+ let output_path: PathBuf = format_diff_snapshot ( network, epoch) ?. into ( ) ;
774+
775+ // Skip if file already exists
776+ if output_path. exists ( ) {
777+ return Ok ( output_path) ;
778+ }
779+
780+ let depth = 30_000 ;
781+ let diff = Some ( epoch - depth) ;
782+ let diff_depth = Some ( 900 ) ;
783+ let force = false ;
784+ do_export (
785+ store,
786+ root,
787+ output_path. clone ( ) ,
788+ Some ( epoch) ,
789+ depth,
790+ diff,
791+ diff_depth,
792+ force,
793+ )
794+ . await ?;
795+ Ok ( output_path)
796+ }
797+
737798// This command is used for keeping the S3 bucket of archival snapshots
738799// up-to-date. It takes a set of snapshot files and queries the S3 bucket to see
739800// what is missing. If the input set of snapshot files can be used to generate
@@ -776,6 +837,17 @@ async fn sync_bucket(snapshot_files: Vec<PathBuf>, endpoint: String) -> anyhow::
776837 let output_path =
777838 export_lite_snapshot ( store. clone ( ) , heaviest_tipset. clone ( ) , & info. network , epoch)
778839 . await ?;
840+ upload_to_forest_bucket ( output_path, & info. network , "lite" ) ?;
841+ }
842+ }
843+
844+ for epoch in steps_in_range ( & range, 3_000 , 800 ) {
845+ if !bucket_has_diff_snapshot ( & info. network , epoch) . await ? {
846+ println ! ( " {}: Exporting diff snapshot" , epoch, ) ;
847+ let output_path =
848+ export_diff_snapshot ( store. clone ( ) , heaviest_tipset. clone ( ) , & info. network , epoch)
849+ . await ?;
850+ upload_to_forest_bucket ( output_path, & info. network , "diff" ) ?;
779851 }
780852 }
781853 Ok ( ( ) )
0 commit comments