discards serialized gossip crds votes if cannot parse tx (#22129)

This commit is contained in:
behzad nouri
2021-12-29 19:31:26 +00:00
committed by GitHub
parent b1d9a2e60e
commit c9c78622a8
6 changed files with 53 additions and 51 deletions

View File

@ -599,7 +599,7 @@ mod tests {
crate::{
packet::{Packet, PacketBatch},
sigverify::{self, PacketOffsets},
test_tx::{test_multisig_tx, test_tx, vote_tx},
test_tx::{new_test_vote_tx, test_multisig_tx, test_tx},
},
bincode::{deserialize, serialize},
solana_sdk::{
@ -1187,6 +1187,7 @@ mod tests {
#[test]
fn test_is_simple_vote_transaction() {
solana_logger::setup();
let mut rng = rand::thread_rng();
// tansfer tx is not
{
@ -1200,7 +1201,7 @@ mod tests {
// single vote tx is
{
let mut tx = vote_tx();
let mut tx = new_test_vote_tx(&mut rng);
tx.message.instructions[0].data = vec![1, 2, 3];
let mut packet = sigverify::make_packet_from_transaction(tx);
let packet_offsets = do_get_packet_offsets(&packet, 0).unwrap();
@ -1233,15 +1234,17 @@ mod tests {
#[test]
fn test_is_simple_vote_transaction_with_offsets() {
solana_logger::setup();
let mut rng = rand::thread_rng();
let mut current_offset = 0usize;
let mut batch = PacketBatch::default();
batch
.packets
.push(sigverify::make_packet_from_transaction(test_tx()));
let tx = new_test_vote_tx(&mut rng);
batch
.packets
.push(sigverify::make_packet_from_transaction(vote_tx()));
.push(sigverify::make_packet_from_transaction(tx));
batch
.packets
.iter_mut()

View File

@ -1,5 +1,7 @@
use {
rand::{CryptoRng, Rng, RngCore},
solana_sdk::{
clock::Slot,
hash::Hash,
instruction::CompiledInstruction,
signature::{Keypair, Signer},
@ -50,15 +52,21 @@ pub fn test_multisig_tx() -> Transaction {
)
}
pub fn vote_tx() -> Transaction {
let keypair = Keypair::new();
pub fn new_test_vote_tx<R>(rng: &mut R) -> Transaction
where
R: CryptoRng + RngCore,
{
let mut slots: Vec<Slot> = std::iter::repeat_with(|| rng.gen()).take(5).collect();
slots.sort_unstable();
slots.dedup();
let switch_proof_hash = rng.gen_bool(0.5).then(|| solana_sdk::hash::new_rand(rng));
vote_transaction::new_vote_transaction(
vec![2],
Hash::default(),
Hash::default(),
&keypair,
&keypair,
&keypair,
None,
slots,
solana_sdk::hash::new_rand(rng), // bank_hash
solana_sdk::hash::new_rand(rng), // blockhash
&Keypair::generate(rng), // node_keypair
&Keypair::generate(rng), // vote_keypair
&Keypair::generate(rng), // authorized_voter_keypair
switch_proof_hash,
)
}