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

chore: Migrate DatabaseVersion to global namespace #4192

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

m1sterc001guy
Copy link
Contributor

Fixes: #3481

In developing the state machine migrations, I have found it annoying to work with DatabaseVersion that is within the module's namespace (since states for state machines are not kept in the module's namespace). Given that this is an existing issue, I decided to fix this first.

  • Adds database migration for DatabaseVersion. Since this is a migration that needs to be applied to clients and server, and is migrating keys from modules to the global namespace, I wrote some custom migration code for this. IMO this should be the only time this is necessary, since it should not be common to move keys from modules to the global namespace.
  • This PR also modifies the migration tests to use isolated databases, which matches what the client and server will do in production. Because of this, all of the database backups needed to be re-generated.
  • Has a simple test in the dummy client that verifies 0x50 prefix cannot be read after the migration, which should verify that the key collision issue is fixed.

@m1sterc001guy m1sterc001guy force-pushed the database_version_migration branch 2 times, most recently from 238a503 to c7de29a Compare January 31, 2024 22:59
@m1sterc001guy m1sterc001guy marked this pull request as ready for review January 31, 2024 23:31
@m1sterc001guy m1sterc001guy requested review from a team as code owners January 31, 2024 23:31
@m1sterc001guy m1sterc001guy marked this pull request as draft January 31, 2024 23:32
fedimint-core/src/db/mod.rs Outdated Show resolved Hide resolved
fedimint-testing/src/db.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@dpc dpc left a comment

Choose a reason for hiding this comment

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

🚀

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 41 lines in your changes are missing coverage. Please review.

Comparison is base (718bf5e) 57.93% compared to head (95474db) 58.04%.
Report is 23 commits behind head on master.

Files Patch % Lines
fedimint-testing/src/db.rs 79.64% 23 Missing ⚠️
fedimint-core/src/db/mod.rs 91.57% 8 Missing ⚠️
fedimint-server/src/db.rs 62.50% 6 Missing ⚠️
modules/fedimint-dummy-client/src/lib.rs 62.50% 3 Missing ⚠️
fedimint-dbtool/src/dump.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4192      +/-   ##
==========================================
+ Coverage   57.93%   58.04%   +0.10%     
==========================================
  Files         197      197              
  Lines       43425    43546     +121     
==========================================
+ Hits        25160    25276     +116     
- Misses      18265    18270       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@m1sterc001guy m1sterc001guy force-pushed the database_version_migration branch 3 times, most recently from 204680f to a760e17 Compare February 5, 2024 04:45
@m1sterc001guy m1sterc001guy marked this pull request as ready for review February 5, 2024 05:28
@m1sterc001guy m1sterc001guy requested a review from a team as a code owner February 5, 2024 05:28
Copy link
Contributor

@elsirion elsirion left a comment

Choose a reason for hiding this comment

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

Looks good, just some nits

fedimint-core/src/module/mod.rs Show resolved Hide resolved
Comment on lines +1925 to +1932
// First check if the module has a `DatabaseVersion` written to
// `DatabaseVersionKey` If `DatabaseVersion` already exists, there is
// nothing to do.
if global_dbtx
.get_value(&DatabaseVersionKey(key_module_instance_id))
.await
.is_none()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: early return might be slightly more readable

Comment on lines +1935 to +1949
let current_version_in_module = if let Some(module_instance_id) = module_instance_id {
remove_current_db_version_if_exists(
&mut global_dbtx
.to_ref_with_prefix_module_id(module_instance_id)
.into_nc(),
target_db_version,
)
.await
} else {
remove_current_db_version_if_exists(
&mut global_dbtx.to_ref().into_nc(),
target_db_version,
)
.await
};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The actual fn call could be factored out, only the DB argument needs to change depending on the instance id being set or not.

@elsirion elsirion added this pull request to the merge queue Feb 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2024
@elsirion elsirion added this pull request to the merge queue Feb 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2024
@elsirion elsirion added this pull request to the merge queue Feb 6, 2024
Merged via the queue into fedimint:master with commit 7245b06 Feb 6, 2024
22 checks passed
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.

Modules can't write to 0x50 database key
3 participants