-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c03802c
commit f961990
Showing
6 changed files
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
use lru::LruCache; | ||
use parking_lot::Mutex; | ||
use types::{AbstractSidecar, EthSpec, Hash256, SidecarList}; | ||
use types::{EthSpec, Hash256, Sidecar, SidecarList}; | ||
|
||
pub const DEFAULT_BLOB_CACHE_SIZE: usize = 10; | ||
|
||
/// A cache blobs by beacon block root. | ||
pub struct BlobCache<T: EthSpec, Sidecar: AbstractSidecar<T>> { | ||
blobs: Mutex<LruCache<BlobCacheId, SidecarList<T, Sidecar>>>, | ||
pub struct BlobCache<T: EthSpec, S: Sidecar<T>> { | ||
blobs: Mutex<LruCache<BlobCacheId, SidecarList<T, S>>>, | ||
} | ||
|
||
#[derive(Hash, PartialEq, Eq)] | ||
struct BlobCacheId(Hash256); | ||
|
||
impl<T: EthSpec, Sidecar: AbstractSidecar<T>> Default for BlobCache<T, Sidecar> { | ||
impl<T: EthSpec, S: Sidecar<T>> Default for BlobCache<T, S> { | ||
fn default() -> Self { | ||
BlobCache { | ||
blobs: Mutex::new(LruCache::new(DEFAULT_BLOB_CACHE_SIZE)), | ||
} | ||
} | ||
} | ||
|
||
impl<T: EthSpec, Sidecar: AbstractSidecar<T>> BlobCache<T, Sidecar> { | ||
impl<T: EthSpec, S: Sidecar<T>> BlobCache<T, S> { | ||
pub fn put( | ||
&self, | ||
beacon_block: Hash256, | ||
blobs: SidecarList<T, Sidecar>, | ||
) -> Option<SidecarList<T, Sidecar>> { | ||
blobs: SidecarList<T, S>, | ||
) -> Option<SidecarList<T, S>> { | ||
self.blobs.lock().put(BlobCacheId(beacon_block), blobs) | ||
} | ||
|
||
pub fn pop(&self, root: &Hash256) -> Option<SidecarList<T, Sidecar>> { | ||
pub fn pop(&self, root: &Hash256) -> Option<SidecarList<T, S>> { | ||
self.blobs.lock().pop(&BlobCacheId(*root)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters