mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-08 20:11:22 +00:00
6c2d8b2262
## Issue Addressed https://github.com/sigp/lighthouse/issues/3091 Extends https://github.com/sigp/lighthouse/pull/3062, adding pre-bellatrix block support on blinded endpoints and allowing the normal proposal flow (local payload construction) on blinded endpoints. This resulted in better fallback logic because the VC will not have to switch endpoints on failure in the BN <> Builder API, the BN can just fallback immediately and without repeating block processing that it shouldn't need to. We can also keep VC fallback from the VC<>BN API's blinded endpoint to full endpoint. ## Proposed Changes - Pre-bellatrix blocks on blinded endpoints - Add a new `PayloadCache` to the execution layer - Better fallback-from-builder logic ## Todos - [x] Remove VC transition logic - [x] Add logic to only enable builder flow after Merge transition finalization - [x] Tests - [x] Fix metrics - [x] Rustdocs Co-authored-by: Mac L <mjladson@pm.me> Co-authored-by: realbigsean <sean@sigmaprime.io>
34 lines
966 B
Rust
34 lines
966 B
Rust
use lru::LruCache;
|
|
use parking_lot::Mutex;
|
|
use tree_hash::TreeHash;
|
|
use types::{EthSpec, ExecutionPayload, 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, ExecutionPayload<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: ExecutionPayload<T>) -> Option<ExecutionPayload<T>> {
|
|
let root = payload.tree_hash_root();
|
|
self.payloads.lock().put(PayloadCacheId(root), payload)
|
|
}
|
|
|
|
pub fn pop(&self, root: &Hash256) -> Option<ExecutionPayload<T>> {
|
|
self.payloads.lock().pop(&PayloadCacheId(*root))
|
|
}
|
|
}
|