@@ -313,7 +313,10 @@ func (s *Staker) IncreaseStake(validator thor.Address, endorser thor.Address, am
313313 if val .Status == validation .StatusExit {
314314 return NewReverts ("validator exited" )
315315 }
316- if val .Status == validation .StatusActive && val .ExitBlock != nil {
316+ if val .Status != validation .StatusActive {
317+ return NewReverts ("can't increase stake while validator not active" )
318+ }
319+ if val .ExitBlock != nil {
317320 return NewReverts ("validator has signaled exit, cannot increase stake" )
318321 }
319322
@@ -327,10 +330,8 @@ func (s *Staker) IncreaseStake(validator thor.Address, endorser thor.Address, am
327330 return err
328331 }
329332
330- if val .Status == validation .StatusActive {
331- if err = s .validationService .AddToRenewalList (validator ); err != nil {
332- return err
333- }
333+ if err = s .validationService .AddToRenewalList (validator ); err != nil {
334+ return err
334335 }
335336
336337 // update global queued, use the initial multiplier
@@ -363,20 +364,14 @@ func (s *Staker) DecreaseStake(validator thor.Address, endorser thor.Address, am
363364 if val .Status == validation .StatusExit {
364365 return NewReverts ("validator exited" )
365366 }
366- if val .Status == validation .StatusActive && val .ExitBlock != nil {
367+ if val .Status != validation .StatusActive {
368+ return NewReverts ("can't decrease stake while validator not active" )
369+ }
370+ if val .ExitBlock != nil {
367371 return NewReverts ("validator has signaled exit, cannot decrease stake" )
368372 }
369373
370- var nextPeriodVET uint64
371- if val .Status == validation .StatusActive {
372- // We don't consider any increases, i.e., entry.QueuedVET. We only consider locked and current decreases.
373- // The reason is that validator can instantly withdraw QueuedVET at any time.
374- // We need to make sure the locked VET minus the sum of the current decreases is still above the minimum stake.
375- nextPeriodVET = val .LockedVET - val .PendingUnlockVET
376- }
377- if val .Status == validation .StatusQueued {
378- nextPeriodVET = val .QueuedVET
379- }
374+ nextPeriodVET := val .LockedVET - val .PendingUnlockVET
380375 if amount > nextPeriodVET {
381376 return NewReverts ("not enough locked stake" )
382377 }
@@ -389,22 +384,8 @@ func (s *Staker) DecreaseStake(validator thor.Address, endorser thor.Address, am
389384 return err
390385 }
391386
392- if val .Status == validation .StatusActive {
393- if err = s .validationService .AddToRenewalList (validator ); err != nil {
394- return err
395- }
396- }
397-
398- if val .Status == validation .StatusQueued {
399- // update global queued
400- if err = s .globalStatsService .RemoveQueued (amount ); err != nil {
401- return err
402- }
403-
404- // update global withdrawable
405- if err = s .globalStatsService .AddWithdrawable (amount ); err != nil {
406- return err
407- }
387+ if err = s .validationService .AddToRenewalList (validator ); err != nil {
388+ return err
408389 }
409390
410391 if err = s .ContractBalanceCheck (0 ); err != nil {
0 commit comments