Skip to content

Commit ea7a94d

Browse files
committed
Fix SignerRegistration 'get_last_n_records' store adapter implementation
Use BTreeMap instead of HashMap to guarantee sort order of records.
1 parent ce7be87 commit ea7a94d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mithril-aggregator/src/database/provider/signer_registration.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{collections::HashMap, sync::Arc};
1+
use std::{
2+
collections::{BTreeMap, HashMap},
3+
sync::Arc,
4+
};
25

36
use sqlite::{Connection, Value};
47

@@ -453,8 +456,8 @@ impl StoreAdapter for SignerRegistrationStoreAdapter {
453456
.collect::<Vec<_>>()
454457
.into_iter()
455458
.rev();
456-
let signer_with_stake_by_epoch: HashMap<Self::Key, Self::Record> = cursor.fold(
457-
HashMap::<Self::Key, Self::Record>::new(),
459+
let signer_with_stake_by_epoch: BTreeMap<Self::Key, Self::Record> = cursor.fold(
460+
BTreeMap::<Self::Key, Self::Record>::new(),
458461
|mut acc, signer_registration_record| {
459462
let epoch = signer_registration_record.epoch_setting_id;
460463
let mut signer_with_stakes: Self::Record =
@@ -473,6 +476,7 @@ impl StoreAdapter for SignerRegistrationStoreAdapter {
473476
);
474477
Ok(signer_with_stake_by_epoch
475478
.into_iter()
479+
.rev()
476480
.take(how_many)
477481
.collect())
478482
}
@@ -839,7 +843,7 @@ mod tests {
839843
async fn test_store_adapter() {
840844
let fixture = MithrilFixtureBuilder::default().with_signers(5).build();
841845
let signer_with_stakes = fixture.signers_with_stake();
842-
let signer_with_stakes_by_epoch: Vec<(Epoch, HashMap<PartyId, SignerWithStake>)> = (0..1)
846+
let signer_with_stakes_by_epoch: Vec<(Epoch, HashMap<PartyId, SignerWithStake>)> = (0..5)
843847
.map(|e| {
844848
(
845849
Epoch(e),

0 commit comments

Comments
 (0)