Skip to content
Snippets Groups Projects
Commit 5ae3c8d0 authored by Éloïs's avatar Éloïs
Browse files

feat(cert): add genesis param apply_cert_period_at_genesis

parent d25fc2e1
No related branches found
No related tags found
1 merge request!24feat: make gdev parameters dynamic
This commit is part of merge request !24. Comments created here will be created in the context of that merge request.
...@@ -140,6 +140,7 @@ fn devnet_genesis( ...@@ -140,6 +140,7 @@ fn devnet_genesis(
.collect(), .collect(),
}, },
strong_cert: StrongCertConfig { strong_cert: StrongCertConfig {
apply_cert_period_at_genesis: false,
certs_by_issuer: clique_wot( certs_by_issuer: clique_wot(
initial_identities.len(), initial_identities.len(),
gdev_runtime::parameters::ValidityPeriod::get(), gdev_runtime::parameters::ValidityPeriod::get(),
......
...@@ -128,6 +128,7 @@ fn devnet_genesis( ...@@ -128,6 +128,7 @@ fn devnet_genesis(
.collect(), .collect(),
}, },
strong_cert: StrongCertConfig { strong_cert: StrongCertConfig {
apply_cert_period_at_genesis: false,
certs_by_issuer: clique_wot( certs_by_issuer: clique_wot(
initial_identities.len(), initial_identities.len(),
gtest_runtime::parameters::ValidityPeriod::get(), gtest_runtime::parameters::ValidityPeriod::get(),
...@@ -333,6 +334,7 @@ fn testnet_genesis( ...@@ -333,6 +334,7 @@ fn testnet_genesis(
.collect(), .collect(),
}, },
strong_cert: StrongCertConfig { strong_cert: StrongCertConfig {
apply_cert_period_at_genesis: false,
certs_by_issuer: clique_wot( certs_by_issuer: clique_wot(
initial_identities.len(), initial_identities.len(),
gtest_runtime::parameters::ValidityPeriod::get(), gtest_runtime::parameters::ValidityPeriod::get(),
......
...@@ -39,6 +39,7 @@ pub mod pallet { ...@@ -39,6 +39,7 @@ pub mod pallet {
use super::*; use super::*;
use frame_support::pallet_prelude::*; use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*; use frame_system::pallet_prelude::*;
use sp_runtime::traits::Saturating;
use sp_std::collections::btree_map::BTreeMap; use sp_std::collections::btree_map::BTreeMap;
/// The current storage version. /// The current storage version.
...@@ -89,6 +90,7 @@ pub mod pallet { ...@@ -89,6 +90,7 @@ pub mod pallet {
#[pallet::genesis_config] #[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> { pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub apply_cert_period_at_genesis: bool,
pub certs_by_issuer: BTreeMap<T::IdtyIndex, BTreeMap<T::IdtyIndex, T::BlockNumber>>, pub certs_by_issuer: BTreeMap<T::IdtyIndex, BTreeMap<T::IdtyIndex, T::BlockNumber>>,
} }
...@@ -96,6 +98,7 @@ pub mod pallet { ...@@ -96,6 +98,7 @@ pub mod pallet {
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> { impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self { fn default() -> Self {
Self { Self {
apply_cert_period_at_genesis: false,
certs_by_issuer: Default::default(), certs_by_issuer: Default::default(),
} }
} }
...@@ -152,13 +155,14 @@ pub mod pallet { ...@@ -152,13 +155,14 @@ pub mod pallet {
.or_default() .or_default()
.push((*issuer, *receiver)); .push((*issuer, *receiver));
use sp_runtime::traits::Saturating as _; if self.apply_cert_period_at_genesis {
let issuer_next_issuable_on = removable_on let issuer_next_issuable_on = removable_on
.saturating_add(T::CertPeriod::get()) .saturating_add(T::CertPeriod::get())
.saturating_sub(T::ValidityPeriod::get()); .saturating_sub(T::ValidityPeriod::get());
if let Some(cert_meta) = cert_meta_by_issuer.get_mut(issuer) { if let Some(cert_meta) = cert_meta_by_issuer.get_mut(issuer) {
if cert_meta.next_issuable_on < issuer_next_issuable_on { if cert_meta.next_issuable_on < issuer_next_issuable_on {
cert_meta.next_issuable_on = issuer_next_issuable_on; cert_meta.next_issuable_on = issuer_next_issuable_on;
}
} }
} }
let renewable_on = removable_on.saturating_sub( let renewable_on = removable_on.saturating_sub(
......
...@@ -25,6 +25,7 @@ use sp_std::collections::btree_map::BTreeMap; ...@@ -25,6 +25,7 @@ use sp_std::collections::btree_map::BTreeMap;
#[test] #[test]
fn test_must_receive_cert_before_can_issue() { fn test_must_receive_cert_before_can_issue() {
new_test_ext(DefaultCertificationConfig { new_test_ext(DefaultCertificationConfig {
apply_cert_period_at_genesis: true,
certs_by_issuer: BTreeMap::new(), certs_by_issuer: BTreeMap::new(),
}) })
.execute_with(|| { .execute_with(|| {
...@@ -38,6 +39,7 @@ fn test_must_receive_cert_before_can_issue() { ...@@ -38,6 +39,7 @@ fn test_must_receive_cert_before_can_issue() {
#[test] #[test]
fn test_genesis_build() { fn test_genesis_build() {
new_test_ext(DefaultCertificationConfig { new_test_ext(DefaultCertificationConfig {
apply_cert_period_at_genesis: true,
certs_by_issuer: btreemap![ certs_by_issuer: btreemap![
0 => btreemap![ 0 => btreemap![
1 => 10, 1 => 10,
...@@ -111,6 +113,7 @@ fn test_genesis_build() { ...@@ -111,6 +113,7 @@ fn test_genesis_build() {
#[test] #[test]
fn test_cert_period() { fn test_cert_period() {
new_test_ext(DefaultCertificationConfig { new_test_ext(DefaultCertificationConfig {
apply_cert_period_at_genesis: true,
certs_by_issuer: btreemap![0 => btreemap![1 => 10]], certs_by_issuer: btreemap![0 => btreemap![1 => 10]],
}) })
.execute_with(|| { .execute_with(|| {
...@@ -133,6 +136,7 @@ fn test_cert_period() { ...@@ -133,6 +136,7 @@ fn test_cert_period() {
#[test] #[test]
fn test_renewable_period() { fn test_renewable_period() {
new_test_ext(DefaultCertificationConfig { new_test_ext(DefaultCertificationConfig {
apply_cert_period_at_genesis: true,
certs_by_issuer: btreemap![0 => btreemap![1 => 10]], certs_by_issuer: btreemap![0 => btreemap![1 => 10]],
}) })
.execute_with(|| { .execute_with(|| {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment