mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Merge pull request #2536 from JeremyRubin/reduce-memory-cache
refactor: use less memory in verifier_cache by storing zero-sized type instead of bool
This commit is contained in:
commit
1f7ea4930e
1 changed files with 7 additions and 13 deletions
|
@ -41,8 +41,8 @@ pub trait VerifierCache: Sync + Send {
|
||||||
/// Caches tx kernels by kernel hash.
|
/// Caches tx kernels by kernel hash.
|
||||||
/// Caches outputs by output rangeproof hash (rangeproofs are committed to separately).
|
/// Caches outputs by output rangeproof hash (rangeproofs are committed to separately).
|
||||||
pub struct LruVerifierCache {
|
pub struct LruVerifierCache {
|
||||||
kernel_sig_verification_cache: LruCache<Hash, bool>,
|
kernel_sig_verification_cache: LruCache<Hash, ()>,
|
||||||
rangeproof_verification_cache: LruCache<Hash, bool>,
|
rangeproof_verification_cache: LruCache<Hash, ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LruVerifierCache {
|
impl LruVerifierCache {
|
||||||
|
@ -60,12 +60,7 @@ impl VerifierCache for LruVerifierCache {
|
||||||
fn filter_kernel_sig_unverified(&mut self, kernels: &[TxKernel]) -> Vec<TxKernel> {
|
fn filter_kernel_sig_unverified(&mut self, kernels: &[TxKernel]) -> Vec<TxKernel> {
|
||||||
let res = kernels
|
let res = kernels
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| {
|
.filter(|x| !self.kernel_sig_verification_cache.contains_key(&x.hash()))
|
||||||
!*self
|
|
||||||
.kernel_sig_verification_cache
|
|
||||||
.get_mut(&x.hash())
|
|
||||||
.unwrap_or(&mut false)
|
|
||||||
})
|
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -80,10 +75,9 @@ impl VerifierCache for LruVerifierCache {
|
||||||
let res = outputs
|
let res = outputs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| {
|
.filter(|x| {
|
||||||
!*self
|
!self
|
||||||
.rangeproof_verification_cache
|
.rangeproof_verification_cache
|
||||||
.get_mut(&x.proof.hash())
|
.contains_key(&x.proof.hash())
|
||||||
.unwrap_or(&mut false)
|
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -97,14 +91,14 @@ impl VerifierCache for LruVerifierCache {
|
||||||
|
|
||||||
fn add_kernel_sig_verified(&mut self, kernels: Vec<TxKernel>) {
|
fn add_kernel_sig_verified(&mut self, kernels: Vec<TxKernel>) {
|
||||||
for k in kernels {
|
for k in kernels {
|
||||||
self.kernel_sig_verification_cache.insert(k.hash(), true);
|
self.kernel_sig_verification_cache.insert(k.hash(), ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_rangeproof_verified(&mut self, outputs: Vec<Output>) {
|
fn add_rangeproof_verified(&mut self, outputs: Vec<Output>) {
|
||||||
for o in outputs {
|
for o in outputs {
|
||||||
self.rangeproof_verification_cache
|
self.rangeproof_verification_cache
|
||||||
.insert(o.proof.hash(), true);
|
.insert(o.proof.hash(), ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue