diff --git a/pallets/certification/src/lib.rs b/pallets/certification/src/lib.rs index 9b423da0db4b6467f0b5613c94b50adf56d71a31..a734fcdeb908a71303d465780a7743f7aa50be7e 100644 --- a/pallets/certification/src/lib.rs +++ b/pallets/certification/src/lib.rs @@ -406,9 +406,16 @@ pub mod pallet { let mut created = false; CertsByReceiver::<T, I>::mutate_exists(receiver, |maybe_issuers| { let issuers = maybe_issuers.get_or_insert(Vec::with_capacity(0)); - if let Err(index) = issuers.binary_search_by(|(issuer_, _)| issuer.cmp(issuer_)) { - issuers.insert(index, (issuer, removable_on)); - created = true; + match issuers.binary_search_by(|(issuer_, _)| issuer_.cmp(&issuer)) { + // cert exists, must be renewed + 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 { total_weight } /// 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( issuer: T::IdtyIndex, receiver: T::IdtyIndex, @@ -471,9 +479,10 @@ pub mod pallet { let mut removed = false; CertsByReceiver::<T, I>::mutate_exists(receiver, |issuers_opt| { 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((_, removable_on)) = issuers.get(index) { + // only remove cert if block number is matching if *removable_on == block_number { issuers.remove(index); removed = true;