Skip to content

Commit

Permalink
Merge pull request #856 from input-output-hk/jpraynaud/828-fix-prunin…
Browse files Browse the repository at this point in the history
…g-panic-epoch-setting

Fix pruning panic
  • Loading branch information
jpraynaud authored Apr 6, 2023
2 parents f8f3434 + fe479dc commit ca18af4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.2.46"
version = "0.2.47"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/database/provider/epoch_setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use mithril_common::StdError;
use tokio::sync::Mutex;

/// Delete epoch settings for Epoch older than this.
const EPOCH_SETTING_PRUNE_EPOCH_THRESHOLD: Epoch = Epoch(3);
const EPOCH_SETTING_PRUNE_EPOCH_THRESHOLD: Epoch = Epoch(10);

/// Settings for an epoch, including the protocol parameters.
#[derive(Debug, PartialEq)]
Expand Down
12 changes: 8 additions & 4 deletions mithril-aggregator/src/database/provider/signer_registration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::HashMap, sync::Arc};
use std::{
collections::{BTreeMap, HashMap},
sync::Arc,
};

use sqlite::{Connection, Value};

Expand Down Expand Up @@ -453,8 +456,8 @@ impl StoreAdapter for SignerRegistrationStoreAdapter {
.collect::<Vec<_>>()
.into_iter()
.rev();
let signer_with_stake_by_epoch: HashMap<Self::Key, Self::Record> = cursor.fold(
HashMap::<Self::Key, Self::Record>::new(),
let signer_with_stake_by_epoch: BTreeMap<Self::Key, Self::Record> = cursor.fold(
BTreeMap::<Self::Key, Self::Record>::new(),
|mut acc, signer_registration_record| {
let epoch = signer_registration_record.epoch_setting_id;
let mut signer_with_stakes: Self::Record =
Expand All @@ -473,6 +476,7 @@ impl StoreAdapter for SignerRegistrationStoreAdapter {
);
Ok(signer_with_stake_by_epoch
.into_iter()
.rev()
.take(how_many)
.collect())
}
Expand Down Expand Up @@ -839,7 +843,7 @@ mod tests {
async fn test_store_adapter() {
let fixture = MithrilFixtureBuilder::default().with_signers(5).build();
let signer_with_stakes = fixture.signers_with_stake();
let signer_with_stakes_by_epoch: Vec<(Epoch, HashMap<PartyId, SignerWithStake>)> = (0..1)
let signer_with_stakes_by_epoch: Vec<(Epoch, HashMap<PartyId, SignerWithStake>)> = (0..5)
.map(|e| {
(
Epoch(e),
Expand Down
15 changes: 12 additions & 3 deletions mithril-aggregator/src/store/protocol_parameters_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ impl StorePruner for ProtocolParametersStore {
fn get_max_records(&self) -> Option<usize> {
self.retention_len
}

/// Pruning is deactivated on this store.
async fn prune(&self) -> Result<(), StoreError> {
Ok(())
}
}

#[async_trait]
Expand Down Expand Up @@ -160,7 +165,11 @@ mod tests {
.save_protocol_parameters(Epoch(3), protocol_parameters[2].1.clone())
.await
.unwrap();
assert_eq!(None, store.get_protocol_parameters(Epoch(1)).await.unwrap());
assert!(store
.get_protocol_parameters(Epoch(1))
.await
.unwrap()
.is_some());
let res = store.get_protocol_parameters(Epoch(2)).await.unwrap();
assert!(res.is_some());
}
Expand Down Expand Up @@ -192,11 +201,11 @@ mod tests {
.get_protocol_parameters(Epoch(1))
.await
.unwrap()
.is_none());
.is_some());
assert!(store
.get_protocol_parameters(Epoch(2))
.await
.unwrap()
.is_none());
.is_some());
}
}
2 changes: 1 addition & 1 deletion mithril-infra/assets/docker/docker-compose-aggregator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ services:
- SNAPSHOT_UPLOADER_TYPE=gcp
- SNAPSHOT_BUCKET_NAME=${SNAPSHOT_BUCKET_NAME}
- DATA_STORES_DIRECTORY=/mithril-aggregator/mithril/stores
#- STORE_RETENTION_LIMIT=5
- STORE_RETENTION_LIMIT=5
- CARDANO_NODE_SOCKET_PATH=/ipc/node.socket
- CARDANO_CLI_PATH=/app/bin/cardano-cli
- GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY}
Expand Down

0 comments on commit ca18af4

Please sign in to comment.