Allow buffered packets be consumed if bank is active, regardless leader schedule (#22913)

This commit is contained in:
Tao Zhu 2022-02-03 15:29:41 -06:00 committed by GitHub
parent 28442aa922
commit 4bec182b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 25 deletions

View File

@ -679,30 +679,30 @@ impl BankingStage {
would_be_leader: bool, would_be_leader: bool,
would_be_leader_shortly: bool, would_be_leader_shortly: bool,
) -> BufferedPacketsDecision { ) -> BufferedPacketsDecision {
leader_pubkey.map_or( // If has active bank, then immediately process buffered packets
// If leader is not known, return the buffered packets as is // otherwise, based on leader schedule to either forward or hold packets
BufferedPacketsDecision::Hold, if let Some(bank) = bank_still_processing_txs {
// else process the packets // If the bank is available, this node is the leader
|x| { BufferedPacketsDecision::Consume(bank.ns_per_slot)
if let Some(bank) = bank_still_processing_txs { } else if would_be_leader_shortly {
// If the bank is available, this node is the leader // If the node will be the leader soon, hold the packets for now
BufferedPacketsDecision::Consume(bank.ns_per_slot) BufferedPacketsDecision::Hold
} else if would_be_leader_shortly { } else if would_be_leader {
// If the node will be the leader soon, hold the packets for now // Node will be leader within ~20 slots, hold the transactions in
BufferedPacketsDecision::Hold // case it is the only node which produces an accepted slot.
} else if would_be_leader { BufferedPacketsDecision::ForwardAndHold
// Node will be leader within ~20 slots, hold the transactions in } else if let Some(x) = leader_pubkey {
// case it is the only node which produces an accepted slot. if x != *my_pubkey {
BufferedPacketsDecision::ForwardAndHold // If the current node is not the leader, forward the buffered packets
} else if x != *my_pubkey { BufferedPacketsDecision::Forward
// If the current node is not the leader, forward the buffered packets } else {
BufferedPacketsDecision::Forward // If the current node is the leader, return the buffered packets as is
} else { BufferedPacketsDecision::Hold
// We don't know the leader. Hold the packets for now }
BufferedPacketsDecision::Hold } else {
} // We don't know the leader. Hold the packets for now
}, BufferedPacketsDecision::Hold
) }
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -2317,9 +2317,10 @@ mod tests {
let my_pubkey = solana_sdk::pubkey::new_rand(); let my_pubkey = solana_sdk::pubkey::new_rand();
let my_pubkey1 = solana_sdk::pubkey::new_rand(); let my_pubkey1 = solana_sdk::pubkey::new_rand();
let bank = Arc::new(Bank::default_for_tests()); let bank = Arc::new(Bank::default_for_tests());
// having active bank allows to consume immediately
assert_matches!( assert_matches!(
BankingStage::consume_or_forward_packets(&my_pubkey, None, Some(&bank), false, false), BankingStage::consume_or_forward_packets(&my_pubkey, None, Some(&bank), false, false),
BufferedPacketsDecision::Hold BufferedPacketsDecision::Consume(_)
); );
assert_matches!( assert_matches!(
BankingStage::consume_or_forward_packets(&my_pubkey, None, None, false, false), BankingStage::consume_or_forward_packets(&my_pubkey, None, None, false, false),