bip158: Hash data instead of copying first
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
This commit is contained in:
parent
db72ea8b32
commit
6d3137ed87
|
@ -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