@@ -111,51 +111,62 @@ pub async fn get_stake_summaries(
111111
112112 let mut summaries = vec ! [ ] ;
113113 for stake_account in & stake_accounts {
114- let summary = if let Some ( account) = stake_account {
115- // if this assert ever triggers, multistake or another account change has landed
116- // this function should be updated to use real stake account sizes
117- // we may be fetching hundreds of accounts here so memoize the rents
118- assert ! (
119- !account. data. is_empty( ) && account. data. len( ) != StakeStateV2 :: size_of( ) ,
120- "StakeStateV2 is no longer canonical, or StakeStateV2::size_of() is no longer 200."
121- ) ;
122-
123- match bincode:: deserialize :: < StakeStateV2 > ( & account. data ) {
124- // typical stake state. either activating or effective can be "pool stake"
125- Ok ( StakeStateV2 :: Stake ( _, Stake { delegation, .. } , _) ) => {
126- let stake = if delegation. activation_epoch <= current_epoch
127- && delegation. deactivation_epoch >= current_epoch
128- {
129- delegation. stake
130- } else {
131- 0
132- } ;
133-
134- StakeSummary {
135- stake,
114+ let summary = match stake_account {
115+ Some ( account) if !account. data . is_empty ( ) => {
116+ // if this assert ever triggers, multistake or another account change has landed.
117+ // this function should be updated to use real stake account sizes.
118+ // we may be fetching hundreds of accounts here so memoize the rents
119+ assert_eq ! (
120+ account. data. len( ) ,
121+ StakeStateV2 :: size_of( ) ,
122+ "StakeStateV2 is no longer canonical, or StakeStateV2::size_of() is no longer 200."
123+ ) ;
124+
125+ match bincode:: deserialize :: < StakeStateV2 > ( & account. data ) {
126+ // typical stake state. either activating or effective can be "pool stake"
127+ Ok ( StakeStateV2 :: Stake ( _, Stake { delegation, .. } , _) ) => {
128+ let stake = if delegation. activation_epoch <= current_epoch
129+ && delegation. deactivation_epoch >= current_epoch
130+ {
131+ delegation. stake
132+ } else {
133+ 0
134+ } ;
135+
136+ StakeSummary {
137+ stake,
138+ usable_lamports : account. lamports . saturating_sub ( rent_exempt_reserve) ,
139+ dedelegated : delegation. deactivation_epoch != u64:: MAX ,
140+ exists : true ,
141+ }
142+ }
143+ // impossible for main stake, routine for onramp
144+ Ok ( StakeStateV2 :: Initialized ( _) ) => StakeSummary {
145+ stake : 0 ,
136146 usable_lamports : account. lamports . saturating_sub ( rent_exempt_reserve) ,
137- dedelegated : delegation . deactivation_epoch != u64 :: MAX ,
147+ dedelegated : true ,
138148 exists : true ,
139- }
149+ } ,
150+ _ => unreachable ! ( ) ,
140151 }
141- // impossible for main stake, routine for onramp
142- Ok ( StakeStateV2 :: Initialized ( _) ) => StakeSummary {
143- stake : 0 ,
144- usable_lamports : account. lamports . saturating_sub ( rent_exempt_reserve) ,
145- dedelegated : true ,
146- exists : true ,
147- } ,
148- _ => unreachable ! ( ) ,
149152 }
150- } else {
151- // possible if onramp never created
152- StakeSummary {
153+ // extremely stupid edge case, someone sent lamports to an onramp that doesnt exist.
154+ // this is impossible for main stake because pool exists => stake exists
155+ Some ( account) => StakeSummary {
156+ stake : 0 ,
157+ usable_lamports : account. lamports ( ) ,
158+ dedelegated : true ,
159+ exists : false ,
160+ } ,
161+ // impossible for main stake, possible if onramp never created
162+ None => StakeSummary {
153163 stake : 0 ,
154164 usable_lamports : 0 ,
155165 dedelegated : true ,
156166 exists : false ,
157- }
167+ } ,
158168 } ;
169+
159170 summaries. push ( summary) ;
160171 }
161172
0 commit comments