Merge branch 'unstable' into off-4844

This commit is contained in:
Diva M
2023-03-02 15:38:00 -05:00
86 changed files with 1224 additions and 316 deletions

View File

@@ -307,6 +307,5 @@ define_hardcoded_nets!(
// Set to `true` if the genesis state can be found in the `built_in_network_configs`
// directory.
GENESIS_STATE_IS_KNOWN
),
(eip4844, "eip4844", GENESIS_STATE_IS_KNOWN)
)
);

View File

@@ -28,6 +28,10 @@ TERMINAL_TOTAL_DIFFICULTY: 17000000000000000
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615
# Capella
CAPELLA_FORK_VERSION: 0x90000072
CAPELLA_FORK_EPOCH: 56832
# Eip4844
EIP4844_FORK_VERSION: 0x03001020
EIP4844_FORK_EPOCH: 18446744073709551615

View File

@@ -17,8 +17,8 @@ pub const VERSION: &str = git_version!(
// NOTE: using --match instead of --exclude for compatibility with old Git
"--match=thiswillnevermatchlol"
],
prefix = "Lighthouse/v3.4.0-",
fallback = "Lighthouse/v3.4.0"
prefix = "Lighthouse/v3.5.0-",
fallback = "Lighthouse/v3.5.0"
);
/// Returns `VERSION`, but with platform information appended to the end.

View File

@@ -31,6 +31,77 @@ where
}
}
/// Inserts a key without removal of potentially expired elements.
/// Returns true if the key does not already exist.
pub fn raw_insert(&mut self, key: Key) -> bool {
// check the cache before removing elements
let is_new = self.map.insert(key.clone());
// add the new key to the list, if it doesn't already exist.
if is_new {
self.list.push_back(Element {
key,
inserted: Instant::now(),
});
} else {
let position = self
.list
.iter()
.position(|e| e.key == key)
.expect("Key is not new");
let mut element = self
.list
.remove(position)
.expect("Position is not occupied");
element.inserted = Instant::now();
self.list.push_back(element);
}
#[cfg(test)]
self.check_invariant();
is_new
}
/// Removes a key from the cache without purging expired elements. Returns true if the key
/// existed.
pub fn raw_remove(&mut self, key: &Key) -> bool {
if self.map.remove(key) {
let position = self
.list
.iter()
.position(|e| &e.key == key)
.expect("Key must exist");
self.list
.remove(position)
.expect("Position is not occupied");
true
} else {
false
}
}
/// Removes all expired elements and returns them
pub fn remove_expired(&mut self) -> Vec<Key> {
if self.list.is_empty() {
return Vec::new();
}
let mut removed_elements = Vec::new();
let now = Instant::now();
// remove any expired results
while let Some(element) = self.list.pop_front() {
if element.inserted + self.ttl > now {
self.list.push_front(element);
break;
}
self.map.remove(&element.key);
removed_elements.push(element.key);
}
#[cfg(test)]
self.check_invariant();
removed_elements
}
// Inserts a new key. It first purges expired elements to do so.
//
// If the key was not present this returns `true`. If the value was already present this

View File

@@ -1,6 +1,7 @@
use super::SlotClock;
use parking_lot::RwLock;
use std::convert::TryInto;
use std::sync::Arc;
use std::time::Duration;
use types::Slot;
@@ -10,7 +11,7 @@ pub struct ManualSlotClock {
/// Duration from UNIX epoch to genesis.
genesis_duration: Duration,
/// Duration from UNIX epoch to right now.
current_time: RwLock<Duration>,
current_time: Arc<RwLock<Duration>>,
/// The length of each slot.
slot_duration: Duration,
}
@@ -20,7 +21,7 @@ impl Clone for ManualSlotClock {
ManualSlotClock {
genesis_slot: self.genesis_slot,
genesis_duration: self.genesis_duration,
current_time: RwLock::new(*self.current_time.read()),
current_time: Arc::clone(&self.current_time),
slot_duration: self.slot_duration,
}
}
@@ -90,7 +91,7 @@ impl SlotClock for ManualSlotClock {
Self {
genesis_slot,
current_time: RwLock::new(genesis_duration),
current_time: Arc::new(RwLock::new(genesis_duration)),
genesis_duration,
slot_duration,
}