* Add Deneb builder flow types with generics * Update validator client `get_blinded_blocks` call to support Deneb * `produceBlindedBlock` endpoint updates: - Handle new Deneb BuilderBid response from builder endpoint (new BlindedBlobsBundle type) - Build BlockContents response (containing kzg_commitments, proof and blinded_blob_sidecars) * Appease Clippy lint * Partial implementation of submit blinded block & blobs. Refactor existing `BlobSidecar` related types to support blinded blobs. * Add associated types for BlockProposal * Rename `AbstractSidecar` to `Sidecar` * Remove blob cache as it's no longer necessary * Remove unnecessary enum variant * Clean up * Hanlde unblinded blobs and publish full block contents * Fix tests * Add local EL blobs caching in blinded flow * Remove BlockProposal and move associated Sidecar trait to AbstractExecPayload to simplify changes * add blob roots associated type * move raw blobs associated type to sidecar trait * Fix todos and improve error handling * Consolidate BlobsBundle from `execution_layer` into `consensus/types` * Rename RawBlobs, Blobs, and BlobRoots * Use `BlobRoots` type alias * Update error message. Co-authored-by: realbigsean <seananderson33@GMAIL.com> * update builder bid type # Conflicts: # consensus/types/src/builder_bid.rs * Fix lint * remove generic from builder bid --------- Co-authored-by: realbigsean <seananderson33@gmail.com>
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use eth2::types::FullPayloadContents;
|
|
use lru::LruCache;
|
|
use parking_lot::Mutex;
|
|
use tree_hash::TreeHash;
|
|
use types::{EthSpec, Hash256};
|
|
|
|
pub const DEFAULT_PAYLOAD_CACHE_SIZE: usize = 10;
|
|
|
|
/// A cache mapping execution payloads by tree hash roots.
|
|
pub struct PayloadCache<T: EthSpec> {
|
|
payloads: Mutex<LruCache<PayloadCacheId, FullPayloadContents<T>>>,
|
|
}
|
|
|
|
#[derive(Hash, PartialEq, Eq)]
|
|
struct PayloadCacheId(Hash256);
|
|
|
|
impl<T: EthSpec> Default for PayloadCache<T> {
|
|
fn default() -> Self {
|
|
PayloadCache {
|
|
payloads: Mutex::new(LruCache::new(DEFAULT_PAYLOAD_CACHE_SIZE)),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T: EthSpec> PayloadCache<T> {
|
|
pub fn put(&self, payload: FullPayloadContents<T>) -> Option<FullPayloadContents<T>> {
|
|
let root = payload.payload_ref().tree_hash_root();
|
|
self.payloads.lock().put(PayloadCacheId(root), payload)
|
|
}
|
|
|
|
pub fn pop(&self, root: &Hash256) -> Option<FullPayloadContents<T>> {
|
|
self.payloads.lock().pop(&PayloadCacheId(*root))
|
|
}
|
|
|
|
pub fn get(&self, hash: &Hash256) -> Option<FullPayloadContents<T>> {
|
|
self.payloads.lock().get(&PayloadCacheId(*hash)).cloned()
|
|
}
|
|
}
|