diff --git a/backend/canisters/cycles_dispenser/CHANGELOG.md b/backend/canisters/cycles_dispenser/CHANGELOG.md index 104fba885e..f03a49bb88 100644 --- a/backend/canisters/cycles_dispenser/CHANGELOG.md +++ b/backend/canisters/cycles_dispenser/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Expose size of each virtual stable memory in metrics ([#6981](https://github.com/open-chat-labs/open-chat/pull/6981)) +### Fixed + +- Fix ordering of `latest_top_ups` ([#7046](https://github.com/open-chat-labs/open-chat/pull/7046)) + ## [[2.0.1485](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1485-cycles_dispenser)] - 2024-11-29 ### Added diff --git a/backend/canisters/cycles_dispenser/impl/src/model/canisters.rs b/backend/canisters/cycles_dispenser/impl/src/model/canisters.rs index c0b340cf2d..ff845948dd 100644 --- a/backend/canisters/cycles_dispenser/impl/src/model/canisters.rs +++ b/backend/canisters/cycles_dispenser/impl/src/model/canisters.rs @@ -1,5 +1,6 @@ use candid::CandidType; use serde::{Deserialize, Serialize}; +use std::cmp::Reverse; use std::collections::hash_map::Entry::Vacant; use std::collections::{BinaryHeap, HashMap}; use types::{CanisterId, Cycles, TimestampMillis}; @@ -67,14 +68,17 @@ impl Canisters { }) }) { if heap.len() < count { - heap.push(top_up); - } else if top_up > *heap.peek().unwrap() { + heap.push(Reverse(top_up)); + } else if top_up > heap.peek().unwrap().0 { heap.pop(); - heap.push(top_up); + heap.push(Reverse(top_up)); } } - let mut vec = heap.into_sorted_vec(); + let mut vec = Vec::with_capacity(heap.len()); + while let Some(Reverse(top_up)) = heap.pop() { + vec.push(top_up); + } vec.reverse(); vec }