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

mod(cert): remove rule CertRenewablePeriod

parent 8685766d
No related branches found
No related tags found
1 merge request!87Remove useless rules RenewablePeriod and CertRenewablePeriod
Showing
with 3 additions and 96 deletions
......@@ -23,7 +23,6 @@
"cert_period": 15,
"cert_max_by_issuer": 10,
"cert_min_received_cert_to_issue_cert": 2,
"cert_renewable_period": 50,
"cert_validity_period": 1000,
"idty_confirm_period": 40,
"idty_creation_period": 50,
......@@ -35,7 +34,6 @@
"smith_cert_period": 15,
"smith_cert_max_by_issuer": 8,
"smith_cert_min_received_cert_to_issue_cert": 2,
"smith_cert_renewable_period": 50,
"smith_cert_validity_period": 1000,
"smith_membership_period": 1000,
"smith_membership_renewable_period": 20,
......
......@@ -28,7 +28,6 @@
"cert_period": 15,
"cert_max_by_issuer": 10,
"cert_min_received_cert_to_issue_cert": 2,
"cert_renewable_period": 50,
"cert_validity_period": 1000,
"idty_confirm_period": 40,
"idty_creation_period": 50,
......@@ -40,7 +39,6 @@
"smith_cert_period": 15,
"smith_cert_max_by_issuer": 8,
"smith_cert_min_received_cert_to_issue_cert": 2,
"smith_cert_renewable_period": 50,
"smith_cert_validity_period": 1000,
"smith_membership_period": 1000,
"smith_membership_renewable_period": 20,
......
......@@ -309,7 +309,6 @@ fn gen_genesis_for_local_chain(
cert_period: 15,
cert_max_by_issuer: 10,
cert_min_received_cert_to_issue_cert: 2,
cert_renewable_period: 50,
cert_validity_period,
idty_confirm_period: 40,
idty_creation_period: 50,
......@@ -321,7 +320,6 @@ fn gen_genesis_for_local_chain(
smith_cert_period: 15,
smith_cert_max_by_issuer: 8,
smith_cert_min_received_cert_to_issue_cert: 2,
smith_cert_renewable_period: 50,
smith_cert_validity_period: 1_000,
smith_membership_period,
smith_membership_renewable_period: 50,
......
......@@ -83,9 +83,6 @@ pub mod pallet {
/// Handler for Removed event
type OnRemovedCert: OnRemovedCert<Self::IdtyIndex>;
#[pallet::constant]
/// Duration after which a certification is renewable
type CertRenewablePeriod: Get<Self::BlockNumber>;
#[pallet::constant]
/// Duration of validity of a certification
type ValidityPeriod: Get<Self::BlockNumber>;
}
......@@ -169,15 +166,11 @@ pub mod pallet {
}
}
}
let renewable_on = removable_on.saturating_sub(
T::ValidityPeriod::get().saturating_sub(T::CertRenewablePeriod::get()),
);
<StorageCertsByIssuer<T, I>>::insert(
issuer,
receiver,
CertValue {
renewable_on,
removable_on: *removable_on,
},
);
......@@ -274,8 +267,6 @@ pub mod pallet {
NotEnoughCertReceived,
/// This identity has already issued a certification too recently
NotRespectCertPeriod,
/// This certification has already been issued or renewed recently
NotRespectRenewablePeriod,
/// Receiver not found
ReceiverNotFound,
}
......@@ -302,7 +293,7 @@ pub mod pallet {
let block_number = frame_system::pallet::Pallet::<T>::block_number();
let create = if verify_rules {
if verify_rules {
let issuer_idty_cert_meta = <StorageIdtyCertMeta<T, I>>::get(issuer);
if issuer_idty_cert_meta.received_count == 0 {
return Err(Error::<T, I>::IdtyMustReceiveCertsBeforeCanIssue.into());
......@@ -317,22 +308,9 @@ pub mod pallet {
} else if issuer_idty_cert_meta.issued_count >= T::MaxByIssuer::get() {
return Err(Error::<T, I>::IssuedTooManyCert.into());
}
// Verify rule CertRenewablePeriod
if let Ok(CertValue { renewable_on, .. }) =
<StorageCertsByIssuer<T, I>>::try_get(issuer, receiver)
{
if renewable_on > block_number {
return Err(Error::<T, I>::NotRespectRenewablePeriod.into());
}
false
} else {
true
}
} else {
!StorageCertsByIssuer::<T, I>::contains_key(issuer, receiver)
};
let create = !StorageCertsByIssuer::<T, I>::contains_key(issuer, receiver);
Self::do_add_cert(block_number, create, issuer, receiver)
}
/// Add a new certification or renew an existing one
......@@ -370,18 +348,7 @@ pub mod pallet {
return Err(Error::<T, I>::IssuedTooManyCert.into());
}
// Verify rule CertRenewablePeriod
let create = if let Ok(CertValue { renewable_on, .. }) =
<StorageCertsByIssuer<T, I>>::try_get(issuer, receiver)
{
if renewable_on > block_number {
return Err(Error::<T, I>::NotRespectRenewablePeriod.into());
}
false
} else {
true
};
let create = !StorageCertsByIssuer::<T, I>::contains_key(issuer, receiver);
Self::do_add_cert(block_number, create, issuer, receiver)
}
......@@ -439,7 +406,6 @@ pub mod pallet {
// Write StorageCertsRemovableOn and StorageCertsByIssuer
let cert_value = CertValue {
renewable_on: block_number + T::CertRenewablePeriod::get(),
removable_on: block_number + T::ValidityPeriod::get(),
};
<StorageCertsRemovableOn<T, I>>::append(cert_value.removable_on, (issuer, receiver));
......
......@@ -94,7 +94,6 @@ impl frame_support::traits::EnsureOrigin<(Origin, IdtyIndex, IdtyIndex)> for Ens
parameter_types! {
pub const MaxByIssuer: u32 = 3;
pub const MinReceivedCertToBeAbleToIssueCert: u32 = 2;
pub const RenewablePeriod: BlockNumber = 4;
pub const CertPeriod: u64 = 2;
pub const ValidityPeriod: u64 = 10;
}
......@@ -109,7 +108,6 @@ impl pallet_certification::Config for Test {
type MinReceivedCertToBeAbleToIssueCert = MinReceivedCertToBeAbleToIssueCert;
type OnNewcert = ();
type OnRemovedCert = ();
type CertRenewablePeriod = RenewablePeriod;
type ValidityPeriod = ValidityPeriod;
}
......
......@@ -115,11 +115,6 @@ fn test_genesis_build() {
DefaultCertification::certs_removable_on(3),
Some(vec![(2, 1)]),
);
// Cert 2->0 cannot be renewed before #5
assert_eq!(
DefaultCertification::add_cert(Origin::signed(2), 0),
Err(Error::<Test, _>::NotRespectRenewablePeriod.into())
);
run_to_block(3);
// Cert 2->1 must have expired
......@@ -162,31 +157,3 @@ fn test_cert_period() {
assert_ok!(DefaultCertification::add_cert(Origin::signed(0), 3));
});
}
#[test]
fn test_renewable_period() {
new_test_ext(DefaultCertificationConfig {
apply_cert_period_at_genesis: true,
certs_by_issuer: btreemap![
0 => btreemap![1 => 10],
2 => btreemap![0 => 10],
3 => btreemap![0 => 10],
],
})
.execute_with(|| {
run_to_block(CertPeriod::get());
assert_eq!(
DefaultCertification::add_cert(Origin::signed(0), 1),
Err(Error::<Test, _>::NotRespectRenewablePeriod.into())
);
run_to_block(RenewablePeriod::get());
assert_ok!(DefaultCertification::add_cert(Origin::signed(0), 1));
run_to_block(RenewablePeriod::get() + CertPeriod::get());
assert_eq!(
DefaultCertification::add_cert(Origin::signed(0), 1),
Err(Error::<Test, _>::NotRespectRenewablePeriod.into())
);
run_to_block((2 * RenewablePeriod::get()) + 1);
assert_ok!(DefaultCertification::add_cert(Origin::signed(0), 1));
});
}
......@@ -22,7 +22,6 @@ use scale_info::TypeInfo;
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct CertValue<BlockNumber> {
pub renewable_on: BlockNumber,
pub removable_on: BlockNumber,
}
......
......@@ -40,7 +40,6 @@ pub mod types {
pub cert_period: BlockNumber,
pub cert_max_by_issuer: CertCount,
pub cert_min_received_cert_to_issue_cert: CertCount,
pub cert_renewable_period: BlockNumber,
pub cert_validity_period: BlockNumber,
pub idty_confirm_period: BlockNumber,
pub idty_creation_period: BlockNumber,
......@@ -52,7 +51,6 @@ pub mod types {
pub smith_cert_period: BlockNumber,
pub smith_cert_max_by_issuer: CertCount,
pub smith_cert_min_received_cert_to_issue_cert: CertCount,
pub smith_cert_renewable_period: BlockNumber,
pub smith_cert_validity_period: BlockNumber,
pub smith_membership_period: BlockNumber,
pub smith_membership_renewable_period: BlockNumber,
......
......@@ -154,7 +154,6 @@ impl pallet_membership::Config<Instance1> for Test {
parameter_types! {
pub const MaxByIssuer: u8 = 8;
pub const MinReceivedCertToBeAbleToIssueCert: u32 = 2;
pub const CertRenewablePeriod: u64 = 4;
pub const CertPeriod: u64 = 2;
pub const ValidityPeriod: u64 = 20;
}
......@@ -169,7 +168,6 @@ impl pallet_certification::Config<Instance1> for Test {
type MinReceivedCertToBeAbleToIssueCert = MinReceivedCertToBeAbleToIssueCert;
type OnNewcert = DuniterWot;
type OnRemovedCert = DuniterWot;
type CertRenewablePeriod = CertRenewablePeriod;
type ValidityPeriod = ValidityPeriod;
}
......@@ -213,7 +211,6 @@ impl pallet_membership::Config<Instance2> for Test {
parameter_types! {
pub const SmithsMaxByIssuer: u8 = 8;
pub const SmithsMinReceivedCertToBeAbleToIssueCert: u32 = 2;
pub const SmithsCertRenewablePeriod: u64 = 4;
pub const SmithsCertPeriod: u64 = 2;
pub const SmithsValidityPeriod: u64 = 10;
}
......@@ -228,7 +225,6 @@ impl pallet_certification::Config<Instance2> for Test {
type MinReceivedCertToBeAbleToIssueCert = SmithsMinReceivedCertToBeAbleToIssueCert;
type OnNewcert = SmithsSubWot;
type OnRemovedCert = SmithsSubWot;
type CertRenewablePeriod = SmithsCertRenewablePeriod;
type ValidityPeriod = SmithsValidityPeriod;
}
......
......@@ -137,7 +137,6 @@
"cert_period": 14400,
"cert_max_by_issuer": 100,
"cert_min_received_cert_to_issue_cert": 5,
"cert_renewable_period": 172800,
"cert_validity_period": 2102400,
"idty_confirm_period": 14400,
"idty_creation_period": 14400,
......@@ -149,7 +148,6 @@
"smith_cert_period": 14400,
"smith_cert_max_by_issuer": 12,
"smith_cert_min_received_cert_to_issue_cert": 3,
"smith_cert_renewable_period": 172800,
"smith_cert_validity_period": 2102400,
"smith_membership_period": 1051200,
"smith_membership_renewable_period": 172800,
......
No preview for this file type
......@@ -461,7 +461,6 @@ macro_rules! pallets_config {
type MinReceivedCertToBeAbleToIssueCert = MinReceivedCertToBeAbleToIssueCert;
type OnNewcert = Wot;
type OnRemovedCert = Wot;
type CertRenewablePeriod = CertRenewablePeriod;
type ValidityPeriod = ValidityPeriod;
}
......@@ -499,7 +498,6 @@ macro_rules! pallets_config {
type MinReceivedCertToBeAbleToIssueCert = SmithMinReceivedCertToBeAbleToIssueCert;
type OnNewcert = SmithsSubWot;
type OnRemovedCert = SmithsSubWot;
type CertRenewablePeriod = SmithCertRenewablePeriod;
type ValidityPeriod = SmithValidityPeriod;
}
......
......@@ -119,7 +119,6 @@ parameter_types! {
pub const CertPeriod: BlockNumber = 5 * DAYS;
pub const MaxByIssuer: u32 = 100;
pub const MinReceivedCertToBeAbleToIssueCert: u32 = 5;
pub const CertRenewablePeriod: BlockNumber = 6 * MONTHS;
pub const ValidityPeriod: BlockNumber = 2 * YEARS;
}
......
......@@ -227,7 +227,6 @@ common_runtime::pallets_config! {
pub type MaxByIssuer = pallet_duniter_test_parameters::CertMaxByIssuer<Runtime>;
pub type MinReceivedCertToBeAbleToIssueCert =
pallet_duniter_test_parameters::CertMinReceivedCertToIssueCert<Runtime>;
pub type CertRenewablePeriod = pallet_duniter_test_parameters::CertRenewablePeriod<Runtime>;
pub type ValidityPeriod = pallet_duniter_test_parameters::CertValidityPeriod<Runtime>;
pub type ConfirmPeriod = pallet_duniter_test_parameters::IdtyConfirmPeriod<Runtime>;
pub type IdtyCreationPeriod = pallet_duniter_test_parameters::IdtyCreationPeriod<Runtime>;
......@@ -247,8 +246,6 @@ common_runtime::pallets_config! {
pub type SmithMaxByIssuer = pallet_duniter_test_parameters::SmithCertMaxByIssuer<Runtime>;
pub type SmithMinReceivedCertToBeAbleToIssueCert =
pallet_duniter_test_parameters::SmithCertMinReceivedCertToIssueCert<Runtime>;
pub type SmithCertRenewablePeriod =
pallet_duniter_test_parameters::SmithCertRenewablePeriod<Runtime>;
pub type SmithValidityPeriod = pallet_duniter_test_parameters::SmithCertValidityPeriod<Runtime>;
pub type SmithMembershipPeriod = pallet_duniter_test_parameters::SmithMembershipPeriod<Runtime>;
pub type SmithPendingMembershipPeriod =
......
......@@ -99,7 +99,6 @@ impl ExtBuilder {
cert_period: 15,
cert_max_by_issuer: 10,
cert_min_received_cert_to_issue_cert: 2,
cert_renewable_period: 50,
cert_validity_period: 10_000,
idty_confirm_period: 40,
idty_creation_period: 50,
......@@ -111,7 +110,6 @@ impl ExtBuilder {
smith_cert_period: 15,
smith_cert_max_by_issuer: 8,
smith_cert_min_received_cert_to_issue_cert: 2,
smith_cert_renewable_period: 50,
smith_cert_validity_period: 1_000,
smith_membership_period: 1_000,
smith_membership_renewable_period: 50,
......
......@@ -119,7 +119,6 @@ parameter_types! {
parameter_types! {
pub const CertPeriod: BlockNumber = DAYS;
pub const MaxByIssuer: u32 = 100;
pub const CertRenewablePeriod: BlockNumber = 12 * DAYS;
pub const ValidityPeriod: BlockNumber = 146 * DAYS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment