pallet-offences: Switch to partition_point (#9049)

This changes the code to use `partition_point` instead of
`binary_search_by_key`, because this was very likely the problematic
pallet 2 weeks ago on polkadot.
This commit is contained in:
Bastian Köcher authored and GitHub committed 2021-06-12 02:38:17 +02:00
1 parent 0869fdf9aa
commit e360cff92e
3 files changed
+68 -9

No files matched your search

+3 -8
View File
@@ -281,15 +281,10 @@ impl<T: Config, O: Offence<T::IdentificationTuple>> ReportIndexStorage<T, O> {
fn insert(&mut self, time_slot: &O::TimeSlot, report_id: ReportIdOf<T>) {
// Insert the report id into the list while maintaining the ordering by the time
// slot.
let pos = match self
let pos = self
.same_kind_reports
.binary_search_by_key(&time_slot, |&(ref when, _)| when)
{
Ok(pos) => pos,
Err(pos) => pos,
};
self.same_kind_reports
.insert(pos, (time_slot.clone(), report_id));
.partition_point(|&(ref when, _)| when <= time_slot);
self.same_kind_reports.insert(pos, (time_slot.clone(), report_id));
// Update the list of concurrent reports.
self.concurrent_reports.push(report_id);