Skip to content

Commit ca18af4

Browse files
authored
Merge pull request #856 from input-output-hk/jpraynaud/828-fix-pruning-panic-epoch-setting
Fix pruning panic
2 parents f8f3434 + fe479dc commit ca18af4

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.2.46"
3+
version = "0.2.47"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use mithril_common::StdError;
2121
use tokio::sync::Mutex;
2222

2323
/// Delete epoch settings for Epoch older than this.
24-
const EPOCH_SETTING_PRUNE_EPOCH_THRESHOLD: Epoch = Epoch(3);
24+
const EPOCH_SETTING_PRUNE_EPOCH_THRESHOLD: Epoch = Epoch(10);
2525

2626
/// Settings for an epoch, including the protocol parameters.
2727
#[derive(Debug, PartialEq)]

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),

mithril-aggregator/src/store/protocol_parameters_store.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl StorePruner for ProtocolParametersStore {
5252
fn get_max_records(&self) -> Option<usize> {
5353
self.retention_len
5454
}
55+
56+
/// Pruning is deactivated on this store.
57+
async fn prune(&self) -> Result<(), StoreError> {
58+
Ok(())
59+
}
5560
}
5661

5762
#[async_trait]
@@ -160,7 +165,11 @@ mod tests {
160165
.save_protocol_parameters(Epoch(3), protocol_parameters[2].1.clone())
161166
.await
162167
.unwrap();
163-
assert_eq!(None, store.get_protocol_parameters(Epoch(1)).await.unwrap());
168+
assert!(store
169+
.get_protocol_parameters(Epoch(1))
170+
.await
171+
.unwrap()
172+
.is_some());
164173
let res = store.get_protocol_parameters(Epoch(2)).await.unwrap();
165174
assert!(res.is_some());
166175
}
@@ -192,11 +201,11 @@ mod tests {
192201
.get_protocol_parameters(Epoch(1))
193202
.await
194203
.unwrap()
195-
.is_none());
204+
.is_some());
196205
assert!(store
197206
.get_protocol_parameters(Epoch(2))
198207
.await
199208
.unwrap()
200-
.is_none());
209+
.is_some());
201210
}
202211
}

mithril-infra/assets/docker/docker-compose-aggregator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ services:
5858
- SNAPSHOT_UPLOADER_TYPE=gcp
5959
- SNAPSHOT_BUCKET_NAME=${SNAPSHOT_BUCKET_NAME}
6060
- DATA_STORES_DIRECTORY=/mithril-aggregator/mithril/stores
61-
#- STORE_RETENTION_LIMIT=5
61+
- STORE_RETENTION_LIMIT=5
6262
- CARDANO_NODE_SOCKET_PATH=/ipc/node.socket
6363
- CARDANO_CLI_PATH=/app/bin/cardano-cli
6464
- GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY}

0 commit comments

Comments
 (0)