light_registry/epoch/
report_work.rs

1use anchor_lang::prelude::*;
2
3use super::register_epoch::{EpochPda, ForesterEpochPda};
4use crate::errors::RegistryError;
5/// Report work:
6/// - work is reported so that relative performance of foresters can be assessed
7/// 1. Check that we are in the report work phase
8/// 2. Check that forester has registered for the epoch
9/// 3. Check that forester has not already reported work
10/// 4. Add work to total work
11pub fn report_work_instruction(
12    forester_epoch_pda: &mut ForesterEpochPda,
13    epoch_pda: &mut EpochPda,
14    current_slot: u64,
15) -> Result<()> {
16    epoch_pda
17        .protocol_config
18        .is_report_work_phase(current_slot, epoch_pda.epoch)?;
19
20    if forester_epoch_pda.epoch != epoch_pda.epoch {
21        return err!(RegistryError::InvalidEpochAccount);
22    }
23    if forester_epoch_pda.has_reported_work {
24        return err!(RegistryError::ForesterAlreadyRegistered);
25    }
26
27    forester_epoch_pda.has_reported_work = true;
28    epoch_pda.total_work += forester_epoch_pda.work_counter;
29    Ok(())
30}
31
32#[derive(Accounts)]
33pub struct ReportWork<'info> {
34    authority: Signer<'info>,
35    #[account(mut, has_one = authority)]
36    pub forester_epoch_pda: Account<'info, ForesterEpochPda>,
37    #[account(mut)]
38    pub epoch_pda: Account<'info, EpochPda>,
39}