Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup bank #277

Merged
merged 6 commits into from
May 29, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Remove dead code
History: we thought SigVerifyStage would use these, but it does
signature verification before deserializing transactions.
  • Loading branch information
garious committed May 29, 2018
commit d3576548bf640634edc76a6906bc6f80d9a6550c
51 changes: 0 additions & 51 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bincode::serialize;
use chrono::prelude::*;
use hash::Hash;
use plan::{Condition, Payment, Plan};
use rayon::prelude::*;
use signature::{KeyPair, KeyPairUtil, PublicKey, Signature, SignatureUtil};

pub const SIGNED_DATA_OFFSET: usize = 112;
Expand Down Expand Up @@ -138,21 +137,6 @@ pub fn memfind<A: Eq>(a: &[A], b: &[A]) -> Option<usize> {
None
}

/// Verify a batch of signatures.
pub fn verify_signatures(transactions: &[Transaction]) -> bool {
transactions.par_iter().all(|tx| tx.verify_sig())
}

/// Verify a batch of spending plans.
pub fn verify_plans(transactions: &[Transaction]) -> bool {
transactions.par_iter().all(|tx| tx.verify_plan())
}

/// Verify a batch of transactions.
pub fn verify_transactions(transactions: &[Transaction]) -> bool {
verify_signatures(transactions) && verify_plans(transactions)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -257,39 +241,4 @@ mod tests {
}
assert!(!tx.verify_plan());
}

#[test]
fn test_verify_transactions() {
let alice_keypair = KeyPair::new();
let bob_pubkey = KeyPair::new().pubkey();
let carol_pubkey = KeyPair::new().pubkey();
let last_id = Hash::default();
let tx0 = Transaction::new(&alice_keypair, bob_pubkey, 1, last_id);
let tx1 = Transaction::new(&alice_keypair, carol_pubkey, 1, last_id);
let transactions = vec![tx0, tx1];
assert!(verify_transactions(&transactions));
}
}

#[cfg(all(feature = "unstable", test))]
mod bench {
extern crate test;
use self::test::Bencher;
use transaction::*;

#[bench]
fn bench_verify_signatures(bencher: &mut Bencher) {
let alice_keypair = KeyPair::new();
let last_id = Hash::default();
let transactions: Vec<_> = (0..64)
.into_par_iter()
.map(|_| {
let rando_pubkey = KeyPair::new().pubkey();
Transaction::new(&alice_keypair, rando_pubkey, 1, last_id)
})
.collect();
bencher.iter(|| {
assert!(verify_signatures(&transactions));
});
}
}