light_registry/protocol_config/
update.rs

1use anchor_lang::prelude::*;
2
3use super::state::{ProtocolConfig, ProtocolConfigPda};
4use crate::errors::RegistryError;
5
6#[derive(Accounts)]
7pub struct UpdateProtocolConfig<'info> {
8    pub fee_payer: Signer<'info>,
9    pub authority: Signer<'info>,
10    /// CHECK: authority is protocol config authority.
11    #[account(mut, has_one=authority)]
12    pub protocol_config_pda: Account<'info, ProtocolConfigPda>,
13    /// CHECK: is signer to reduce risk of updating with a wrong authority.
14    pub new_authority: Option<Signer<'info>>,
15}
16
17pub fn check_protocol_config(protocol_config: ProtocolConfig) -> Result<()> {
18    if protocol_config.min_weight == 0 {
19        msg!("Min weight cannot be zero.");
20        return err!(RegistryError::InvalidConfigUpdate);
21    }
22    if protocol_config.active_phase_length < protocol_config.registration_phase_length {
23        msg!(
24            "Active phase length must be greater or equal than registration phase length. {} {}",
25            protocol_config.active_phase_length,
26            protocol_config.registration_phase_length
27        );
28        return err!(RegistryError::InvalidConfigUpdate);
29    }
30    if protocol_config.active_phase_length < protocol_config.report_work_phase_length {
31        msg!(
32            "Active phase length must be greater or equal than report work phase length. {} {}",
33            protocol_config.active_phase_length,
34            protocol_config.report_work_phase_length
35        );
36        return err!(RegistryError::InvalidConfigUpdate);
37    }
38    if protocol_config.active_phase_length < protocol_config.slot_length {
39        msg!(
40            "Active phase length is less than slot length, active phase length {} < slot length {}. (Active phase length must be greater than slot length.)",
41            protocol_config.active_phase_length,
42            protocol_config.slot_length
43        );
44        return err!(RegistryError::InvalidConfigUpdate);
45    }
46    Ok(())
47}