change add stake filtering algo
This commit is contained in:
parent
f282b5e282
commit
e108ffae2e
|
@ -298,7 +298,7 @@ async fn run_loop<F: Interceptor>(mut client: GeyserGrpcClient<F>) -> anyhow::Re
|
||||||
match account.owner {
|
match account.owner {
|
||||||
solana_sdk::stake::program::ID => {
|
solana_sdk::stake::program::ID => {
|
||||||
log::info!("Geyser Notif stake account:{}", account);
|
log::info!("Geyser Notif stake account:{}", account);
|
||||||
if let Err(err) = stakestore.notify_change_stake(
|
if let Err(err) = stakestore.notify_stake_change(
|
||||||
account,
|
account,
|
||||||
current_epoch_state.current_epoch_end_slot(),
|
current_epoch_state.current_epoch_end_slot(),
|
||||||
current_epoch_state.current_epoch.epoch,
|
current_epoch_state.current_epoch.epoch,
|
||||||
|
|
|
@ -37,7 +37,6 @@ fn stake_map_notify_stake(
|
||||||
map: &mut StakeMap,
|
map: &mut StakeMap,
|
||||||
stake_account: Pubkey,
|
stake_account: Pubkey,
|
||||||
stake: StoredStake,
|
stake: StoredStake,
|
||||||
//TODO manage already deractivated stake.
|
|
||||||
current_epoch: u64,
|
current_epoch: u64,
|
||||||
) {
|
) {
|
||||||
//don't add stake that are already desactivated.
|
//don't add stake that are already desactivated.
|
||||||
|
@ -46,23 +45,21 @@ fn stake_map_notify_stake(
|
||||||
// if stake.stake.deactivation_epoch < current_epoch {
|
// if stake.stake.deactivation_epoch < current_epoch {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
log::trace!("stake_map_notify_stake stake:{stake:?}");
|
log::info!("stake_map_notify_stake stake:{stake:?}");
|
||||||
let remove = match map.entry(stake_account) {
|
match map.entry(stake_account) {
|
||||||
// If value already exists, then increment it by one
|
// If value already exists, then increment it by one
|
||||||
std::collections::hash_map::Entry::Occupied(occupied) => {
|
std::collections::hash_map::Entry::Occupied(occupied) => {
|
||||||
let strstake = occupied.into_mut(); // <-- get mut reference to existing value
|
let strstake = occupied.into_mut(); // <-- get mut reference to existing value
|
||||||
//doesn't erase new state with an old one. Can arrive during bootstrapping.
|
//doesn't erase new state with an old one. Can arrive during bootstrapping.
|
||||||
//several instructions can be done in the same slot.
|
//several instructions can be done in the same slot.
|
||||||
if strstake.last_update_slot <= stake.last_update_slot {
|
if strstake.last_update_slot <= stake.last_update_slot {
|
||||||
if stake.is_inserted(current_epoch) {
|
if stake.is_removed(current_epoch) {
|
||||||
|
log::info!("stake_map_notify_stake Stake store insert stake: {stake_account} stake:{stake:?}");
|
||||||
|
map.remove(&stake_account);
|
||||||
|
} else {
|
||||||
log::info!("stake_map_notify_stake Stake store updated stake: {stake_account} old_stake:{strstake:?} stake:{stake:?}");
|
log::info!("stake_map_notify_stake Stake store updated stake: {stake_account} old_stake:{strstake:?} stake:{stake:?}");
|
||||||
*strstake = stake;
|
*strstake = stake;
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If value doesn't exist yet, then insert a new value of 1
|
// If value doesn't exist yet, then insert a new value of 1
|
||||||
|
@ -71,13 +68,8 @@ fn stake_map_notify_stake(
|
||||||
log::info!("stake_map_notify_stake Stake store insert stake: {stake_account} stake:{stake:?}");
|
log::info!("stake_map_notify_stake Stake store insert stake: {stake_account} stake:{stake:?}");
|
||||||
vacant.insert(stake);
|
vacant.insert(stake);
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if remove {
|
|
||||||
log::info!("stake_map_notify_stake Stake store remove stake: {stake_account}");
|
|
||||||
map.remove(&stake_account);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
@ -101,24 +93,15 @@ pub struct StoredStake {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StoredStake {
|
impl StoredStake {
|
||||||
|
fn is_removed(&self, current_epoch: u64) -> bool {
|
||||||
|
self.stake.activation_epoch != crate::leader_schedule::MAX_EPOCH_VALUE
|
||||||
|
&& self.stake.deactivation_epoch < current_epoch
|
||||||
|
}
|
||||||
fn is_inserted(&self, current_epoch: u64) -> bool {
|
fn is_inserted(&self, current_epoch: u64) -> bool {
|
||||||
if self.stake.deactivation_epoch == crate::leader_schedule::MAX_EPOCH_VALUE {
|
self.stake.activation_epoch == crate::leader_schedule::MAX_EPOCH_VALUE
|
||||||
true
|
|| self.stake.deactivation_epoch >= current_epoch
|
||||||
} else if self.stake.activation_epoch == crate::leader_schedule::MAX_EPOCH_VALUE {
|
|
||||||
//some stake has activeate_epock = max epoch are taken into account even if deactivation_epoch is past.
|
|
||||||
log::info!(
|
|
||||||
"Stake with stake.activation_epoch == MAX_EPOCH_VALUE, account:{}",
|
|
||||||
self.pubkey
|
|
||||||
);
|
|
||||||
true
|
|
||||||
} else if self.stake.deactivation_epoch < current_epoch {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct StakeStore {
|
pub struct StakeStore {
|
||||||
stakes: StakeMap,
|
stakes: StakeMap,
|
||||||
|
@ -143,7 +126,7 @@ impl StakeStore {
|
||||||
self.stakes.clone()
|
self.stakes.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notify_change_stake(
|
pub fn notify_stake_change(
|
||||||
&mut self,
|
&mut self,
|
||||||
new_account: AccountPretty,
|
new_account: AccountPretty,
|
||||||
current_end_epoch_slot: Slot,
|
current_end_epoch_slot: Slot,
|
||||||
|
@ -172,6 +155,11 @@ impl StakeStore {
|
||||||
}),
|
}),
|
||||||
true => self.notify_stake(new_account.pubkey, ststake, current_epoch),
|
true => self.notify_stake(new_account.pubkey, ststake, current_epoch),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::warn!(
|
||||||
|
"notify_stake_change {} No delegated stake in account data",
|
||||||
|
new_account.pubkey
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue