6
6
crate :: {
7
7
forward_packet_batches_by_accounts:: ForwardPacketBatchesByAccounts ,
8
8
immutable_deserialized_packet:: ImmutableDeserializedPacket ,
9
- latest_unprocessed_votes:: { self , LatestUnprocessedVotes , VoteSource } ,
9
+ latest_unprocessed_votes:: { LatestUnprocessedVotes , VoteSource } ,
10
10
leader_slot_banking_stage_metrics:: { LeaderSlotMetricsTracker , ProcessTransactionsSummary } ,
11
11
leader_slot_banking_stage_timing_metrics:: {
12
12
LeaderExecuteAndCommitTimings , RecordTransactionsTimings ,
15
15
sigverify:: SigverifyTracerPacketStats ,
16
16
tracer_packet_stats:: TracerPacketStats ,
17
17
unprocessed_packet_batches:: { self , * } ,
18
- unprocessed_transaction_storage:: {
19
- InsertPacketBatchesSummary , ThreadType , UnprocessedTransactionStorage ,
20
- } ,
18
+ unprocessed_transaction_storage:: { ThreadType , UnprocessedTransactionStorage } ,
21
19
} ,
22
20
core:: iter:: repeat,
23
21
crossbeam_channel:: {
@@ -385,9 +383,9 @@ pub enum ForwardOption {
385
383
386
384
#[ derive( Debug , Default ) ]
387
385
pub struct FilterForwardingResults {
388
- total_forwardable_packets : usize ,
389
- total_tracer_packets_in_buffer : usize ,
390
- total_forwardable_tracer_packets : usize ,
386
+ pub ( crate ) total_forwardable_packets : usize ,
387
+ pub ( crate ) total_tracer_packets_in_buffer : usize ,
388
+ pub ( crate ) total_forwardable_tracer_packets : usize ,
391
389
}
392
390
393
391
impl BankingStage {
@@ -447,9 +445,10 @@ impl BankingStage {
447
445
TOTAL_BUFFERED_PACKETS / ( ( num_threads - NUM_VOTE_PROCESSING_THREADS ) as usize ) ;
448
446
// Keeps track of extraneous vote transactions for the vote threads
449
447
let latest_unprocessed_votes = Arc :: new ( LatestUnprocessedVotes :: new ( ) ) ;
450
- let bank = poh_recorder. read ( ) . unwrap ( ) . bank ( ) ;
451
- let split_voting_threads = bank
452
- . map ( |bank| {
448
+ let should_split_voting_threads = bank_forks
449
+ . read ( )
450
+ . map ( |bank_forks| {
451
+ let bank = bank_forks. root_bank ( ) ;
453
452
bank. feature_set
454
453
. is_active ( & allow_votes_to_directly_update_vote_state:: id ( ) )
455
454
&& bank. feature_set . is_active ( & split_banking_threads:: id ( ) )
@@ -465,7 +464,7 @@ impl BankingStage {
465
464
(
466
465
verified_vote_receiver. clone ( ) ,
467
466
(
468
- split_voting_threads ,
467
+ should_split_voting_threads ,
469
468
Some ( latest_unprocessed_votes. clone ( ) ) ,
470
469
ThreadType :: Voting ( VoteSource :: Gossip ) ,
471
470
) ,
@@ -474,14 +473,14 @@ impl BankingStage {
474
473
1 => (
475
474
tpu_verified_vote_receiver. clone ( ) ,
476
475
(
477
- split_voting_threads ,
476
+ should_split_voting_threads ,
478
477
Some ( latest_unprocessed_votes. clone ( ) ) ,
479
478
ThreadType :: Voting ( VoteSource :: Tpu ) ,
480
479
) ,
481
480
) ,
482
481
_ => (
483
482
verified_receiver. clone ( ) ,
484
- ( split_voting_threads , None , ThreadType :: Transactions ) ,
483
+ ( should_split_voting_threads , None , ThreadType :: Transactions ) ,
485
484
) ,
486
485
} ;
487
486
@@ -681,15 +680,15 @@ impl BankingStage {
681
680
poh_recorder : & Arc < RwLock < PohRecorder > > ,
682
681
slot_metrics_tracker : & mut LeaderSlotMetricsTracker ,
683
682
recorder : & TransactionRecorder ,
684
- transaction_status_sender : Option < TransactionStatusSender > ,
683
+ transaction_status_sender : & Option < TransactionStatusSender > ,
685
684
gossip_vote_sender : & ReplayVoteSender ,
686
685
banking_stage_stats : & BankingStageStats ,
687
686
qos_service : & QosService ,
688
687
log_messages_bytes_limit : Option < usize > ,
689
688
consumed_buffered_packets_count : & mut usize ,
690
689
rebuffered_packet_count : & mut usize ,
691
690
reached_end_of_slot : & mut bool ,
692
- test_fn : Option < impl Fn ( ) > ,
691
+ test_fn : & Option < impl Fn ( ) > ,
693
692
packets_to_process : & Vec < Rc < ImmutableDeserializedPacket > > ,
694
693
) -> Option < Vec < usize > > {
695
694
// TODO: Right now we iterate through buffer and try the highest weighted transaction once
@@ -714,7 +713,7 @@ impl BankingStage {
714
713
& bank_creation_time,
715
714
recorder,
716
715
packets_to_process. iter( ) . map( |p| & * * p) ,
717
- transaction_status_sender. clone ( ) ,
716
+ transaction_status_sender,
718
717
gossip_vote_sender,
719
718
banking_stage_stats,
720
719
qos_service,
@@ -755,15 +754,15 @@ impl BankingStage {
755
754
// Out of the buffered packets just retried, collect any still unprocessed
756
755
// transactions in this batch for forwarding
757
756
* rebuffered_packet_count += retryable_transaction_indexes. len ( ) ;
758
- if let Some ( test_fn) = & test_fn {
757
+ if let Some ( test_fn) = test_fn {
759
758
test_fn ( ) ;
760
759
}
761
760
762
761
slot_metrics_tracker
763
762
. increment_retryable_packets_count ( retryable_transaction_indexes. len ( ) as u64 ) ;
764
763
765
764
Some ( retryable_transaction_indexes)
766
- } else if reached_end_of_slot {
765
+ } else if * reached_end_of_slot {
767
766
None
768
767
} else {
769
768
// mark as end-of-slot to avoid aggressively lock poh for the remaining for
@@ -806,15 +805,15 @@ impl BankingStage {
806
805
poh_recorder,
807
806
slot_metrics_tracker,
808
807
recorder,
809
- transaction_status_sender,
808
+ & transaction_status_sender,
810
809
gossip_vote_sender,
811
810
banking_stage_stats,
812
811
qos_service,
813
812
log_messages_bytes_limit,
814
813
& mut consumed_buffered_packets_count,
815
814
& mut rebuffered_packet_count,
816
815
& mut reached_end_of_slot,
817
- test_fn,
816
+ & test_fn,
818
817
packets_to_process,
819
818
)
820
819
} ,
@@ -1135,27 +1134,19 @@ impl BankingStage {
1135
1134
vote_source,
1136
1135
)
1137
1136
}
1138
- ( _, _ , thread_type) => UnprocessedTransactionStorage :: new_transaction_storage (
1137
+ ( _, hot_swap , thread_type) => UnprocessedTransactionStorage :: new_transaction_storage (
1139
1138
UnprocessedPacketBatches :: with_capacity ( batch_limit) ,
1140
1139
thread_type,
1140
+ hot_swap,
1141
1141
) ,
1142
1142
} ;
1143
1143
1144
1144
loop {
1145
1145
// Hotswap
1146
- unprocessed_transaction_storage = match unprocessed_transaction_storage {
1147
- UnprocessedTransactionStorage :: TransactionStorage ( transaction_storage) => {
1148
- if let ThreadType :: Voting ( vote_source) = transaction_storage. thread_type {
1149
- UnprocessedTransactionStorage :: new_vote_storage (
1150
- latest_unprocessed_votes,
1151
- vote_source,
1152
- )
1153
- } else {
1154
- UnprocessedTransactionStorage :: TransactionStorage ( transaction_storage)
1155
- }
1156
- }
1157
- _ => unprocessed_transaction_storage,
1158
- } ;
1146
+ // TODO: figure out how often to check this as it grabs the read lock on bank forks
1147
+ // when checking feature_set
1148
+ unprocessed_transaction_storage =
1149
+ unprocessed_transaction_storage. maybe_hot_swap ( bank_forks) ;
1159
1150
1160
1151
let my_pubkey = cluster_info. id ( ) ;
1161
1152
if !unprocessed_transaction_storage. is_empty ( )
@@ -1287,7 +1278,7 @@ impl BankingStage {
1287
1278
bank : & Arc < Bank > ,
1288
1279
poh : & TransactionRecorder ,
1289
1280
batch : & TransactionBatch ,
1290
- transaction_status_sender : Option < TransactionStatusSender > ,
1281
+ transaction_status_sender : & Option < TransactionStatusSender > ,
1291
1282
gossip_vote_sender : & ReplayVoteSender ,
1292
1283
log_messages_bytes_limit : Option < usize > ,
1293
1284
) -> ExecuteAndCommitTransactionsOutput {
@@ -1529,7 +1520,7 @@ impl BankingStage {
1529
1520
txs : & [ SanitizedTransaction ] ,
1530
1521
poh : & TransactionRecorder ,
1531
1522
chunk_offset : usize ,
1532
- transaction_status_sender : Option < TransactionStatusSender > ,
1523
+ transaction_status_sender : & Option < TransactionStatusSender > ,
1533
1524
gossip_vote_sender : & ReplayVoteSender ,
1534
1525
qos_service : & QosService ,
1535
1526
log_messages_bytes_limit : Option < usize > ,
@@ -1722,7 +1713,7 @@ impl BankingStage {
1722
1713
bank_creation_time : & Instant ,
1723
1714
transactions : & [ SanitizedTransaction ] ,
1724
1715
poh : & TransactionRecorder ,
1725
- transaction_status_sender : Option < TransactionStatusSender > ,
1716
+ transaction_status_sender : & Option < TransactionStatusSender > ,
1726
1717
gossip_vote_sender : & ReplayVoteSender ,
1727
1718
qos_service : & QosService ,
1728
1719
log_messages_bytes_limit : Option < usize > ,
@@ -1754,7 +1745,7 @@ impl BankingStage {
1754
1745
& transactions[ chunk_start..chunk_end] ,
1755
1746
poh,
1756
1747
chunk_start,
1757
- transaction_status_sender. clone ( ) ,
1748
+ transaction_status_sender,
1758
1749
gossip_vote_sender,
1759
1750
qos_service,
1760
1751
log_messages_bytes_limit,
@@ -1919,7 +1910,7 @@ impl BankingStage {
1919
1910
bank_creation_time : & Instant ,
1920
1911
poh : & ' a TransactionRecorder ,
1921
1912
deserialized_packets : impl Iterator < Item = & ' a ImmutableDeserializedPacket > ,
1922
- transaction_status_sender : Option < TransactionStatusSender > ,
1913
+ transaction_status_sender : & Option < TransactionStatusSender > ,
1923
1914
gossip_vote_sender : & ' a ReplayVoteSender ,
1924
1915
banking_stage_stats : & ' a BankingStageStats ,
1925
1916
qos_service : & ' a QosService ,
@@ -2187,12 +2178,15 @@ impl BankingStage {
2187
2178
}
2188
2179
}
2189
2180
2190
- pub ( crate ) fn weighted_random_order_by_stake ( bank : & Arc < Bank > ) -> impl Iterator < Item = Pubkey > {
2181
+ pub ( crate ) fn weighted_random_order_by_stake < ' a > (
2182
+ bank : & Arc < Bank > ,
2183
+ pubkeys : impl Iterator < Item = & ' a Pubkey > ,
2184
+ ) -> impl Iterator < Item = Pubkey > {
2191
2185
// Efraimidis and Spirakis algo for weighted random sample without replacement
2192
- let mut pubkey_with_weight : Vec < ( f64 , Pubkey ) > = bank
2193
- . staked_nodes ( )
2194
- . iter ( )
2195
- . filter_map ( | ( & pubkey, & stake ) | {
2186
+ let staked_nodes = bank. staked_nodes ( ) ;
2187
+ let mut pubkey_with_weight : Vec < ( f64 , Pubkey ) > = pubkeys
2188
+ . filter_map ( | & pubkey| {
2189
+ let stake = staked_nodes . get ( & pubkey) . copied ( ) . unwrap_or ( 0 ) ;
2196
2190
if stake == 0 {
2197
2191
None // Ignore votes from unstaked validators
2198
2192
} else {
@@ -2270,7 +2264,6 @@ mod tests {
2270
2264
solana_runtime:: { bank_forks:: BankForks , genesis_utils:: activate_feature} ,
2271
2265
solana_sdk:: {
2272
2266
account:: AccountSharedData ,
2273
- feature_set,
2274
2267
hash:: Hash ,
2275
2268
instruction:: InstructionError ,
2276
2269
message:: {
@@ -2931,7 +2924,7 @@ mod tests {
2931
2924
& transactions,
2932
2925
& recorder,
2933
2926
0 ,
2934
- None ,
2927
+ & None ,
2935
2928
& gossip_vote_sender,
2936
2929
& QosService :: new ( Arc :: new ( RwLock :: new ( CostModel :: default ( ) ) ) , 1 ) ,
2937
2930
None ,
@@ -2984,7 +2977,7 @@ mod tests {
2984
2977
& transactions,
2985
2978
& recorder,
2986
2979
0 ,
2987
- None ,
2980
+ & None ,
2988
2981
& gossip_vote_sender,
2989
2982
& QosService :: new ( Arc :: new ( RwLock :: new ( CostModel :: default ( ) ) ) , 1 ) ,
2990
2983
None ,
@@ -3068,7 +3061,7 @@ mod tests {
3068
3061
& transactions,
3069
3062
& recorder,
3070
3063
0 ,
3071
- None ,
3064
+ & None ,
3072
3065
& gossip_vote_sender,
3073
3066
& QosService :: new ( Arc :: new ( RwLock :: new ( CostModel :: default ( ) ) ) , 1 ) ,
3074
3067
None ,
@@ -3160,7 +3153,7 @@ mod tests {
3160
3153
& transactions,
3161
3154
& recorder,
3162
3155
0 ,
3163
- None ,
3156
+ & None ,
3164
3157
& gossip_vote_sender,
3165
3158
& qos_service,
3166
3159
None ,
@@ -3200,7 +3193,7 @@ mod tests {
3200
3193
& transactions,
3201
3194
& recorder,
3202
3195
0 ,
3203
- None ,
3196
+ & None ,
3204
3197
& gossip_vote_sender,
3205
3198
& qos_service,
3206
3199
None ,
@@ -3297,7 +3290,7 @@ mod tests {
3297
3290
& transactions,
3298
3291
& recorder,
3299
3292
0 ,
3300
- None ,
3293
+ & None ,
3301
3294
& gossip_vote_sender,
3302
3295
& QosService :: new ( Arc :: new ( RwLock :: new ( CostModel :: default ( ) ) ) , 1 ) ,
3303
3296
None ,
@@ -3463,7 +3456,7 @@ mod tests {
3463
3456
& Instant :: now ( ) ,
3464
3457
& transactions,
3465
3458
& recorder,
3466
- None ,
3459
+ & None ,
3467
3460
& gossip_vote_sender,
3468
3461
& QosService :: new ( Arc :: new ( RwLock :: new ( CostModel :: default ( ) ) ) , 1 ) ,
3469
3462
None ,
@@ -3530,7 +3523,7 @@ mod tests {
3530
3523
& Instant :: now ( ) ,
3531
3524
& transactions,
3532
3525
& recorder,
3533
- None ,
3526
+ & None ,
3534
3527
& gossip_vote_sender,
3535
3528
& QosService :: new ( Arc :: new ( RwLock :: new ( CostModel :: default ( ) ) ) , 1 ) ,
3536
3529
None ,
@@ -3751,7 +3744,7 @@ mod tests {
3751
3744
& transactions,
3752
3745
& recorder,
3753
3746
0 ,
3754
- Some ( TransactionStatusSender {
3747
+ & Some ( TransactionStatusSender {
3755
3748
sender : transaction_status_sender,
3756
3749
} ) ,
3757
3750
& gossip_vote_sender,
@@ -3913,7 +3906,7 @@ mod tests {
3913
3906
& [ sanitized_tx. clone ( ) ] ,
3914
3907
& recorder,
3915
3908
0 ,
3916
- Some ( TransactionStatusSender {
3909
+ & Some ( TransactionStatusSender {
3917
3910
sender : transaction_status_sender,
3918
3911
} ) ,
3919
3912
& gossip_vote_sender,
@@ -4025,6 +4018,7 @@ mod tests {
4025
4018
num_conflicting_transactions,
4026
4019
) ,
4027
4020
ThreadType :: Transactions ,
4021
+ None ,
4028
4022
) ;
4029
4023
4030
4024
let ( gossip_vote_sender, _gossip_vote_receiver) = unbounded ( ) ;
@@ -4125,6 +4119,7 @@ mod tests {
4125
4119
num_conflicting_transactions,
4126
4120
) ,
4127
4121
ThreadType :: Transactions ,
4122
+ None ,
4128
4123
) ;
4129
4124
let all_packet_message_hashes: HashSet < Hash > = buffered_packet_batches
4130
4125
. iter ( )
@@ -4244,6 +4239,7 @@ mod tests {
4244
4239
& mut UnprocessedTransactionStorage :: new_transaction_storage (
4245
4240
unprocessed_packet_batches,
4246
4241
ThreadType :: Transactions ,
4242
+ None ,
4247
4243
) ,
4248
4244
& poh_recorder,
4249
4245
& socket,
@@ -4301,6 +4297,7 @@ mod tests {
4301
4297
2 ,
4302
4298
) ,
4303
4299
ThreadType :: Transactions ,
4300
+ None ,
4304
4301
) ;
4305
4302
4306
4303
let genesis_config_info = create_slow_genesis_config ( 10_000 ) ;
@@ -4520,6 +4517,7 @@ mod tests {
4520
4517
let mut transaction_storage = UnprocessedTransactionStorage :: new_transaction_storage (
4521
4518
UnprocessedPacketBatches :: with_capacity ( 100 ) ,
4522
4519
thread_type,
4520
+ None ,
4523
4521
) ;
4524
4522
transaction_storage
4525
4523
. deserialize_and_insert_batch ( & packet_batch, & ( 0 ..3_usize ) . collect_vec ( ) ) ;
0 commit comments