From d5a271c7a457f599e96729f77b42a322b30b22f5 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 13 Jul 2022 22:41:56 +0000 Subject: [PATCH] Add bundle kind to `BundleValidityCache` initialization log message --- src/rust/src/bundlecache.rs | 10 ++++++---- src/zcash/cache.cpp | 6 +++--- src/zcash/cache.h | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rust/src/bundlecache.rs b/src/rust/src/bundlecache.rs index 22a3fe08e..e5873dc1b 100644 --- a/src/rust/src/bundlecache.rs +++ b/src/rust/src/bundlecache.rs @@ -13,7 +13,7 @@ mod ffi { type BundleValidityCache; - fn NewBundleValidityCache(bytes: usize) -> UniquePtr; + fn NewBundleValidityCache(kind: &str, bytes: usize) -> UniquePtr; fn insert(self: Pin<&mut BundleValidityCache>, entry: [u8; 32]); fn contains(&self, entry: &[u8; 32], erase: bool) -> bool; } @@ -46,7 +46,7 @@ pub(crate) struct BundleValidityCache { } impl BundleValidityCache { - fn new(personalization: &[u8; 16], cache_bytes: usize) -> Self { + fn new(kind: &'static str, personalization: &[u8; 16], cache_bytes: usize) -> Self { // Use BLAKE2b to produce entries from bundles. It has a block size of 128 bytes, // into which we put: // - 32 byte nonce @@ -65,7 +65,7 @@ impl BundleValidityCache { Self { hasher, - cache: ffi::NewBundleValidityCache(cache_bytes), + cache: ffi::NewBundleValidityCache(kind, cache_bytes), } } @@ -84,7 +84,7 @@ impl BundleValidityCache { .as_bytes() .try_into() .map(CacheEntry) - .unwrap() + .expect("BLAKE2b configured with hash length of 32 so conversion cannot fail") } pub(crate) fn insert(&mut self, queued_entries: CacheEntries) { @@ -117,10 +117,12 @@ static mut ORCHARD_BUNDLE_VALIDITY_CACHE: Option> = fn init(cache_bytes: usize) { BUNDLE_CACHES_LOADED.call_once(|| unsafe { SAPLING_BUNDLE_VALIDITY_CACHE = Some(RwLock::new(BundleValidityCache::new( + "Sapling", b"SaplingVeriCache", cache_bytes, ))); ORCHARD_BUNDLE_VALIDITY_CACHE = Some(RwLock::new(BundleValidityCache::new( + "Orchard", b"OrchardVeriCache", cache_bytes, ))); diff --git a/src/zcash/cache.cpp b/src/zcash/cache.cpp index d6cf1a737..6c737fee3 100644 --- a/src/zcash/cache.cpp +++ b/src/zcash/cache.cpp @@ -7,12 +7,12 @@ namespace libzcash { -std::unique_ptr NewBundleValidityCache(size_t nMaxCacheSize) +std::unique_ptr NewBundleValidityCache(rust::Str kind, size_t nMaxCacheSize) { auto cache = std::unique_ptr(new BundleValidityCache()); size_t nElems = cache->setup_bytes(nMaxCacheSize); - LogPrintf("Using %zu MiB out of %zu requested for bundle cache, able to store %zu elements\n", - (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, nElems); + LogPrintf("Using %zu MiB out of %zu requested for %s bundle cache, able to store %zu elements\n", + (nElems * sizeof(BundleCacheEntry)) >> 20, nMaxCacheSize >> 20, kind, nElems); return cache; } } // namespace libzcash diff --git a/src/zcash/cache.h b/src/zcash/cache.h index 15df35f32..dc6a646a4 100644 --- a/src/zcash/cache.h +++ b/src/zcash/cache.h @@ -7,6 +7,8 @@ #include "cuckoocache.h" +#include + #include namespace libzcash @@ -36,7 +38,7 @@ public: typedef CuckooCache::cache BundleValidityCache; -std::unique_ptr NewBundleValidityCache(size_t nMaxCacheSize); +std::unique_ptr NewBundleValidityCache(rust::Str kind, size_t nMaxCacheSize); } // namespace libzcash template void CuckooCache::cache::insert(libzcash::BundleCacheEntry e);