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

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-solana committed Jun 26, 2018
1 parent f492644 commit 058fda2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 15 additions & 1 deletion src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub struct Entry {
/// purposes of duplicate rejection
pub has_more: bool,

erasure_pad: [u8; 3],
/// Erasure requires that Entry be a multiple of 4 bytes in size
pad: [u8; 3],
}

impl Entry {
Expand All @@ -61,11 +62,22 @@ impl Entry {
id,
transactions,
has_more,
pad: [0, 0, 0],
};
assert!(serialized_size(&entry).unwrap() <= BLOB_DATA_SIZE as u64);
entry
}

pub fn will_fit(transactions: Vec<Transaction>) -> bool {
serialized_size(&Entry {
num_hashes: 0,
id: Hash::default(),
transactions,
has_more: false,
pad: [0, 0, 0],
}).unwrap() <= BLOB_DATA_SIZE as u64
}

/// Creates the next Tick Entry `num_hashes` after `start_hash`.
pub fn new_mut(
start_hash: &mut Hash,
Expand All @@ -88,6 +100,7 @@ impl Entry {
id: *id,
transactions: vec![],
has_more: false,
pad: [0, 0, 0],
}
}

Expand Down Expand Up @@ -137,6 +150,7 @@ pub fn next_entry(start_hash: &Hash, num_hashes: u64, transactions: Vec<Transact
id: next_hash(start_hash, num_hashes, &transactions),
transactions,
has_more: false,
pad: [0, 0, 0],
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/ledger.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! The `ledger` module provides functions for parallel verification of the
//! Proof of History ledger.
use bincode::{self, deserialize, serialize_into, serialized_size};
use bincode::{self, deserialize, serialize_into};
use entry::Entry;
use hash::Hash;
use packet::{self, SharedBlob, BLOB_DATA_SIZE, BLOB_SIZE};
use packet::{self, SharedBlob, BLOB_SIZE};
use rayon::prelude::*;
use std::collections::VecDeque;
use std::io::Cursor;
Expand Down Expand Up @@ -78,13 +78,7 @@ pub fn next_entries_mut(
let mut chunk_len = transactions.len();

// check for fit, make sure they can be serialized
while serialized_size(&Entry {
num_hashes: 0,
id: Hash::default(),
transactions: transactions[0..chunk_len].to_vec(),
has_more: false,
}).unwrap() > BLOB_DATA_SIZE as u64
{
while !Entry::will_fit(transactions[0..chunk_len].to_vec()) {
chunk_len /= 2;
}

Expand Down Expand Up @@ -131,7 +125,7 @@ mod tests {
use super::*;
use entry::{next_entry, Entry};
use hash::hash;
use packet::BlobRecycler;
use packet::{BlobRecycler, BLOB_DATA_SIZE};
use signature::{KeyPair, KeyPairUtil};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use transaction::Transaction;
Expand Down

0 comments on commit 058fda2

Please sign in to comment.