Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of store adapter in aggregator #2143

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

sfauvel
Copy link
Collaborator

@sfauvel sfauvel commented Nov 25, 2024

Content

Replace the store using the legacy store adapter and replace them with a repository implementation in the Aggregator.

This PR includes:

  • Removing of StoreAdapter from persistence
  • Remove links to StoreAdapter for signer_registration and CertificatePending in Aggregator
  • Remove usage of AdapterError

Note

If pruning is unit tested, there is no test that verify that it's really plugged and worked in production.
It's just a configuration in build_upkeep_service function in the builder.rs file that activate it.

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • CHANGELOG file is updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • No clippy warnings in the CI
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested
  • Documentation
    • Update README file (if relevant)
    • Update documentation website (if relevant)
    • Add dev blog post (if relevant)

Comments

Issue(s)

Relates to #2118

Copy link

github-actions bot commented Nov 25, 2024

Test Results

    4 files  ± 0     51 suites  ±0   11m 54s ⏱️ +10s
1 410 tests  - 45  1 410 ✅  - 45  0 💤 ±0  0 ❌ ±0 
1 621 runs   - 45  1 621 ✅  - 45  0 💤 ±0  0 ❌ ±0 

Results for commit e450847. ± Comparison against base commit 67d7501.

This pull request removes 61 and adds 16 tests. Note that renamed tests count towards both.
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::can_prune_keys_from_given_epoch_retention_limit
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::get_signers_for_empty_epoch
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::get_signers_for_existing_epoch
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::get_verification_keys_for_empty_epoch
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::get_verification_keys_for_existing_epoch
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::save_key_in_empty_store
mithril-aggregator ‑ database::repository::signer_registration_store::tests::test_signer_registration_store::update_signer_in_store
mithril-aggregator ‑ signer_registerer::tests::should_prune_verification_keys_older_than_two_epochs_at_round_opening
mithril-aggregator ‑ store::pending_certificate_store::test::get_certificate_pending_with_existing_certificate
mithril-aggregator ‑ store::pending_certificate_store::test::get_certificate_pending_with_no_existing_certificate
…
mithril-aggregator ‑ database::repository::pending_certificate_repository::test::get_certificate_pending_with_existing_certificate
mithril-aggregator ‑ database::repository::pending_certificate_repository::test::get_certificate_pending_with_no_existing_certificate
mithril-aggregator ‑ database::repository::pending_certificate_repository::test::remove_certificate_pending
mithril-aggregator ‑ database::repository::pending_certificate_repository::test::save_certificate_pending_once
mithril-aggregator ‑ database::repository::pending_certificate_repository::test::should_migrate_data_from_adapter
mithril-aggregator ‑ database::repository::pending_certificate_repository::test::update_certificate_pending
mithril-aggregator ‑ database::repository::signer_registration_store::tests::can_prune_keys_from_given_epoch_retention_limit
mithril-aggregator ‑ database::repository::signer_registration_store::tests::get_signers_for_empty_epoch
mithril-aggregator ‑ database::repository::signer_registration_store::tests::get_signers_for_existing_epoch
mithril-aggregator ‑ database::repository::signer_registration_store::tests::get_verification_keys_for_empty_epoch
…

♻️ This comment has been updated with latest results.

@sfauvel sfauvel force-pushed the sfa/2118/get_rid_of_store_adapter_in_aggregator branch from 7363c3c to dae2e96 Compare November 26, 2024 09:41

impl CertificatePendingRecord {
/// Construct a [Projection] that will allow to hydrate this `CertificatePendingRecord`.
pub fn get_projection_with_table(table: &str) -> Projection {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a proposition to have a function that produce projection with that final table name instead of using an alias.
Tell me if we put it in this PR or if you prefer to keep the standard way

The alias mechanism is not really necessary because we always calling it just after creating the projection. There is no reuse of the projection.
With this function, the caller knows which table name(s) need to be map instead of using an alias key string without any constraints and used in different files (we may use a constant).
Callers of projection function are requests that know record type and can use specific function of this record.

// it is important to alias the fields with the same name as the table
// since the table cannot be aliased in a RETURNING statement in SQLite.

// let projection = Self::Entity::get_projection().expand(SourceAlias::new(&[(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment will be remove if we keep get_projection_with_table otherwise it will be uncommented and the code below will be removed.
See PR comment on get_projection_with_table in CertificatePendingRecord to have explanation about this function.

&mut self,
) -> Result<Arc<dyn CertificatePendingStorer>> {
Ok(Arc::new(CertificatePendingRepository::new(
self.get_sqlite_connection().await?,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The building of certificate_pending_store is know the same in production and in test environment.
There is no really need to make a difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it's better like this 👍

@sfauvel sfauvel marked this pull request as ready for review November 26, 2024 10:23
@sfauvel sfauvel force-pushed the sfa/2118/get_rid_of_store_adapter_in_aggregator branch from dae2e96 to d0ba1ee Compare November 26, 2024 10:26
mod stake_store;
mod store_pruner;

pub use stake_store::StakeStorer;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We keep StakeStore that contain the trait.
Maybe it's could be better to move this trait from persistence to aggregator and signer
What do you think ?

@sfauvel sfauvel force-pushed the sfa/2118/get_rid_of_store_adapter_in_aggregator branch from d0ba1ee to 20c0332 Compare November 26, 2024 10:45
@sfauvel sfauvel force-pushed the sfa/2118/get_rid_of_store_adapter_in_aggregator branch from 20c0332 to e450847 Compare November 26, 2024 13:13
Copy link
Member

@jpraynaud jpraynaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good 👍

I left few questions and suggestions.

}

fn get_definition(&self, condition: &str) -> String {
// let aliases = SourceAlias::new(&[("{:pending_certificate:}", "new_pending_certificate")]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to remove this comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rework it using the new function expand_projection

let projection = Self::Entity::get_projection_with_table("pending_certificate")
.expand(SourceAlias::new(&[]));
format!(
// TODO check the order to keep
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this order (rowid desc). You can remove this comment.


use crate::database::record::CertificatePendingRecord;

/// Query to update [CertificatePendingRecord] in the sqlite database
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Query to update [CertificatePendingRecord] in the sqlite database
/// Query to save [CertificatePendingRecord] in the sqlite database

r#"
create table new_pending_certificate (
epoch integer not null,
certificate text not null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certificate is a bit misleading here as this does not represent a certificate.
But let's keep it like that if it requires too many modifications as we will remove it completely in the near future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a better name, we can change it. It's not a lot of work.

}
}

impl From<CertificatePending> for CertificatePendingRecord {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to implement TryFrom here to avoid panics.


use super::*;

fn build_signers(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have used a helper to create a SignerWithStake from a party_id and a verification_key.
Also the code could probably be a bit more functional.

@@ -456,3 +458,52 @@ pub fn insert_stake_pool(

Ok(())
}

/// A simple struct that help to initialize database with the old adapter behavior for testing purposes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A simple struct that help to initialize database with the old adapter behavior for testing purposes.
/// A simple struct that helps initialize a database with the old adapter behavior for testing purposes.

self.connection.execute(sql).unwrap();
}

pub fn is_key_hash_exist(&self, key_hash: &str) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn is_key_hash_exist(&self, key_hash: &str) -> bool {
pub fn ihas_key_hash(&self, key_hash: &str) -> bool {

&mut self,
) -> Result<Arc<dyn CertificatePendingStorer>> {
Ok(Arc::new(CertificatePendingRepository::new(
self.get_sqlite_connection().await?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it's better like this 👍

.unwrap(),
));

let vkey_store = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let vkey_store = {
let verification_key_store = {

Copy link
Collaborator

@dlachaume dlachaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

migrations
.clone()
.into_iter()
.filter(|m| m.version < 32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder if you want to update the version number after rebasing on the main branch.

/// Get a configured [CertificatePendingStore].
pub async fn get_certificate_pending_store(&mut self) -> Result<Arc<CertificatePendingStore>> {
/// Get a configured [CertificatePendingStorer].
pub async fn get_certificate_pending_store(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename the function as well?

Suggested change
pub async fn get_certificate_pending_store(
pub async fn get_certificate_pending_storer(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also rename build_certificate_pending_store to build_certificate_pending_storer

@sfauvel sfauvel force-pushed the sfa/2118/get_rid_of_store_adapter_in_aggregator branch from d78085f to 61fd2ee Compare November 26, 2024 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants