fn maybe_upsert_work_report(
        reporter: &T::AccountId,
        anchor: &TarsAnchor,
        reported_srd_size: u64,
        reported_files_size: u64,
        added_files: &Vec<(MerkleRoot, u64, u64)>,
        deleted_files: &Vec<(MerkleRoot, u64, u64)>,
        reported_srd_root: &MerkleRoot,
        reported_files_root: &MerkleRoot,
        report_slot: u64,
    ) {
        let mut old_used: u64 = 0;
        let mut old_free: u64 = 0;
        let mut old_reported_files_size: u64 = 0;
        // 1. Mark who has reported in this (report)slot
        ReportedInSlot::insert(&anchor, report_slot, true);

        // 2. Update sOrder and get changed size
        // loop added. if not exist, calculate used.
        // loop deleted, need to check each key whether we should delete it or not
        let added_files = Self::update_files(reporter, added_files, &anchor, true);
        let deleted_files = Self::update_files(reporter, deleted_files, &anchor, false);

        // 3. If contains work report
        if let Some(old_wr) = Self::work_reports(&anchor) {
            old_used = old_wr.used;
            old_free = old_wr.free;
            old_reported_files_size = old_wr.reported_files_size;
        }

        // 4. Construct work report
        let used = old_used.saturating_add(added_files.iter().fold(0, |acc, (_, f_size, _)| acc + *f_size)).saturating_sub(deleted_files.iter().fold(0, |acc, (_, f_size, _)| acc + *f_size));
        let wr = WorkReport {
            report_slot,
            used,
            free: reported_srd_size,
            reported_files_size,
            reported_srd_root: reported_srd_root.clone(),
            reported_files_root: reported_files_root.clone()
        };

        // 5. Upsert work report
        WorkReports::insert(anchor, wr);

        // 6. Update workload
        let total_used = Self::used().saturating_sub(old_used as u128).saturating_add(used as u128);
        let total_free = Self::free().saturating_sub(old_free as u128).saturating_add(reported_srd_size as u128);
        let total_reported_files_size = Self::reported_files_size().saturating_sub(old_reported_files_size as u128).saturating_add(reported_files_size as u128);

        Used::put(total_used);
        Free::put(total_free);
        ReportedFilesSize::put(total_reported_files_size);
    }
/// This function will (maybe) update or insert a work report, in details:
/// 1. calculate used from reported files
/// 2. set `ReportedInSlot`
/// 3. update `Used` and `Free`
/// 4. call `Works::report_works` interface
This function will (maybe) update or insert a work report, in details:
1. calculate used from reported files
2.
This function will ( maybe ) update or insert a work report in details : 1 . calculate used from reported files 2 .
fn maybe_upsert_work_report(
        reporter: &T::AccountId,
        anchor: &TarsAnchor,
        reported_srd_size: u64,
        reported_files_size: u64,
        added_files: &Vec<(MerkleRoot, u64, u64)>,
        deleted_files: &Vec<(MerkleRoot, u64, u64)>,
        reported_srd_root: &MerkleRoot,
        reported_files_root: &MerkleRoot,
        report_slot: u64,
    ) {
        let mut old_used: u64 = 0;
        let mut old_free: u64 = 0;
        let mut old_reported_files_size: u64 = 0;
        // 1. Mark who has reported in this (report)slot
        ReportedInSlot::insert(&anchor, report_slot, true);
        // 2. Update sOrder and get changed size
        // loop added. if not exist, calculate used.
        // loop deleted, need to check each key whether we should delete it or not
        let added_files = Self::update_files(reporter, added_files, &anchor, true);
        let deleted_files = Self::update_files(reporter, deleted_files, &anchor, false);
        // 3. If contains work report
        if let Some(old_wr) = Self::work_reports(&anchor) {
            old_used = old_wr.used;
            old_free = old_wr.free;
            old_reported_files_size = old_wr.reported_files_size;
        }
        // 4. Construct work report
        let used = old_used.saturating_add(added_files.iter().fold(0, |acc, (_, f_size, _)| acc + *f_size)).saturating_sub(deleted_files.iter().fold(0, |acc, (_, f_size, _)| acc + *f_size));
        let wr = WorkReport {
            report_slot,
            used,
            free: reported_srd_size,
            reported_files_size,
            reported_srd_root: reported_srd_root.clone(),
            reported_files_root: reported_files_root.clone()
        };
        // 5. Upsert work report
        WorkReports::insert(anchor, wr);
        // 6. Update workload
        let total_used = Self::used().saturating_sub(old_used as u128).saturating_add(used as u128);
        let total_free = Self::free().saturating_sub(old_free as u128).saturating_add(reported_srd_size as u128);
        let total_reported_files_size = Self::reported_files_size().saturating_sub(old_reported_files_size as u128).saturating_add(reported_files_size as u128);
        Used::put(total_used);
        Free::put(total_free);
        ReportedFilesSize::put(total_reported_files_size);
    }
fn maybe_upsert_work_report ( reporter : & T :: AccountId , anchor : & TarsAnchor , reported_srd_size : u64 , reported_files_size : u64 , added_files : & Vec < ( MerkleRoot , u64 , u64 ) > , deleted_files : & Vec < ( MerkleRoot , u64 , u64 ) > , reported_srd_root : & MerkleRoot , reported_files_root : & MerkleRoot , report_slot : u64 , ) { let mut old_used : u64 = 0 ; let mut old_free : u64 = 0 ; let mut old_reported_files_size : u64 = 0 ; // 1. Mark who has reported in this (report)slot ReportedInSlot :: insert ( & anchor , report_slot , true ) ; // 2. Update sOrder and get changed size // loop added. if not exist, calculate used. // loop deleted, need to check each key whether we should delete it or not let added_files = Self :: update_files ( reporter , added_files , & anchor , true ) ; let deleted_files = Self :: update_files ( reporter , deleted_files , & anchor , false ) ; // 3. If contains work report if let Some ( old_wr ) = Self :: work_reports ( & anchor ) { old_used = old_wr . used ; old_free = old_wr . free ; old_reported_files_size = old_wr . reported_files_size ; } // 4. Construct work report let used = old_used . saturating_add ( added_files . iter ( ) . fold ( 0 , | acc , ( _ , f_size , _ ) | acc + * f_size ) ) . saturating_sub ( deleted_files . iter ( ) . fold ( 0 , | acc , ( _ , f_size , _ ) | acc + * f_size ) ) ; let wr = WorkReport { report_slot , used , free : reported_srd_size , reported_files_size , reported_srd_root : reported_srd_root . clone ( ) , reported_files_root : reported_files_root . clone ( ) } ; // 5. Upsert work report WorkReports :: insert ( anchor , wr ) ; // 6. Update workload let total_used = Self :: used ( ) . saturating_sub ( old_used as u128 ) . saturating_add ( used as u128 ) ; let total_free = Self :: free ( ) . saturating_sub ( old_free as u128 ) . saturating_add ( reported_srd_size as u128 ) ; let total_reported_files_size = Self :: reported_files_size ( ) . saturating_sub ( old_reported_files_size as u128 ) . saturating_add ( reported_files_size as u128 ) ; Used :: put ( total_used ) ; Free :: put ( total_free ) ; ReportedFilesSize :: put ( total_reported_files_size ) ; }
This function will (maybe) update or insert a work report, in details:
1. calculate used from reported files
2. set `ReportedInSlot`
3. update `Used` and `Free`
4. call `Works::report_works` interface
This function will ( maybe ) update or insert a work report in details : 1 . calculate used from reported files 2 . set ` ReportedInSlot ` 3 . update ` Used ` and ` Free ` 4 . call ` Works :: report_works ` interface
reporter
&T::AccountId
anchor
&TarsAnchor
reported_srd_size
u64
reported_files_size
u64
added_files
&Vec<(MerkleRoot, u64, u64)>
deleted_files
&Vec<(MerkleRoot, u64, u64)>
reported_srd_root
&MerkleRoot
reported_files_root
&MerkleRoot
report_slot
u64