Minor fixes (#2038)
Fixes a couple of low hanging fruits. - Fixes #2037 - `validators-dir` and `secrets-dir` flags don't really need to depend upon each other - Fixes #2006 and Fixes #1995
This commit is contained in:
parent
d8cda2d86e
commit
482695142a
@ -813,7 +813,7 @@ mod test {
|
|||||||
.write()
|
.write()
|
||||||
.cache
|
.cache
|
||||||
.insert_log(log.clone())
|
.insert_log(log.clone())
|
||||||
.expect("should insert log")
|
.expect("should insert log");
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -102,6 +102,12 @@ impl Default for DepositCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum DepositCacheInsertOutcome {
|
||||||
|
Inserted,
|
||||||
|
Duplicate,
|
||||||
|
}
|
||||||
|
|
||||||
impl DepositCache {
|
impl DepositCache {
|
||||||
/// Create new `DepositCache` given block number at which deposit
|
/// Create new `DepositCache` given block number at which deposit
|
||||||
/// contract was deployed.
|
/// contract was deployed.
|
||||||
@ -146,7 +152,7 @@ impl DepositCache {
|
|||||||
///
|
///
|
||||||
/// - If a log with index `log.index - 1` is not already present in `self` (ignored when empty).
|
/// - If a log with index `log.index - 1` is not already present in `self` (ignored when empty).
|
||||||
/// - If a log with `log.index` is already known, but the given `log` is distinct to it.
|
/// - If a log with `log.index` is already known, but the given `log` is distinct to it.
|
||||||
pub fn insert_log(&mut self, log: DepositLog) -> Result<(), Error> {
|
pub fn insert_log(&mut self, log: DepositLog) -> Result<DepositCacheInsertOutcome, Error> {
|
||||||
match log.index.cmp(&(self.logs.len() as u64)) {
|
match log.index.cmp(&(self.logs.len() as u64)) {
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
let deposit = log.deposit_data.tree_hash_root();
|
let deposit = log.deposit_data.tree_hash_root();
|
||||||
@ -156,11 +162,11 @@ impl DepositCache {
|
|||||||
.push_leaf(deposit)
|
.push_leaf(deposit)
|
||||||
.map_err(Error::DepositTreeError)?;
|
.map_err(Error::DepositTreeError)?;
|
||||||
self.deposit_roots.push(self.deposit_tree.root());
|
self.deposit_roots.push(self.deposit_tree.root());
|
||||||
Ok(())
|
Ok(DepositCacheInsertOutcome::Inserted)
|
||||||
}
|
}
|
||||||
Ordering::Less => {
|
Ordering::Less => {
|
||||||
if self.logs[log.index as usize] == log {
|
if self.logs[log.index as usize] == log {
|
||||||
Ok(())
|
Ok(DepositCacheInsertOutcome::Duplicate)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::DuplicateDistinctLog(log.index))
|
Err(Error::DuplicateDistinctLog(log.index))
|
||||||
}
|
}
|
||||||
@ -314,7 +320,7 @@ pub mod tests {
|
|||||||
for i in 0..16 {
|
for i in 0..16 {
|
||||||
let mut log = example_log();
|
let mut log = example_log();
|
||||||
log.index = i;
|
log.index = i;
|
||||||
tree.insert_log(log).expect("should add consecutive logs")
|
tree.insert_log(log).expect("should add consecutive logs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,13 +331,16 @@ pub mod tests {
|
|||||||
for i in 0..4 {
|
for i in 0..4 {
|
||||||
let mut log = example_log();
|
let mut log = example_log();
|
||||||
log.index = i;
|
log.index = i;
|
||||||
tree.insert_log(log).expect("should add consecutive logs")
|
tree.insert_log(log).expect("should add consecutive logs");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add duplicate, when given is the same as the one known.
|
// Add duplicate, when given is the same as the one known.
|
||||||
let mut log = example_log();
|
let mut log = example_log();
|
||||||
log.index = 3;
|
log.index = 3;
|
||||||
assert!(tree.insert_log(log).is_ok());
|
assert_eq!(
|
||||||
|
tree.insert_log(log).unwrap(),
|
||||||
|
DepositCacheInsertOutcome::Duplicate
|
||||||
|
);
|
||||||
|
|
||||||
// Add duplicate, when given is different to the one known.
|
// Add duplicate, when given is different to the one known.
|
||||||
let mut log = example_log();
|
let mut log = example_log();
|
||||||
@ -355,7 +364,7 @@ pub mod tests {
|
|||||||
log.index = i;
|
log.index = i;
|
||||||
log.block_number = i;
|
log.block_number = i;
|
||||||
log.deposit_data.withdrawal_credentials = Hash256::from_low_u64_be(i);
|
log.deposit_data.withdrawal_credentials = Hash256::from_low_u64_be(i);
|
||||||
tree.insert_log(log).expect("should add consecutive logs")
|
tree.insert_log(log).expect("should add consecutive logs");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 0 deposits, with max deposit count.
|
// Get 0 deposits, with max deposit count.
|
||||||
@ -432,7 +441,7 @@ pub mod tests {
|
|||||||
log.index = i;
|
log.index = i;
|
||||||
log.block_number = i;
|
log.block_number = i;
|
||||||
log.deposit_data.withdrawal_credentials = Hash256::from_low_u64_be(i);
|
log.deposit_data.withdrawal_credentials = Hash256::from_low_u64_be(i);
|
||||||
tree.insert_log(log).expect("should add consecutive logs")
|
tree.insert_log(log).expect("should add consecutive logs");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range too high.
|
// Range too high.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::metrics;
|
use crate::metrics;
|
||||||
use crate::{
|
use crate::{
|
||||||
block_cache::{BlockCache, Error as BlockCacheError, Eth1Block},
|
block_cache::{BlockCache, Error as BlockCacheError, Eth1Block},
|
||||||
deposit_cache::Error as DepositCacheError,
|
deposit_cache::{DepositCacheInsertOutcome, Error as DepositCacheError},
|
||||||
http::{
|
http::{
|
||||||
get_block, get_block_number, get_chain_id, get_deposit_logs_in_range, get_network_id,
|
get_block, get_block_number, get_chain_id, get_deposit_logs_in_range, get_network_id,
|
||||||
BlockQuery, Eth1Id,
|
BlockQuery, Eth1Id,
|
||||||
@ -866,12 +866,13 @@ impl Service {
|
|||||||
.collect::<Result<Vec<_>, _>>()?
|
.collect::<Result<Vec<_>, _>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|deposit_log| {
|
.map(|deposit_log| {
|
||||||
cache
|
if let DepositCacheInsertOutcome::Inserted = cache
|
||||||
.cache
|
.cache
|
||||||
.insert_log(deposit_log)
|
.insert_log(deposit_log)
|
||||||
.map_err(Error::FailedToInsertDeposit)?;
|
.map_err(Error::FailedToInsertDeposit)?
|
||||||
|
{
|
||||||
logs_imported += 1;
|
logs_imported += 1;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
@ -521,7 +521,7 @@ mod deposit_tree {
|
|||||||
.map(|raw| raw.to_deposit_log(spec).expect("should parse deposit log"))
|
.map(|raw| raw.to_deposit_log(spec).expect("should parse deposit log"))
|
||||||
.inspect(|log| {
|
.inspect(|log| {
|
||||||
tree.insert_log(log.clone())
|
tree.insert_log(log.clone())
|
||||||
.expect("should add consecutive logs")
|
.expect("should add consecutive logs");
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use target_info::Target;
|
|||||||
///
|
///
|
||||||
/// `Lighthouse/v0.2.0-1419501f2+`
|
/// `Lighthouse/v0.2.0-1419501f2+`
|
||||||
pub const VERSION: &str = git_version!(
|
pub const VERSION: &str = git_version!(
|
||||||
args = ["--always", "--dirty=+"],
|
args = ["--always", "--dirty=+", "--abbrev=7"],
|
||||||
prefix = "Lighthouse/v1.0.3-",
|
prefix = "Lighthouse/v1.0.3-",
|
||||||
fallback = "unknown"
|
fallback = "unknown"
|
||||||
);
|
);
|
||||||
|
@ -37,7 +37,6 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
)
|
)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.conflicts_with("datadir")
|
.conflicts_with("datadir")
|
||||||
.requires("secrets-dir")
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("secrets-dir")
|
Arg::with_name("secrets-dir")
|
||||||
@ -51,7 +50,6 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
)
|
)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.conflicts_with("datadir")
|
.conflicts_with("datadir")
|
||||||
.requires("validators-dir"),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("delete-lockfiles")
|
Arg::with_name("delete-lockfiles")
|
||||||
|
@ -82,10 +82,10 @@ impl Config {
|
|||||||
validator_dir = Some(base_dir.join(DEFAULT_VALIDATOR_DIR));
|
validator_dir = Some(base_dir.join(DEFAULT_VALIDATOR_DIR));
|
||||||
secrets_dir = Some(base_dir.join(DEFAULT_SECRET_DIR));
|
secrets_dir = Some(base_dir.join(DEFAULT_SECRET_DIR));
|
||||||
}
|
}
|
||||||
if cli_args.value_of("validators-dir").is_some()
|
if cli_args.value_of("validators-dir").is_some() {
|
||||||
&& cli_args.value_of("secrets-dir").is_some()
|
|
||||||
{
|
|
||||||
validator_dir = Some(parse_required(cli_args, "validators-dir")?);
|
validator_dir = Some(parse_required(cli_args, "validators-dir")?);
|
||||||
|
}
|
||||||
|
if cli_args.value_of("secrets-dir").is_some() {
|
||||||
secrets_dir = Some(parse_required(cli_args, "secrets-dir")?);
|
secrets_dir = Some(parse_required(cli_args, "secrets-dir")?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user