Add support for spam filter to CUDA processor
This commit is contained in:
parent
f62a3f3031
commit
1d6307de76
49
src/gpu.rs
49
src/gpu.rs
|
@ -123,33 +123,36 @@ fn collect_decrypted_notes(
|
|||
let domain = SaplingDomain::for_height(*network, BlockHeight::from_u32(b.height as u32));
|
||||
for (tx_index, tx) in b.vtx.iter().enumerate() {
|
||||
for (output_index, co) in tx.outputs.iter().enumerate() {
|
||||
let plaintext = &output_buffer[i * buffer_stride + 32..i * buffer_stride + 92];
|
||||
// version and amount must be in range - 21 million ZEC is less than 0x0008 0000 0000 0000
|
||||
if plaintext[0] <= 2 && plaintext[18] < 0x08 && plaintext[19] == 0 {
|
||||
if let Some((note, pa)) =
|
||||
if !co.epk.is_empty() {
|
||||
let offset = i * buffer_stride + 32;
|
||||
let plaintext = &output_buffer[offset..offset + 60];
|
||||
// version and amount must be in range - 21 million ZEC is less than 0x0008 0000 0000 0000
|
||||
if plaintext[0] <= 2 && plaintext[18] < 0x08 && plaintext[19] == 0 {
|
||||
if let Some((note, pa)) =
|
||||
domain.parse_note_plaintext_without_memo_ivk(&ivk, plaintext)
|
||||
{
|
||||
let position_in_block =
|
||||
usize::from_le_bytes(plaintext[52..60].try_into().unwrap());
|
||||
let cmu = note.cmu().to_bytes();
|
||||
if &cmu == co.cmu.as_slice() {
|
||||
log::info!("Note {} {}", account, u64::from(note.value));
|
||||
decrypted_notes.push(DecryptedNote {
|
||||
account,
|
||||
ivk: fvk.clone(),
|
||||
note,
|
||||
pa,
|
||||
position_in_block,
|
||||
viewonly: false,
|
||||
height: b.height as u32,
|
||||
txid: tx.hash.clone(),
|
||||
tx_index,
|
||||
output_index,
|
||||
});
|
||||
{
|
||||
let position_in_block =
|
||||
usize::from_le_bytes(plaintext[52..60].try_into().unwrap());
|
||||
let cmu = note.cmu().to_bytes();
|
||||
if &cmu == co.cmu.as_slice() {
|
||||
log::info!("Note {} {}", account, u64::from(note.value));
|
||||
decrypted_notes.push(DecryptedNote {
|
||||
account,
|
||||
ivk: fvk.clone(),
|
||||
note,
|
||||
pa,
|
||||
position_in_block,
|
||||
viewonly: false,
|
||||
height: b.height as u32,
|
||||
txid: tx.hash.clone(),
|
||||
tx_index,
|
||||
output_index,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
db.notes.extend(decrypted_notes);
|
||||
|
|
|
@ -150,35 +150,30 @@ impl CudaProcessor {
|
|||
let cuda_context = m.as_ref().unwrap();
|
||||
CurrentContext::set_current(&cuda_context.context).unwrap();
|
||||
|
||||
let n = blocks
|
||||
.iter()
|
||||
.map(|b| b.vtx.iter().map(|tx| tx.outputs.len()).sum::<usize>())
|
||||
.sum::<usize>();
|
||||
let block_count = (n + THREADS_PER_BLOCK - 1) / THREADS_PER_BLOCK;
|
||||
|
||||
let decrypted_blocks = collect_nf(blocks)?;
|
||||
|
||||
let mut data_buffer = vec![0u8; n * BUFFER_SIZE];
|
||||
let mut data_buffer = vec![];
|
||||
let mut i = 0;
|
||||
for db in decrypted_blocks.iter() {
|
||||
let mut i = 0;
|
||||
let mut position_in_block = 0;
|
||||
let b = &db.compact_block;
|
||||
for tx in b.vtx.iter() {
|
||||
for co in tx.outputs.iter() {
|
||||
if co.epk.is_empty() {
|
||||
break;
|
||||
} // skip decryption
|
||||
data_buffer[i * BUFFER_SIZE..i * BUFFER_SIZE + 32].copy_from_slice(&co.epk);
|
||||
data_buffer[i * BUFFER_SIZE + 32..i * BUFFER_SIZE + 84]
|
||||
.copy_from_slice(&co.ciphertext);
|
||||
data_buffer[i * BUFFER_SIZE + 84..i * BUFFER_SIZE + 92]
|
||||
.copy_from_slice(&usize::to_le_bytes(position_in_block));
|
||||
i += 1;
|
||||
if !co.epk.is_empty() {
|
||||
data_buffer.extend(&co.epk);
|
||||
data_buffer.extend(&co.ciphertext);
|
||||
data_buffer.extend(&u64::to_le_bytes(position_in_block as u64));
|
||||
data_buffer.extend(&[0u8; 4]); // padding
|
||||
i += 1;
|
||||
}
|
||||
position_in_block += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let n = i;
|
||||
let block_count = (n + THREADS_PER_BLOCK - 1) / THREADS_PER_BLOCK;
|
||||
|
||||
let encrypted_data_device = unsafe { DeviceBuffer::uninitialized(data_buffer.len())? };
|
||||
let ivk_device = unsafe { DeviceBuffer::zeroed(32)? };
|
||||
|
||||
|
@ -199,6 +194,7 @@ impl CudaProcessor {
|
|||
|
||||
impl GPUProcessor for CudaProcessor {
|
||||
fn decrypt_account(&mut self, ivk: &SaplingIvk) -> Result<()> {
|
||||
log::info!("n = {}", self.n);
|
||||
if self.n == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue