Merge rust-bitcoin/rust-bitcoin#2961: bip158: Hash data instead of copying first
6d3137ed87
bip158: Hash data instead of copying first (Tobin C. Harding) Pull request description: Currently we copy data into a new buffer before passing it into the hasher, we can just hash the data directly. Internal change only, no external change. Fix: #2917 ACKs for top commit: Kixunil: ACK6d3137ed87
apoelstra: ACK6d3137ed87
Tree-SHA512: ff5bd18feffe1e77494b0cd14713bc55f1111f026d05bfa58a679f609fdba70160ab9df7677f0790b5b269878226c2f16164be2c918e1ad8b77e2c23d72889dd
This commit is contained in:
commit
ec18895bd4
|
@ -40,7 +40,7 @@
|
||||||
use core::cmp::{self, Ordering};
|
use core::cmp::{self, Ordering};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use hashes::{sha256d, siphash24};
|
use hashes::{sha256d, siphash24, HashEngine as _};
|
||||||
use internals::write_err;
|
use internals::write_err;
|
||||||
use io::{BufRead, Write};
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
|
@ -115,10 +115,10 @@ pub struct BlockFilter {
|
||||||
impl FilterHash {
|
impl FilterHash {
|
||||||
/// Computes the filter header from a filter hash and previous filter header.
|
/// Computes the filter header from a filter hash and previous filter header.
|
||||||
pub fn filter_header(&self, previous_filter_header: FilterHeader) -> FilterHeader {
|
pub fn filter_header(&self, previous_filter_header: FilterHeader) -> FilterHeader {
|
||||||
let mut header_data = [0u8; 64];
|
let mut engine = sha256d::Hash::engine();
|
||||||
header_data[0..32].copy_from_slice(&self[..]);
|
engine.input(self.as_ref());
|
||||||
header_data[32..64].copy_from_slice(&previous_filter_header[..]);
|
engine.input(previous_filter_header.as_ref());
|
||||||
FilterHeader(sha256d::Hash::hash(&header_data))
|
FilterHeader(sha256d::Hash::from_engine(engine))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue