@@ -121,6 +121,7 @@ impl Stakes {
121
121
account : & AccountSharedData ,
122
122
fix_stake_deactivate : bool ,
123
123
check_vote_init : bool ,
124
+ remove_delegation_on_inactive : bool ,
124
125
) -> Option < ArcVoteAccount > {
125
126
if solana_vote_program:: check_id ( & account. owner ) {
126
127
// unconditionally remove existing at first; there is no dependent calculated state for
@@ -187,7 +188,13 @@ impl Stakes {
187
188
}
188
189
}
189
190
190
- if account. lamports == 0 {
191
+ let remove_delegation = if remove_delegation_on_inactive {
192
+ delegation. is_none ( )
193
+ } else {
194
+ account. lamports == 0
195
+ } ;
196
+
197
+ if remove_delegation {
191
198
// when account is removed (lamports == 0), remove it from Stakes as well
192
199
// so that given `pubkey` can be used for any owner in the future, while not
193
200
// affecting Stakes.
@@ -306,8 +313,8 @@ pub mod tests {
306
313
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, mut stake_account) ) =
307
314
create_staked_node_accounts ( 10 ) ;
308
315
309
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
310
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
316
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
317
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
311
318
let stake = StakeState :: stake_from ( & stake_account) . unwrap ( ) ;
312
319
{
313
320
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -319,7 +326,7 @@ pub mod tests {
319
326
}
320
327
321
328
stake_account. lamports = 42 ;
322
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
329
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
323
330
{
324
331
let vote_accounts = stakes. vote_accounts ( ) ;
325
332
assert ! ( vote_accounts. get( & vote_pubkey) . is_some( ) ) ;
@@ -331,7 +338,7 @@ pub mod tests {
331
338
332
339
// activate more
333
340
let ( _stake_pubkey, mut stake_account) = create_stake_account ( 42 , & vote_pubkey) ;
334
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
341
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
335
342
let stake = StakeState :: stake_from ( & stake_account) . unwrap ( ) ;
336
343
{
337
344
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -343,7 +350,7 @@ pub mod tests {
343
350
}
344
351
345
352
stake_account. lamports = 0 ;
346
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
353
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
347
354
{
348
355
let vote_accounts = stakes. vote_accounts ( ) ;
349
356
assert ! ( vote_accounts. get( & vote_pubkey) . is_some( ) ) ;
@@ -361,14 +368,14 @@ pub mod tests {
361
368
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
362
369
create_staked_node_accounts ( 10 ) ;
363
370
364
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
365
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
371
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
372
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
366
373
367
374
let ( ( vote11_pubkey, vote11_account) , ( stake11_pubkey, stake11_account) ) =
368
375
create_staked_node_accounts ( 20 ) ;
369
376
370
- stakes. store ( & vote11_pubkey, & vote11_account, true , true ) ;
371
- stakes. store ( & stake11_pubkey, & stake11_account, true , true ) ;
377
+ stakes. store ( & vote11_pubkey, & vote11_account, true , true , true ) ;
378
+ stakes. store ( & stake11_pubkey, & stake11_account, true , true , true ) ;
372
379
373
380
let vote11_node_pubkey = VoteState :: from ( & vote11_account) . unwrap ( ) . node_pubkey ;
374
381
@@ -385,8 +392,8 @@ pub mod tests {
385
392
let ( ( vote_pubkey, mut vote_account) , ( stake_pubkey, stake_account) ) =
386
393
create_staked_node_accounts ( 10 ) ;
387
394
388
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
389
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
395
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
396
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
390
397
391
398
{
392
399
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -395,15 +402,15 @@ pub mod tests {
395
402
}
396
403
397
404
vote_account. lamports = 0 ;
398
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
405
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
399
406
400
407
{
401
408
let vote_accounts = stakes. vote_accounts ( ) ;
402
409
assert ! ( vote_accounts. get( & vote_pubkey) . is_none( ) ) ;
403
410
}
404
411
405
412
vote_account. lamports = 1 ;
406
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
413
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
407
414
408
415
{
409
416
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -414,7 +421,7 @@ pub mod tests {
414
421
// Vote account too big
415
422
let cache_data = vote_account. data ( ) . to_vec ( ) ;
416
423
vote_account. data . push ( 0 ) ;
417
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
424
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
418
425
419
426
{
420
427
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -425,15 +432,15 @@ pub mod tests {
425
432
let default_vote_state = VoteState :: default ( ) ;
426
433
let versioned = VoteStateVersions :: new_current ( default_vote_state) ;
427
434
VoteState :: to ( & versioned, & mut vote_account) . unwrap ( ) ;
428
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
435
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
429
436
430
437
{
431
438
let vote_accounts = stakes. vote_accounts ( ) ;
432
439
assert ! ( vote_accounts. get( & vote_pubkey) . is_none( ) ) ;
433
440
}
434
441
435
442
vote_account. set_data ( cache_data) ;
436
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
443
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
437
444
438
445
{
439
446
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -455,11 +462,11 @@ pub mod tests {
455
462
let ( ( vote_pubkey2, vote_account2) , ( _stake_pubkey2, stake_account2) ) =
456
463
create_staked_node_accounts ( 10 ) ;
457
464
458
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
459
- stakes. store ( & vote_pubkey2, & vote_account2, true , true ) ;
465
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
466
+ stakes. store ( & vote_pubkey2, & vote_account2, true , true , true ) ;
460
467
461
468
// delegates to vote_pubkey
462
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
469
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
463
470
464
471
let stake = StakeState :: stake_from ( & stake_account) . unwrap ( ) ;
465
472
@@ -475,7 +482,7 @@ pub mod tests {
475
482
}
476
483
477
484
// delegates to vote_pubkey2
478
- stakes. store ( & stake_pubkey, & stake_account2, true , true ) ;
485
+ stakes. store ( & stake_pubkey, & stake_account2, true , true , true ) ;
479
486
480
487
{
481
488
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -500,11 +507,11 @@ pub mod tests {
500
507
501
508
let ( stake_pubkey2, stake_account2) = create_stake_account ( 10 , & vote_pubkey) ;
502
509
503
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
510
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
504
511
505
512
// delegates to vote_pubkey
506
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
507
- stakes. store ( & stake_pubkey2, & stake_account2, true , true ) ;
513
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
514
+ stakes. store ( & stake_pubkey2, & stake_account2, true , true , true ) ;
508
515
509
516
{
510
517
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -519,8 +526,8 @@ pub mod tests {
519
526
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
520
527
create_staked_node_accounts ( 10 ) ;
521
528
522
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
523
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
529
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
530
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
524
531
let stake = StakeState :: stake_from ( & stake_account) . unwrap ( ) ;
525
532
526
533
{
@@ -550,8 +557,8 @@ pub mod tests {
550
557
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
551
558
create_staked_node_accounts ( 10 ) ;
552
559
553
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
554
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
560
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
561
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
555
562
556
563
{
557
564
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -565,6 +572,7 @@ pub mod tests {
565
572
& AccountSharedData :: new ( 1 , 0 , & solana_stake_program:: id ( ) ) ,
566
573
true ,
567
574
true ,
575
+ true ,
568
576
) ;
569
577
{
570
578
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -594,8 +602,8 @@ pub mod tests {
594
602
let genesis_epoch = 0 ;
595
603
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
596
604
create_warming_staked_node_accounts ( 10 , genesis_epoch) ;
597
- stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
598
- stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
605
+ stakes. store ( & vote_pubkey, & vote_account, true , true , true ) ;
606
+ stakes. store ( & stake_pubkey, & stake_account, true , true , true ) ;
599
607
600
608
assert_eq ! ( stakes. vote_balance_and_staked( ) , 11 ) ;
601
609
assert_eq ! ( stakes. vote_balance_and_warmed_staked( ) , 1 ) ;
0 commit comments