diff --git a/entry/src/entry.rs b/entry/src/entry.rs index addc04127a..bfdba187d0 100644 --- a/entry/src/entry.rs +++ b/entry/src/entry.rs @@ -35,10 +35,7 @@ use { std::{ cmp, ffi::OsStr, - sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, Mutex, Once, - }, + sync::{Arc, Mutex, Once}, thread::{self, JoinHandle}, time::Instant, }, @@ -473,24 +470,6 @@ pub fn start_verify_transactions( let entries = verify_transactions(entries, Arc::new(verify_func)); match entries { Ok(entries) => { - let num_transactions: usize = entries - .iter() - .map(|entry: &EntryType| -> usize { - match entry { - EntryType::Transactions(transactions) => transactions.len(), - EntryType::Tick(_) => 0, - } - }) - .sum(); - - if num_transactions == 0 { - return Ok(EntrySigVerificationState { - verification_status: EntryVerificationStatus::Success, - entries: Some(entries), - device_verification_data: DeviceSigVerificationData::Cpu(), - gpu_verify_duration_us: 0, - }); - } let entry_txs: Vec<&SanitizedTransaction> = entries .iter() .filter_map(|entry_type| match entry_type { @@ -499,22 +478,30 @@ pub fn start_verify_transactions( }) .flatten() .collect::>(); - let total_packets = AtomicUsize::new(0); + + if entry_txs.is_empty() { + return Ok(EntrySigVerificationState { + verification_status: EntryVerificationStatus::Success, + entries: Some(entries), + device_verification_data: DeviceSigVerificationData::Cpu(), + gpu_verify_duration_us: 0, + }); + } + let mut packet_batches = entry_txs .par_iter() .chunks(PACKETS_PER_BATCH) .map(|slice| { let vec_size = slice.len(); - total_packets.fetch_add(vec_size, Ordering::Relaxed); let mut packet_batch = PacketBatch::new_with_recycler( verify_recyclers.packet_recycler.clone(), vec_size, "entry-sig-verify", ); - // We use set_len here instead of resize(num_transactions, Packet::default()), to save + // We use set_len here instead of resize(vec_size, Packet::default()), to save // memory bandwidth and avoid writing a large amount of data that will be overwritten // soon afterwards. As well, Packet::default() actually leaves the packet data - // uninitialized anyway, so the initilization would simply write junk into + // uninitialized, so the initialization would simply write junk into // the vector anyway. unsafe { packet_batch.set_len(vec_size); @@ -537,6 +524,7 @@ pub fn start_verify_transactions( let tx_offset_recycler = verify_recyclers.tx_offset_recycler; let out_recycler = verify_recyclers.out_recycler; + let num_packets = entry_txs.len(); let gpu_verify_thread = thread::spawn(move || { let mut verify_time = Measure::start("sigverify"); sigverify::ed25519_verify( @@ -544,7 +532,7 @@ pub fn start_verify_transactions( &tx_offset_recycler, &out_recycler, false, - total_packets.load(Ordering::Relaxed), + num_packets, ); let verified = packet_batches .iter()