From cdc3fe9ea0b2a25c57bcb3e982e3826008ddc3da Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 19 Jun 2020 12:34:30 +0200 Subject: [PATCH 1/5] Initial commit Forked at: d735e4d0b5378c227f81a5127a1d4544de112fd8 No parent branch. From a9e9820e124571f73d3e498e969a74d01fd3fe96 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 19 Jun 2020 12:34:46 +0200 Subject: [PATCH 2/5] Errors if slot_duration is zero --- client/consensus/babe/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 3d14f0a7bf08d..e66fe9d0cd71f 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -285,7 +285,7 @@ impl Config { C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi, { trace!(target: "babe", "Getting slot duration"); - match sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| { + let config = match sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| { let has_api_v1 = a.has_api_with::, _>( &b, |v| v == 1, )?; @@ -310,7 +310,15 @@ impl Config { warn!(target: "babe", "Failed to get slot duration"); Err(s) } + }?; + + if config.slot_duration == 0 { + return Err(sp_blockchain::Error::Msg( + "Invalid value for slot_duration: the value must be greater than 0.".to_string(), + )) } + + Ok(config) } } From f7115c05c603e43c765e29f61700852a05eff4ac Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 19 Jun 2020 13:58:39 +0200 Subject: [PATCH 3/5] Errors if slot_duration is zero --- client/consensus/slots/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index fe1c6bab7b579..f74520e9e8508 100644 --- a/client/consensus/slots/src/lib.rs +++ b/client/consensus/slots/src/lib.rs @@ -455,7 +455,7 @@ impl SlotDuration { CB: FnOnce(ApiRef, &BlockId) -> sp_blockchain::Result, T: SlotData + Encode + Decode + Debug, { - match client.get_aux(T::SLOT_KEY)? { + let slot_duration = match client.get_aux(T::SLOT_KEY)? { Some(v) => ::decode(&mut &v[..]) .map(SlotDuration) .map_err(|_| { @@ -479,7 +479,15 @@ impl SlotDuration { 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.".to_string(), + )) } + + Ok(slot_duration) } /// Returns slot data value. From a858a6352c82295f741f3ba684253bf284bab341 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 19 Jun 2020 13:58:53 +0200 Subject: [PATCH 4/5] Revert "Errors if slot_duration is zero" This reverts commit a9e9820e124571f73d3e498e969a74d01fd3fe96. --- client/consensus/babe/src/lib.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index e66fe9d0cd71f..3d14f0a7bf08d 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -285,7 +285,7 @@ impl Config { C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi, { trace!(target: "babe", "Getting slot duration"); - let config = match sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| { + match sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| { let has_api_v1 = a.has_api_with::, _>( &b, |v| v == 1, )?; @@ -310,15 +310,7 @@ impl Config { warn!(target: "babe", "Failed to get slot duration"); Err(s) } - }?; - - if config.slot_duration == 0 { - return Err(sp_blockchain::Error::Msg( - "Invalid value for slot_duration: the value must be greater than 0.".to_string(), - )) } - - Ok(config) } } From 5b852dd7c35805f936c4688bc21944cf9311bb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 19 Jun 2020 14:03:12 +0200 Subject: [PATCH 5/5] Update client/consensus/slots/src/lib.rs --- client/consensus/slots/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index f74520e9e8508..950f83fbced18 100644 --- a/client/consensus/slots/src/lib.rs +++ b/client/consensus/slots/src/lib.rs @@ -483,7 +483,7 @@ impl SlotDuration { if slot_duration.slot_duration() == 0 { return Err(sp_blockchain::Error::Msg( - "Invalid value for slot_duration: the value must be greater than 0.".to_string(), + "Invalid value for slot_duration: the value must be greater than 0.".into(), )) }