Skip to content

Commit

Permalink
Make slasher update period configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Sep 11, 2020
1 parent 5725fde commit f6c1ce6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
11 changes: 11 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
)
.value_name("DIR")
.takes_value(true)
.requires("slasher")
)
.arg(
Arg::with_name("slasher-update-period")
.long("slasher-update-period")
.help(
"Configure how often the slasher runs batch processing."
)
.value_name("SECONDS")
.requires("slasher")
.takes_value(true)
)
}
10 changes: 9 additions & 1 deletion beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,15 @@ pub fn get_config<E: EthSpec>(
} else {
client_config.data_dir.join("slasher_db")
};
client_config.slasher = Some(slasher::Config::new(slasher_dir));

let mut slasher_config = slasher::Config::new(slasher_dir);

if let Some(update_period) = clap_utils::parse_optional(cli_args, "slasher-update-period")?
{
slasher_config.update_period = update_period;
}

client_config.slasher = Some(slasher_config);
}

Ok(client_config)
Expand Down
4 changes: 4 additions & 0 deletions slasher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use types::{Epoch, EthSpec, IndexedAttestation};
pub const DEFAULT_CHUNK_SIZE: usize = 16;
pub const DEFAULT_VALIDATOR_CHUNK_SIZE: usize = 256;
pub const DEFAULT_HISTORY_LENGTH: usize = 54_000;
pub const DEFAULT_UPDATE_PERIOD: u64 = 12;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
Expand All @@ -14,6 +15,8 @@ pub struct Config {
pub validator_chunk_size: usize,
/// Number of epochs of history to keep.
pub history_length: usize,
/// Update frequency in seconds.
pub update_period: u64,
}

impl Config {
Expand All @@ -23,6 +26,7 @@ impl Config {
chunk_size: DEFAULT_CHUNK_SIZE,
validator_chunk_size: DEFAULT_VALIDATOR_CHUNK_SIZE,
history_length: DEFAULT_HISTORY_LENGTH,
update_period: DEFAULT_UPDATE_PERIOD,
}
}

Expand Down
3 changes: 2 additions & 1 deletion slasher/src/slasher_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ impl SlasherServer {
// don't need to burden them with more work (we can wait).
let (sender, receiver) = sync_channel(1);
let log = slasher.log.clone();
let update_period = slasher.config().update_period;

executor.spawn(
async move {
// FIXME(sproul): read slot time from config, align to some fraction of each slot
let slot_clock = Arc::new(slot_clock);
let mut interval = interval_at(Instant::now(), Duration::from_secs(12));
let mut interval = interval_at(Instant::now(), Duration::from_secs(update_period));
while interval.next().await.is_some() {
if let Some(current_slot) = slot_clock.clone().now() {
let current_epoch = current_slot.epoch(E::slots_per_epoch());
Expand Down

0 comments on commit f6c1ce6

Please sign in to comment.