Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use less memory in verifier_cache by storing zero-sized type instead of bool #2536

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions core/src/core/verifier_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub trait VerifierCache: Sync + Send {
/// Caches tx kernels by kernel hash.
/// Caches outputs by output rangeproof hash (rangeproofs are committed to separately).
pub struct LruVerifierCache {
kernel_sig_verification_cache: LruCache<Hash, bool>,
rangeproof_verification_cache: LruCache<Hash, bool>,
kernel_sig_verification_cache: LruCache<Hash, ()>,
rangeproof_verification_cache: LruCache<Hash, ()>,
}

impl LruVerifierCache {
Expand All @@ -60,12 +60,7 @@ impl VerifierCache for LruVerifierCache {
fn filter_kernel_sig_unverified(&mut self, kernels: &[TxKernel]) -> Vec<TxKernel> {
let res = kernels
.iter()
.filter(|x| {
!*self
.kernel_sig_verification_cache
.get_mut(&x.hash())
.unwrap_or(&mut false)
})
.filter(|x| !self.kernel_sig_verification_cache.contains_key(&x.hash()))
.cloned()
.collect::<Vec<_>>();
trace!(
Expand All @@ -80,10 +75,9 @@ impl VerifierCache for LruVerifierCache {
let res = outputs
.iter()
.filter(|x| {
!*self
!self
.rangeproof_verification_cache
.get_mut(&x.proof.hash())
.unwrap_or(&mut false)
.contains_key(&x.proof.hash())
})
.cloned()
.collect::<Vec<_>>();
Expand All @@ -97,14 +91,14 @@ impl VerifierCache for LruVerifierCache {

fn add_kernel_sig_verified(&mut self, kernels: Vec<TxKernel>) {
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>) {
for o in outputs {
self.rangeproof_verification_cache
.insert(o.proof.hash(), true);
.insert(o.proof.hash(), ());
}
}
}