Skip to content
Snippets Groups Projects
Commit f4d63dd9 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

fix(#109): handle certification renewal

parent bdb31722
No related branches found
No related tags found
No related merge requests found
Pipeline #19602 failed
...@@ -406,9 +406,16 @@ pub mod pallet { ...@@ -406,9 +406,16 @@ pub mod pallet {
let mut created = false; let mut created = false;
CertsByReceiver::<T, I>::mutate_exists(receiver, |maybe_issuers| { CertsByReceiver::<T, I>::mutate_exists(receiver, |maybe_issuers| {
let issuers = maybe_issuers.get_or_insert(Vec::with_capacity(0)); let issuers = maybe_issuers.get_or_insert(Vec::with_capacity(0));
if let Err(index) = issuers.binary_search_by(|(issuer_, _)| issuer.cmp(issuer_)) { match issuers.binary_search_by(|(issuer_, _)| issuer_.cmp(&issuer)) {
issuers.insert(index, (issuer, removable_on)); // cert exists, must be renewed
created = true; Ok(index) => {
issuers[index] = (issuer, removable_on);
}
// cert does not exist, must be created
Err(index) => {
issuers.insert(index, (issuer, removable_on));
created = true;
}
} }
}); });
...@@ -462,6 +469,7 @@ pub mod pallet { ...@@ -462,6 +469,7 @@ pub mod pallet {
total_weight total_weight
} }
/// perform the certification removal /// perform the certification removal
/// if block number is given only remove cert if still set to expire at this block number
fn remove_cert_inner( fn remove_cert_inner(
issuer: T::IdtyIndex, issuer: T::IdtyIndex,
receiver: T::IdtyIndex, receiver: T::IdtyIndex,
...@@ -471,9 +479,10 @@ pub mod pallet { ...@@ -471,9 +479,10 @@ pub mod pallet {
let mut removed = false; let mut removed = false;
CertsByReceiver::<T, I>::mutate_exists(receiver, |issuers_opt| { CertsByReceiver::<T, I>::mutate_exists(receiver, |issuers_opt| {
let issuers = issuers_opt.get_or_insert(Vec::with_capacity(0)); let issuers = issuers_opt.get_or_insert(Vec::with_capacity(0));
if let Ok(index) = issuers.binary_search_by(|(issuer_, _)| issuer.cmp(issuer_)) { if let Ok(index) = issuers.binary_search_by(|(issuer_, _)| issuer_.cmp(&issuer)) {
if let Some(block_number) = block_number_opt { if let Some(block_number) = block_number_opt {
if let Some((_, removable_on)) = issuers.get(index) { if let Some((_, removable_on)) = issuers.get(index) {
// only remove cert if block number is matching
if *removable_on == block_number { if *removable_on == block_number {
issuers.remove(index); issuers.remove(index);
removed = true; removed = true;
......
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