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

Commit

Permalink
More descriptive error message when invalid slot duration is used (#6430
Browse files Browse the repository at this point in the history
)

* Initial commit

Forked at: d735e4d
No parent branch.

* Errors if slot_duration is zero

* Errors if slot_duration is zero

* Revert "Errors if slot_duration is zero"

This reverts commit a9e9820.

* Update client/consensus/slots/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
  • Loading branch information
cecton and bkchr committed Jun 19, 2020
1 parent 2bb79cb commit a2c493d
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit a2c493d

Please sign in to comment.