@@ -123,6 +123,7 @@ impl Stakes {
123
123
pubkey : & Pubkey ,
124
124
account : & AccountSharedData ,
125
125
check_vote_init : bool ,
126
+ remove_delegation_on_inactive : bool ,
126
127
) -> Option < VoteAccount > {
127
128
if solana_vote_program:: check_id ( account. owner ( ) ) {
128
129
// unconditionally remove existing at first; there is no dependent calculated state for
@@ -178,7 +179,13 @@ impl Stakes {
178
179
}
179
180
}
180
181
181
- if account. lamports ( ) == 0 {
182
+ let remove_delegation = if remove_delegation_on_inactive {
183
+ delegation. is_none ( )
184
+ } else {
185
+ account. lamports ( ) == 0
186
+ } ;
187
+
188
+ if remove_delegation {
182
189
// when account is removed (lamports == 0), remove it from Stakes as well
183
190
// so that given `pubkey` can be used for any owner in the future, while not
184
191
// affecting Stakes.
@@ -297,8 +304,8 @@ pub mod tests {
297
304
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, mut stake_account) ) =
298
305
create_staked_node_accounts ( 10 ) ;
299
306
300
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
301
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
307
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
308
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
302
309
let stake = stake_state:: stake_from ( & stake_account) . unwrap ( ) ;
303
310
{
304
311
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -310,7 +317,7 @@ pub mod tests {
310
317
}
311
318
312
319
stake_account. set_lamports ( 42 ) ;
313
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
320
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
314
321
{
315
322
let vote_accounts = stakes. vote_accounts ( ) ;
316
323
assert ! ( vote_accounts. get( & vote_pubkey) . is_some( ) ) ;
@@ -322,7 +329,7 @@ pub mod tests {
322
329
323
330
// activate more
324
331
let ( _stake_pubkey, mut stake_account) = create_stake_account ( 42 , & vote_pubkey) ;
325
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
332
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
326
333
let stake = stake_state:: stake_from ( & stake_account) . unwrap ( ) ;
327
334
{
328
335
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -334,7 +341,7 @@ pub mod tests {
334
341
}
335
342
336
343
stake_account. set_lamports ( 0 ) ;
337
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
344
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
338
345
{
339
346
let vote_accounts = stakes. vote_accounts ( ) ;
340
347
assert ! ( vote_accounts. get( & vote_pubkey) . is_some( ) ) ;
@@ -352,14 +359,14 @@ pub mod tests {
352
359
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
353
360
create_staked_node_accounts ( 10 ) ;
354
361
355
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
356
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
362
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
363
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
357
364
358
365
let ( ( vote11_pubkey, vote11_account) , ( stake11_pubkey, stake11_account) ) =
359
366
create_staked_node_accounts ( 20 ) ;
360
367
361
- stakes. store ( & vote11_pubkey, & vote11_account, true ) ;
362
- stakes. store ( & stake11_pubkey, & stake11_account, true ) ;
368
+ stakes. store ( & vote11_pubkey, & vote11_account, true , true ) ;
369
+ stakes. store ( & stake11_pubkey, & stake11_account, true , true ) ;
363
370
364
371
let vote11_node_pubkey = VoteState :: from ( & vote11_account) . unwrap ( ) . node_pubkey ;
365
372
@@ -376,8 +383,8 @@ pub mod tests {
376
383
let ( ( vote_pubkey, mut vote_account) , ( stake_pubkey, stake_account) ) =
377
384
create_staked_node_accounts ( 10 ) ;
378
385
379
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
380
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
386
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
387
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
381
388
382
389
{
383
390
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -386,15 +393,15 @@ pub mod tests {
386
393
}
387
394
388
395
vote_account. set_lamports ( 0 ) ;
389
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
396
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
390
397
391
398
{
392
399
let vote_accounts = stakes. vote_accounts ( ) ;
393
400
assert ! ( vote_accounts. get( & vote_pubkey) . is_none( ) ) ;
394
401
}
395
402
396
403
vote_account. set_lamports ( 1 ) ;
397
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
404
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
398
405
399
406
{
400
407
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -407,7 +414,7 @@ pub mod tests {
407
414
let mut pushed = vote_account. data ( ) . to_vec ( ) ;
408
415
pushed. push ( 0 ) ;
409
416
vote_account. set_data ( pushed) ;
410
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
417
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
411
418
412
419
{
413
420
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -418,15 +425,15 @@ pub mod tests {
418
425
let default_vote_state = VoteState :: default ( ) ;
419
426
let versioned = VoteStateVersions :: new_current ( default_vote_state) ;
420
427
VoteState :: to ( & versioned, & mut vote_account) . unwrap ( ) ;
421
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
428
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
422
429
423
430
{
424
431
let vote_accounts = stakes. vote_accounts ( ) ;
425
432
assert ! ( vote_accounts. get( & vote_pubkey) . is_none( ) ) ;
426
433
}
427
434
428
435
vote_account. set_data ( cache_data) ;
429
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
436
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
430
437
431
438
{
432
439
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -448,11 +455,11 @@ pub mod tests {
448
455
let ( ( vote_pubkey2, vote_account2) , ( _stake_pubkey2, stake_account2) ) =
449
456
create_staked_node_accounts ( 10 ) ;
450
457
451
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
452
- stakes. store ( & vote_pubkey2, & vote_account2, true ) ;
458
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
459
+ stakes. store ( & vote_pubkey2, & vote_account2, true , true ) ;
453
460
454
461
// delegates to vote_pubkey
455
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
462
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
456
463
457
464
let stake = stake_state:: stake_from ( & stake_account) . unwrap ( ) ;
458
465
@@ -468,7 +475,7 @@ pub mod tests {
468
475
}
469
476
470
477
// delegates to vote_pubkey2
471
- stakes. store ( & stake_pubkey, & stake_account2, true ) ;
478
+ stakes. store ( & stake_pubkey, & stake_account2, true , true ) ;
472
479
473
480
{
474
481
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -493,11 +500,11 @@ pub mod tests {
493
500
494
501
let ( stake_pubkey2, stake_account2) = create_stake_account ( 10 , & vote_pubkey) ;
495
502
496
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
503
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
497
504
498
505
// delegates to vote_pubkey
499
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
500
- stakes. store ( & stake_pubkey2, & stake_account2, true ) ;
506
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
507
+ stakes. store ( & stake_pubkey2, & stake_account2, true , true ) ;
501
508
502
509
{
503
510
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -512,8 +519,8 @@ pub mod tests {
512
519
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
513
520
create_staked_node_accounts ( 10 ) ;
514
521
515
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
516
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
522
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
523
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
517
524
let stake = stake_state:: stake_from ( & stake_account) . unwrap ( ) ;
518
525
519
526
{
@@ -543,8 +550,8 @@ pub mod tests {
543
550
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
544
551
create_staked_node_accounts ( 10 ) ;
545
552
546
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
547
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
553
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
554
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
548
555
549
556
{
550
557
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -557,6 +564,7 @@ pub mod tests {
557
564
& stake_pubkey,
558
565
& AccountSharedData :: new ( 1 , 0 , & stake:: program:: id ( ) ) ,
559
566
true ,
567
+ true ,
560
568
) ;
561
569
{
562
570
let vote_accounts = stakes. vote_accounts ( ) ;
@@ -586,8 +594,8 @@ pub mod tests {
586
594
let genesis_epoch = 0 ;
587
595
let ( ( vote_pubkey, vote_account) , ( stake_pubkey, stake_account) ) =
588
596
create_warming_staked_node_accounts ( 10 , genesis_epoch) ;
589
- stakes. store ( & vote_pubkey, & vote_account, true ) ;
590
- stakes. store ( & stake_pubkey, & stake_account, true ) ;
597
+ stakes. store ( & vote_pubkey, & vote_account, true , true ) ;
598
+ stakes. store ( & stake_pubkey, & stake_account, true , true ) ;
591
599
592
600
assert_eq ! ( stakes. vote_balance_and_staked( ) , 11 ) ;
593
601
assert_eq ! ( stakes. vote_balance_and_warmed_staked( ) , 1 ) ;
0 commit comments