Skip to content

Commit

Permalink
Don't panic if sent a bad packet
Browse files Browse the repository at this point in the history
  • Loading branch information
garious committed Jun 16, 2018
1 parent 9d84ec4 commit 808c8d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/ledger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The `ledger` module provides functions for parallel verification of the
//! Proof of History ledger.

use bincode::{deserialize, serialize_into};
use bincode::{self, deserialize, serialize_into};
use entry::{next_entry, Entry};
use hash::Hash;
use packet;
Expand Down Expand Up @@ -104,12 +104,12 @@ pub fn next_entries(
entries
}

pub fn reconstruct_entries_from_blobs(blobs: &VecDeque<SharedBlob>) -> Vec<Entry> {
pub fn reconstruct_entries_from_blobs(blobs: &VecDeque<SharedBlob>) -> bincode::Result<Vec<Entry>> {
let mut entries_to_apply: Vec<Entry> = Vec::new();
let mut last_id = Hash::default();
for msgs in blobs {
let blob = msgs.read().unwrap();
let entries: Vec<Entry> = deserialize(&blob.data()[..blob.meta.size]).unwrap();
let entries: Vec<Entry> = deserialize(&blob.data()[..blob.meta.size])?;
for entry in entries {
if entry.id == last_id {
if let Some(last_entry) = entries_to_apply.last_mut() {
Expand All @@ -120,9 +120,8 @@ pub fn reconstruct_entries_from_blobs(blobs: &VecDeque<SharedBlob>) -> Vec<Entry
entries_to_apply.push(entry);
}
}
//TODO respond back to leader with hash of the state
}
entries_to_apply
Ok(entries_to_apply)
}

#[cfg(test)]
Expand Down Expand Up @@ -161,7 +160,7 @@ mod tests {
let mut blob_q = VecDeque::new();
entries.to_blobs(&blob_recycler, &mut blob_q);

assert_eq!(reconstruct_entries_from_blobs(&blob_q), entries);
assert_eq!(reconstruct_entries_from_blobs(&blob_q).unwrap(), entries);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/replicate_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl ReplicateStage {
) -> Result<()> {
let timer = Duration::new(1, 0);
let blobs = blob_receiver.recv_timeout(timer)?;
let entries = ledger::reconstruct_entries_from_blobs(&blobs);
let entries = ledger::reconstruct_entries_from_blobs(&blobs)?;
let res = bank.process_entries(entries);
if res.is_err() {
error!("process_entries {} {:?}", blobs.len(), res);
Expand Down

0 comments on commit 808c8d3

Please sign in to comment.