Skip to content

Commit

Permalink
Only allow votes when root distance gets too high #2
Browse files Browse the repository at this point in the history
Updates from master
  • Loading branch information
sakridge authored and tao-stones committed Sep 21, 2021
1 parent c17c740 commit 776c76e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
38 changes: 35 additions & 3 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use solana_sdk::{
use solana_transaction_status::token_balances::{
collect_token_balances, TransactionTokenBalancesSet,
};
use solana_vote_program::vote_transaction;
use std::{
borrow::Cow,
cmp,
Expand Down Expand Up @@ -1033,7 +1032,7 @@ impl BankingStage {
.filter_map(|tx_index| {
let p = &msgs.packets[*tx_index];
let tx: Transaction = limited_deserialize(&p.data[0..p.meta.size]).ok()?;
if votes_only && vote_transaction::parse_vote_transaction(&tx).is_none() {
if votes_only && !solana_runtime::bank::is_simple_vote_transaction(&tx) {
return None;
}
tx.verify_precompiles(libsecp256k1_0_5_upgrade_enabled)
Expand Down Expand Up @@ -1174,7 +1173,7 @@ impl BankingStage {
msgs,
&transaction_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
false,
bank.vote_only_bank(),
);

let tx_count = transaction_to_packet_indexes.len();
Expand Down Expand Up @@ -2914,4 +2913,37 @@ mod tests {
transaction.message_data()
);
}

#[test]
fn test_transactions_from_packets() {
use solana_vote_program::vote_state::Vote;
solana_logger::setup();
let mut vote_packet = Packet::default();
let vote_instruction = solana_vote_program::vote_instruction::vote(
&Pubkey::new_unique(),
&Pubkey::new_unique(),
Vote::default(),
);
let vote_transaction =
Transaction::new_with_payer(&[vote_instruction], Some(&Pubkey::new_unique()));
Packet::populate_packet(&mut vote_packet, None, &vote_transaction).unwrap();
let mut non_vote = Packet::default();
let tx = system_transaction::transfer(
&Keypair::new(),
&Pubkey::new_unique(),
2,
Hash::default(),
);
Packet::populate_packet(&mut non_vote, None, &tx).unwrap();
let msgs = Packets::new(vec![non_vote, vote_packet]);
let packet_indexes = [0, 1];
let (transactions, _transaction_to_packet_indexes) =
BankingStage::transactions_from_packets(&msgs, &packet_indexes, false, true);
assert_eq!(transactions.len(), 1);
assert!(!transactions[0].transaction().signatures.is_empty());

let (transactions, _transaction_to_packet_indexes) =
BankingStage::transactions_from_packets(&msgs, &packet_indexes, false, false);
assert_eq!(transactions.len(), 2);
}
}
9 changes: 8 additions & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,14 +1228,21 @@ impl ReplayStage {
);

let root_distance = poh_slot - root_slot;
const MAX_ROOT_DISTANCE_FOR_VOTE_ONLY: Slot = 500;
let vote_only_bank = if root_distance > MAX_ROOT_DISTANCE_FOR_VOTE_ONLY {
datapoint_info!("vote-only-bank", ("slot", poh_slot, i64));
true
} else {
false
};

let tpu_bank = Self::new_bank_from_parent_with_notify(
&parent,
poh_slot,
root_slot,
my_pubkey,
rpc_subscriptions,
root_distance > 500,
vote_only_bank,
);

let tpu_bank = bank_forks.write().unwrap().insert(tpu_bank);
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5150,7 +5150,7 @@ pub fn goto_end_of_slot(bank: &mut Bank) {
}
}

fn is_simple_vote_transaction(transaction: &Transaction) -> bool {
pub fn is_simple_vote_transaction(transaction: &Transaction) -> bool {
if transaction.message.instructions.len() == 1 {
let instruction = &transaction.message.instructions[0];
let program_pubkey =
Expand Down

0 comments on commit 776c76e

Please sign in to comment.