Represent slots in secs instead of millisecs (#2163)

## Issue Addressed

NA

## Proposed Changes

Copied from #2083, changes the config milliseconds_per_slot to seconds_per_slot to avoid errors when slot duration is not a multiple of a second. To avoid deserializing old serialized data (with milliseconds instead of seconds) the Serialize and Deserialize derive got removed from the Spec struct (isn't currently used anyway).

This PR replaces #2083 for the purpose of fixing a merge conflict without requiring the input of @blacktemplar.

## Additional Info

NA


Co-authored-by: blacktemplar <blacktemplar@a1.net>
This commit is contained in:
Paul Hauner
2021-01-19 09:39:51 +00:00
parent 46cb6e204c
commit d9f940613f
24 changed files with 58 additions and 132 deletions

View File

@@ -322,13 +322,13 @@ where
.beacon_chain
.clone()
.ok_or("node timer requires a beacon chain")?;
let milliseconds_per_slot = self
let seconds_per_slot = self
.chain_spec
.as_ref()
.ok_or("node timer requires a chain spec")?
.milliseconds_per_slot;
.seconds_per_slot;
spawn_timer(context.executor, beacon_chain, milliseconds_per_slot)
spawn_timer(context.executor, beacon_chain, seconds_per_slot)
.map_err(|e| format!("Unable to start node timer: {}", e))?;
Ok(self)
@@ -381,17 +381,17 @@ where
.network_globals
.clone()
.ok_or("slot_notifier requires a libp2p network")?;
let milliseconds_per_slot = self
let seconds_per_slot = self
.chain_spec
.as_ref()
.ok_or("slot_notifier requires a chain spec")?
.milliseconds_per_slot;
.seconds_per_slot;
spawn_notifier(
context.executor,
beacon_chain,
network_globals,
milliseconds_per_slot,
seconds_per_slot,
)
.map_err(|e| format!("Unable to start slot notifier: {}", e))?;
@@ -685,7 +685,7 @@ where
let slot_clock = SystemTimeSlotClock::new(
spec.genesis_slot,
Duration::from_secs(genesis_time),
Duration::from_millis(spec.milliseconds_per_slot),
Duration::from_secs(spec.seconds_per_slot),
);
self.slot_clock = Some(slot_clock);

View File

@@ -25,9 +25,9 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
executor: task_executor::TaskExecutor,
beacon_chain: Arc<BeaconChain<T>>,
network: Arc<NetworkGlobals<T::EthSpec>>,
milliseconds_per_slot: u64,
seconds_per_slot: u64,
) -> Result<(), String> {
let slot_duration = Duration::from_millis(milliseconds_per_slot);
let slot_duration = Duration::from_secs(seconds_per_slot);
let duration_to_next_slot = beacon_chain
.slot_clock
.duration_to_next_slot()