Skip to content

Commit

Permalink
fix bug when change delegate doesn't change deposit_entry.delegate field
Browse files Browse the repository at this point in the history
  • Loading branch information
kstepanovdev committed Jul 24, 2024
1 parent 73be31e commit 1d7709c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChangeDelegate>, deposit_entry_index: u8) -> Result<()> {
require!(
&ctx.accounts.voter.key() != &ctx.accounts.delegate_voter.key(),

Check failure on line 67 in programs/voter-stake-registry/src/instructions/change_delegate.rs

View workflow job for this annotation

GitHub Actions / Linter

needlessly taken reference of both operands
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,
Expand Down Expand Up @@ -107,6 +112,8 @@ pub fn change_delegate(ctx: Context<ChangeDelegate>, 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();
Expand Down

0 comments on commit 1d7709c

Please sign in to comment.