Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Failure test case #750

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ pub fn next_entries(
#[cfg(test)]
mod tests {
use super::*;
use bincode::serialized_size;
use entry::{next_entry, Entry};
use hash::hash;
use packet::{BlobRecycler, BLOB_DATA_SIZE};
use packet::{BlobRecycler, BLOB_DATA_SIZE, PACKET_DATA_SIZE};
use signature::{KeyPair, KeyPairUtil};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use transaction::Transaction;
use transaction::{Transaction, Vote};

#[test]
fn test_verify_slice() {
Expand Down Expand Up @@ -170,27 +171,55 @@ mod tests {

#[test]
fn test_next_entries() {
use logger;
logger::setup();
let id = Hash::default();
let next_id = hash(&id);
let keypair = KeyPair::new();
let tx0 = Transaction::new(&keypair, keypair.pubkey(), 1, next_id);
let tx_small = Transaction::new_vote(
&keypair,
Vote {
version: 0,
contact_info_version: 2,
},
next_id,
2,
);
let tx_large = Transaction::new(&keypair, keypair.pubkey(), 1, next_id);

let tx_small_size = serialized_size(&tx_small).unwrap();
let tx_large_size = serialized_size(&tx_large).unwrap();
assert!(tx_small_size < tx_large_size);
assert!(tx_large_size < PACKET_DATA_SIZE as u64);

// NOTE: if Entry grows to larger than a transaction, the code below falls over
let threshold = (BLOB_DATA_SIZE / 256) - 1; // 256 is transaction size
let threshold = (BLOB_DATA_SIZE / PACKET_DATA_SIZE) - 1;
Copy link
Contributor

@rob-solana rob-solana Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PACKET_DATA_SIZE may be the wrong magic number, what you want is sizeof(Transaction)

the test also assumes that the rest of an Entry struct is smaller than a Transaction (hence the -1)

threshold should be (BLOB_DATA_SIZE - serialized_size(Entry)) / serialized_size(Transaction), assuming there's zero overhead for typing in serialization of an Entry (which holds a Vector of Transactions)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would use sizeof(serialized Transaction) no? But we don’t have a way to generate that other than serializing all the different types of Transactions at runtime. sizeof(Transaction), the in-memory representation, is more than 300 bytes. But when serialized always must be less than 256, which I think is what this const represents


// verify no split
let transactions = vec![tx0.clone(); threshold];
let transactions = vec![tx_small.clone(); threshold];
let entries0 = next_entries(&id, 0, transactions.clone());
assert_eq!(entries0.len(), 1);
assert!(entries0.verify(&id));

// verify the split
let transactions = vec![tx0.clone(); threshold * 2];
// verify the split with uniform transactions
let transactions = vec![tx_small.clone(); threshold * 2];
let entries0 = next_entries(&id, 0, transactions.clone());
assert_eq!(entries0.len(), 2);
assert!(entries0[0].has_more);
assert!(!entries0[entries0.len() - 1].has_more);
assert!(entries0.verify(&id));

// verify the split with small transactions followed by large
// transactions
let mut transactions = vec![tx_small.clone(); BLOB_DATA_SIZE / (tx_small_size as usize)];
let large_transactions = vec![tx_large.clone(); BLOB_DATA_SIZE / (tx_large_size as usize)];

transactions.extend(large_transactions);

let entries0 = next_entries(&id, 0, transactions.clone());
assert_eq!(entries0.len(), 5);
assert!(entries0[0].has_more);
assert!(!entries0[entries0.len() - 1].has_more);
assert!(entries0.verify(&id));
// test hand-construction... brittle, changes if split method changes... ?
// let mut entries1 = vec![];
Expand Down