Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

More descriptive error message when invalid slot duration is used #6430

Merged
merged 5 commits into from
Jun 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl<T: Clone> SlotDuration<T> {
CB: FnOnce(ApiRef<C::Api>, &BlockId<B>) -> sp_blockchain::Result<T>,
T: SlotData + Encode + Decode + Debug,
{
match client.get_aux(T::SLOT_KEY)? {
let slot_duration = match client.get_aux(T::SLOT_KEY)? {
Some(v) => <T as codec::Decode>::decode(&mut &v[..])
.map(SlotDuration)
.map_err(|_| {
Expand All @@ -479,7 +479,15 @@ impl<T: Clone> SlotDuration<T> {

Ok(SlotDuration(genesis_slot_duration))
}
}?;

if slot_duration.slot_duration() == 0 {
return Err(sp_blockchain::Error::Msg(
"Invalid value for slot_duration: the value must be greater than 0.".into(),
))
}

Ok(slot_duration)
}

/// Returns slot data value.
Expand Down