From 1d7709ccc515823e6f87d77c95f8b629a32359bf Mon Sep 17 00:00:00 2001 From: Kyrylo Stepanov Date: Wed, 24 Jul 2024 18:46:47 +0300 Subject: [PATCH] fix bug when change delegate doesn't change deposit_entry.delegate field --- .../src/instructions/change_delegate.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/programs/voter-stake-registry/src/instructions/change_delegate.rs b/programs/voter-stake-registry/src/instructions/change_delegate.rs index 01c88b4a..67fb225e 100644 --- a/programs/voter-stake-registry/src/instructions/change_delegate.rs +++ b/programs/voter-stake-registry/src/instructions/change_delegate.rs @@ -63,10 +63,15 @@ pub struct ChangeDelegate<'info> { /// The old delegate will stop receiving rewards. /// It might be done once per five days. pub fn change_delegate(ctx: Context, deposit_entry_index: u8) -> Result<()> { + require!( + &ctx.accounts.voter.key() != &ctx.accounts.delegate_voter.key(), + VsrError::SameDelegate + ); + let registrar = &ctx.accounts.registrar.load()?; - let voter = &ctx.accounts.voter.load()?; + let voter = &mut ctx.accounts.voter.load_mut()?; let delegate_voter = &ctx.accounts.delegate_voter.load()?; - let target = voter.active_deposit(deposit_entry_index)?; + let target = voter.active_deposit_mut(deposit_entry_index)?; require!( delegate_voter.voter_authority != target.delegate, @@ -107,6 +112,8 @@ pub fn change_delegate(ctx: Context, deposit_entry_index: u8) -> VsrError::InvalidMining ); + target.delegate = delegate_voter.voter_authority; + let reward_pool = ctx.accounts.reward_pool.to_account_info(); let mining = ctx.accounts.deposit_mining.to_account_info(); let deposit_authority = ctx.accounts.registrar.to_account_info();