-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes: rebalance decrease amount calculation, validator_lamport_balance initialization, tweaks to keeper #72
Changes from 6 commits
d00be0f
604189d
1e703e2
b92af33
a56426e
bfae2bf
ca7003b
f4132b8
506e27d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{ | ||
constants::{LAMPORT_BALANCE_DEFAULT, MAX_VALIDATORS}, | ||
state::*, | ||
utils::get_config_admin, | ||
}; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct ResetValidatorLamportBalances<'info> { | ||
#[account( | ||
mut, | ||
seeds = [StewardStateAccount::SEED, config.key().as_ref()], | ||
bump | ||
)] | ||
pub steward_state: AccountLoader<'info, StewardStateAccount>, | ||
|
||
pub config: AccountLoader<'info, Config>, | ||
|
||
#[account(address = get_config_admin(&config)?)] | ||
pub authority: Signer<'info>, | ||
} | ||
|
||
pub fn handler(ctx: Context<ResetValidatorLamportBalances>) -> Result<()> { | ||
let state_account = &mut ctx.accounts.steward_state.load_mut()?; | ||
|
||
state_account.state.validator_lamport_balances = [LAMPORT_BALANCE_DEFAULT; MAX_VALIDATORS]; | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use std::fmt::Display; | |
|
||
use crate::{ | ||
bitmask::BitMask, | ||
constants::{MAX_VALIDATORS, SORTED_INDEX_DEFAULT}, | ||
constants::{LAMPORT_BALANCE_DEFAULT, MAX_VALIDATORS, SORTED_INDEX_DEFAULT}, | ||
delegation::{ | ||
decrease_stake_calculation, increase_stake_calculation, RebalanceType, UnstakeState, | ||
}, | ||
|
@@ -859,12 +859,6 @@ impl StewardState { | |
.checked_add(stake_rent) | ||
.ok_or(StewardError::ArithmeticError)?; | ||
|
||
msg!("Reserve lamports before adjustment: {}", reserve_lamports); | ||
msg!( | ||
"Stake pool lamports before adjustment: {}", | ||
stake_pool_lamports | ||
); | ||
|
||
// Maximum increase amount is the total lamports in the reserve stake account minus (num_validators + 1) * stake_rent, which covers rent for all validators plus the transient rent | ||
let all_accounts_needed_reserve_for_rent = validator_list | ||
.len() | ||
|
@@ -907,6 +901,11 @@ impl StewardState { | |
In all cases where the current_lamports is now below the target or internal balance, we update the internal balance. | ||
Otherwise, keep the internal balance the same to ensure we still see the stake deposit delta, until it can be unstaked. | ||
*/ | ||
|
||
if self.validator_lamport_balances[index] == LAMPORT_BALANCE_DEFAULT { | ||
self.validator_lamport_balances[index] = current_lamports; | ||
} | ||
|
||
self.validator_lamport_balances[index] = match ( | ||
current_lamports < self.validator_lamport_balances[index], | ||
current_lamports < target_lamports, | ||
|
@@ -947,6 +946,7 @@ impl StewardState { | |
self, | ||
index, | ||
unstake_state, | ||
current_lamports, | ||
stake_pool_lamports, | ||
validator_list, | ||
minimum_delegation, | ||
|
@@ -967,15 +967,6 @@ impl StewardState { | |
RebalanceType::None | ||
}; | ||
|
||
msg!("Reserve lamports after adjustment: {}", reserve_lamports); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too much CU? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was causing local tests to fail since it was calling msg! outside of context, + think we're okay to remove these now since we have the emits There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10-4 |
||
msg!( | ||
"Stake pool lamports after adjustment: {}", | ||
stake_pool_lamports | ||
); | ||
msg!("Rebalance Type: {:?}", rebalance); | ||
msg!("Current Lamports: {}", current_lamports); | ||
msg!("Target Lamports: {}", target_lamports); | ||
|
||
// Update internal state based on rebalance | ||
match rebalance { | ||
RebalanceType::Decrease(DecreaseComponents { | ||
|
@@ -984,8 +975,11 @@ impl StewardState { | |
stake_deposit_unstake_lamports, | ||
total_unstake_lamports, | ||
}) => { | ||
self.validator_lamport_balances[index] = self.validator_lamport_balances[index] | ||
.saturating_sub(total_unstake_lamports); | ||
if self.validator_lamport_balances[index] != LAMPORT_BALANCE_DEFAULT { | ||
self.validator_lamport_balances[index] = self.validator_lamport_balances | ||
[index] | ||
.saturating_sub(total_unstake_lamports); | ||
} | ||
|
||
self.scoring_unstake_total = self | ||
.scoring_unstake_total | ||
|
@@ -1026,9 +1020,12 @@ impl StewardState { | |
} | ||
} | ||
RebalanceType::Increase(amount) => { | ||
self.validator_lamport_balances[index] = self.validator_lamport_balances[index] | ||
.checked_add(amount) | ||
.ok_or(StewardError::ArithmeticError)?; | ||
if self.validator_lamport_balances[index] != LAMPORT_BALANCE_DEFAULT { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want this same check for Decrease? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, good catch |
||
self.validator_lamport_balances[index] = self.validator_lamport_balances | ||
[index] | ||
.checked_add(amount) | ||
.ok_or(StewardError::ArithmeticError)?; | ||
} | ||
} | ||
RebalanceType::None => {} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want the same check for increase_stake_calculation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the increase_stake_calculation algo here doesn't interact with this field so we're safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10-4