From 1eb631a8d70185e8e2094f605d6286885d3b5027 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Thu, 9 Jan 2025 10:59:50 -0800 Subject: [PATCH] Do not try to deserialize genesis end epoch info in Accounts --- .../delegation/extend_expiration_ts_v0.rs | 90 +++++++++++-------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs b/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs index 5203dc68c..173269285 100644 --- a/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs +++ b/programs/helium-sub-daos/src/instructions/delegation/extend_expiration_ts_v0.rs @@ -72,9 +72,7 @@ pub struct ExtendExpirationTsV0<'info> { )] pub closing_time_sub_dao_epoch_info: Box>, #[account( - init_if_needed, - payer = payer, - space = SubDaoEpochInfoV0::SIZE, + mut, seeds = [ "sub_dao_epoch_info".as_bytes(), sub_dao.key().as_ref(), @@ -91,7 +89,8 @@ pub struct ExtendExpirationTsV0<'info> { ], bump, )] - pub genesis_end_sub_dao_epoch_info: Box>, + /// CHECK: Verified when needed in the inner instr + pub genesis_end_sub_dao_epoch_info: UncheckedAccount<'info>, pub proxy_config: Box>, pub system_program: Program<'info, System>, } @@ -180,43 +179,56 @@ pub fn handler(ctx: Context) -> Result<()> { closing_time_sdei.exit(&id())?; } - // Always update genesis_end_sdei - ctx.accounts.genesis_end_sub_dao_epoch_info.reload()?; - let genesis_end_sdei = &mut ctx.accounts.genesis_end_sub_dao_epoch_info; - if genesis_end_sdei.epoch > epoch { - msg!( - "Subtracting vehnt info from genesis end sdei {:?}", - vehnt_info_old - ); - genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei - .vehnt_in_closing_positions - .checked_sub(vehnt_info_old.genesis_end_vehnt_correction) - .unwrap(); - genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei - .fall_rates_from_closing_positions - .checked_sub(vehnt_info_old.genesis_end_fall_rate_correction) - .unwrap(); - msg!( - "Post subtraction genesis end sdei {} {}", - genesis_end_sdei.vehnt_in_closing_positions, - genesis_end_sdei.fall_rates_from_closing_positions - ); + let genesis_end_is_closing = ctx.accounts.genesis_end_sub_dao_epoch_info.key() + == ctx.accounts.closing_time_sub_dao_epoch_info.key(); + if !ctx.accounts.genesis_end_sub_dao_epoch_info.data_len() == 0 { + let mut parsed: Account; + let genesis_end_sdei: &mut Account = if genesis_end_is_closing { + &mut ctx.accounts.closing_time_sub_dao_epoch_info + } else { + parsed = Account::try_from( + &ctx + .accounts + .genesis_end_sub_dao_epoch_info + .to_account_info(), + )?; + &mut parsed + }; + if genesis_end_sdei.epoch > epoch { + msg!( + "Subtracting vehnt info from genesis end sdei {:?}", + vehnt_info_old + ); + genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei + .vehnt_in_closing_positions + .checked_sub(vehnt_info_old.genesis_end_vehnt_correction) + .unwrap(); + genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei + .fall_rates_from_closing_positions + .checked_sub(vehnt_info_old.genesis_end_fall_rate_correction) + .unwrap(); + msg!( + "Post subtraction genesis end sdei {} {}", + genesis_end_sdei.vehnt_in_closing_positions, + genesis_end_sdei.fall_rates_from_closing_positions + ); - genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei - .vehnt_in_closing_positions - .checked_add(vehnt_info_new.genesis_end_vehnt_correction) - .unwrap(); - genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei - .fall_rates_from_closing_positions - .checked_add(vehnt_info_new.genesis_end_fall_rate_correction) - .unwrap(); - msg!( - "Post addition genesis end sdei {} {}", - genesis_end_sdei.vehnt_in_closing_positions, - genesis_end_sdei.fall_rates_from_closing_positions - ); + genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei + .vehnt_in_closing_positions + .checked_add(vehnt_info_new.genesis_end_vehnt_correction) + .unwrap(); + genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei + .fall_rates_from_closing_positions + .checked_add(vehnt_info_new.genesis_end_fall_rate_correction) + .unwrap(); + msg!( + "Post addition genesis end sdei {} {}", + genesis_end_sdei.vehnt_in_closing_positions, + genesis_end_sdei.fall_rates_from_closing_positions + ); - genesis_end_sdei.exit(&id())?; + genesis_end_sdei.exit(&id())?; + } } Ok(())