mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 02:12:33 +00:00
Cache deposit signature verification (#1298)
* Bake in Altona testnet (without genesis state) * Add sig verification, without optimization * Start integration with genesis service * Update config.yml * Fix eth2_testnet_config test * Stop using default spec in genesis * Fix lcli compile error * Update min genesis time * Fix typo
This commit is contained in:
@@ -14,6 +14,7 @@ use std::ops::{Range, RangeInclusive};
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tokio::time::{interval_at, Duration, Instant};
|
||||
use types::ChainSpec;
|
||||
|
||||
const STANDARD_TIMEOUT_MILLIS: u64 = 15_000;
|
||||
|
||||
@@ -130,14 +131,15 @@ pub struct Service {
|
||||
|
||||
impl Service {
|
||||
/// Creates a new service. Does not attempt to connect to the eth1 node.
|
||||
pub fn new(config: Config, log: Logger) -> Self {
|
||||
pub fn new(config: Config, log: Logger, spec: ChainSpec) -> Self {
|
||||
Self {
|
||||
inner: Arc::new(Inner {
|
||||
block_cache: <_>::default(),
|
||||
deposit_cache: RwLock::new(DepositUpdater::new(
|
||||
config.deposit_contract_deploy_block,
|
||||
)),
|
||||
config: RwLock::new(config),
|
||||
..Inner::default()
|
||||
spec,
|
||||
}),
|
||||
log,
|
||||
}
|
||||
@@ -149,8 +151,13 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Recover the deposit and block caches from encoded bytes.
|
||||
pub fn from_bytes(bytes: &[u8], config: Config, log: Logger) -> Result<Self, String> {
|
||||
let inner = Inner::from_bytes(bytes, config)?;
|
||||
pub fn from_bytes(
|
||||
bytes: &[u8],
|
||||
config: Config,
|
||||
log: Logger,
|
||||
spec: ChainSpec,
|
||||
) -> Result<Self, String> {
|
||||
let inner = Inner::from_bytes(bytes, config, spec)?;
|
||||
Ok(Self {
|
||||
inner: Arc::new(inner),
|
||||
log,
|
||||
@@ -194,6 +201,14 @@ impl Service {
|
||||
self.inner.block_cache.read().lowest_block_number()
|
||||
}
|
||||
|
||||
/// Returns the highest block that is present in both the deposit and block caches.
|
||||
pub fn highest_safe_block(&self) -> Option<u64> {
|
||||
let block_cache = self.blocks().read().highest_block_number()?;
|
||||
let deposit_cache = self.deposits().read().last_processed_block?;
|
||||
|
||||
Some(std::cmp::min(block_cache, deposit_cache))
|
||||
}
|
||||
|
||||
/// Returns the number of currently cached blocks.
|
||||
pub fn block_cache_len(&self) -> usize {
|
||||
self.blocks().read().len()
|
||||
@@ -204,6 +219,25 @@ impl Service {
|
||||
self.deposits().read().cache.len()
|
||||
}
|
||||
|
||||
/// Returns the number of deposits with valid signatures that have been observed.
|
||||
pub fn get_valid_signature_count(&self) -> Option<usize> {
|
||||
self.deposits()
|
||||
.read()
|
||||
.cache
|
||||
.get_valid_signature_count(self.highest_safe_block()?)
|
||||
}
|
||||
|
||||
/// Returns the number of deposits with valid signatures that have been observed up to and
|
||||
/// including the block at `block_number`.
|
||||
///
|
||||
/// Returns `None` if the `block_number` is zero or prior to contract deployment.
|
||||
pub fn get_valid_signature_count_at_block(&self, block_number: u64) -> Option<usize> {
|
||||
self.deposits()
|
||||
.read()
|
||||
.cache
|
||||
.get_valid_signature_count(block_number)
|
||||
}
|
||||
|
||||
/// Read the service's configuration.
|
||||
pub fn config(&self) -> RwLockReadGuard<Config> {
|
||||
self.inner.config.read()
|
||||
@@ -402,9 +436,11 @@ impl Service {
|
||||
log_chunk
|
||||
.into_iter()
|
||||
.map(|raw_log| {
|
||||
DepositLog::from_log(&raw_log).map_err(|error| Error::FailedToParseDepositLog {
|
||||
block_range: block_range.clone(),
|
||||
error,
|
||||
DepositLog::from_log(&raw_log, service.inner.spec()).map_err(|error| {
|
||||
Error::FailedToParseDepositLog {
|
||||
block_range: block_range.clone(),
|
||||
error,
|
||||
}
|
||||
})
|
||||
})
|
||||
// Return early if any of the logs cannot be parsed.
|
||||
|
||||
Reference in New Issue
Block a user