diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 2f57cd6af0..c37a9cd209 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -4,7 +4,7 @@ use crate::cluster_info::ClusterInfo; use crate::entry; -use crate::entry::Entry; +use crate::entry::{hash_transactions, Entry}; use crate::leader_schedule_utils; use crate::packet; use crate::packet::SharedPackets; @@ -236,7 +236,7 @@ impl BankingStage { debug!("processed: {} ", processed_transactions.len()); // unlock all the accounts with errors which are filtered by the above `filter_map` if !processed_transactions.is_empty() { - let hash = Transaction::hash(&processed_transactions); + let hash = hash_transactions(&processed_transactions); // record and unlock will unlock all the successfull transactions poh.lock() .unwrap() diff --git a/core/src/entry.rs b/core/src/entry.rs index 600e85a887..347cbcb3f6 100644 --- a/core/src/entry.rs +++ b/core/src/entry.rs @@ -9,7 +9,7 @@ use bincode::{deserialize, serialized_size}; use chrono::prelude::Utc; use rayon::prelude::*; use solana_budget_api::budget_instruction::BudgetInstruction; -use solana_sdk::hash::Hash; +use solana_sdk::hash::{Hash, Hasher}; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::transaction::Transaction; use std::borrow::Borrow; @@ -155,6 +155,17 @@ impl Entry { } } +pub fn hash_transactions(transactions: &[Transaction]) -> Hash { + // a hash of a slice of transactions only needs to hash the signatures + let mut hasher = Hasher::default(); + transactions.iter().for_each(|tx| { + if !tx.signatures.is_empty() { + hasher.hash(&tx.signatures[0].as_ref()); + } + }); + hasher.result() +} + /// Creates the hash `num_hashes` after `start_hash`. If the transaction contains /// a signature, the final hash will be a hash of both the previous ID and /// the signature. If num_hashes is zero and there's no transaction data, @@ -173,7 +184,7 @@ fn next_hash(start_hash: &Hash, num_hashes: u64, transactions: &[Transaction]) - if transactions.is_empty() { poh.tick().hash } else { - poh.record(Transaction::hash(transactions)).hash + poh.record(hash_transactions(transactions)).hash } } diff --git a/core/src/sigverify.rs b/core/src/sigverify.rs index 159c247658..c1afe6eefc 100644 --- a/core/src/sigverify.rs +++ b/core/src/sigverify.rs @@ -392,7 +392,6 @@ mod tests { Some(sig_start as usize) ); assert_eq!(sig_len, 1); - assert!(tx.verify_signature()); } #[test] diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 7cada5213e..f615b5e78c 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -1,6 +1,6 @@ //! Defines a Transaction type to package an atomic sequence of instructions. -use crate::hash::{Hash, Hasher}; +use crate::hash::Hash; use crate::instruction::{CompiledInstruction, Instruction, InstructionError}; use crate::message::Message; use crate::packet::PACKET_DATA_SIZE; @@ -215,13 +215,6 @@ impl Transaction { self.sign_unchecked(keypairs, recent_blockhash); } - /// Verify only the transaction signature. - pub fn verify_signature(&self) -> bool { - self.signatures - .iter() - .all(|s| s.verify(&self.from().as_ref(), &self.message())) - } - /// Verify that references in the instructions are valid pub fn verify_refs(&self) -> bool { for instruction in &self.instructions { @@ -237,21 +230,6 @@ impl Transaction { true } - pub fn from(&self) -> &Pubkey { - &self.account_keys[0] - } - - // a hash of a slice of transactions only needs to hash the signatures - pub fn hash(transactions: &[Transaction]) -> Hash { - let mut hasher = Hasher::default(); - transactions.iter().for_each(|tx| { - if !tx.signatures.is_empty() { - hasher.hash(&tx.signatures[0].as_ref()); - } - }); - hasher.result() - } - pub fn serialized_size(&self) -> Result { let mut buf = [0u8; size_of::() + 1]; let mut wr = Cursor::new(&mut buf[..]);