Skip to content

Add common intervals for ValidatorService and LeanChainService #683

@syjn99

Description

@syjn99

Describe the feature

#679 introduced redundant code block in ValidatorService and LeanChainService.

// TODO: Duplicate clock logic from ValidatorService. May need to refactor later.
// Get the Lean network specification.
let network_spec = lean_network_spec();
let seconds_per_slot = network_spec.seconds_per_slot;
let genesis_time = network_spec.genesis_time;
info!("LeanChainService started with genesis_time={genesis_time}");
// Calculate the genesis instant from the genesis time (in seconds).
let genesis_instant = UNIX_EPOCH + Duration::from_secs(genesis_time);
// Assume genesis time is "always" in the future,
// as we don't support syncing features yet.
let interval_start = Instant::now()
+ genesis_instant
.duration_since(SystemTime::now())
.expect("Genesis time is in the past");
let mut tick_count = 0u64;
let mut interval = interval_at(
interval_start,
Duration::from_secs(seconds_per_slot / INTERVALS_PER_SLOT),
);
interval.set_missed_tick_behavior(MissedTickBehavior::Burst);

// TODO: Duplicate clock logic from LeanChainService. May need to refactor later.
// Get the Lean network specification.
let network_spec = lean_network_spec();
let seconds_per_slot = network_spec.seconds_per_slot;
let genesis_time = network_spec.genesis_time;
info!(
"ValidatorService started with {} validator(s), genesis_time={genesis_time}",
self.keystores.len()
);
// Calculate the genesis instant from the genesis time (in seconds).
let genesis_instant = UNIX_EPOCH + Duration::from_secs(genesis_time);
// Assume genesis time is "always" in the future,
// as we don't support syncing features yet.
let interval_start = Instant::now()
+ genesis_instant
.duration_since(SystemTime::now())
.expect("Genesis time is in the past");
let mut tick_count = 0u64;
let mut interval = interval_at(
interval_start,
Duration::from_secs(seconds_per_slot / INTERVALS_PER_SLOT),
);
interval.set_missed_tick_behavior(MissedTickBehavior::Burst);

As I wrote in the comment, it'll be great to have common way to "tick" by a global clock.

Additional context

Shariq's comment: #679 (comment)

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions