-
Notifications
You must be signed in to change notification settings - Fork 11
refactor(db): implement macro-based versioning system for database types #273
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
Draft
kariy
wants to merge
9
commits into
main
Choose a base branch
from
versioned-db-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
==========================================
+ Coverage 73.32% 75.50% +2.18%
==========================================
Files 209 231 +22
Lines 23132 27234 +4102
==========================================
+ Hits 16961 20564 +3603
- Misses 6171 6670 +499 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Introduces a declarative macro system to simplify adding new database versions. The new `versioned_type!` macro automatically generates versioned enums with all necessary trait implementations, reducing boilerplate from hundreds of lines to just a few lines per version. Key changes: - Add `versioned_type!` macro for generating versioned enums with automatic Compress/Decompress implementations - Migrate existing V6/V7 transaction and block types to use the new macro system - Add comprehensive documentation and examples for adding new versions - Include tests to verify backward compatibility and round-trip serialization This makes database format changes much more manageable - adding a new version now only requires: 1. Incrementing CURRENT_DB_VERSION 2. Adding one line to the versioned type declaration 3. Defining only the types that changed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4a32267 to
2576e52
Compare
Marks older version decompression paths as #[cold] and #[inline(never)] to optimize for the common case where most data is in the latest format. This helps the compiler generate better code for the hot path (latest version), improving decompression performance for typical database reads. The optimization splits the decompression attempts into: - Hot path: Latest version (most common case) - Cold paths: Older versions (less common, marked with compiler hints) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…ping Extends ResourceBoundsMapping serde to support different formats based on serializer type: - Binary formats (postcard, bincode): Uses standard enum serialization with variant tags - Human-readable formats (JSON): Uses unified object format with all possible fields This allows ResourceBoundsMapping to: - Maintain backward compatibility with existing binary database format - Support JSON deserialization from a single object containing union of all fields - Automatically determine variant based on presence of l1_data_gas field Added comprehensive tests for both JSON and binary serialization/deserialization. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Introduces a procedural macro that eliminates boilerplate when creating versioned database types. The macro automatically generates version-specific structs and From implementations based on field-level attributes.
Key features:
- #[derive(Versioned)] generates version-specific modules and structs
- Field-level #[versioned()] attributes specify version-specific types
- Automatic From trait implementations using .into() for conversions
- Support for both structs and enums
- Users retain full control over conversion logic via From traits
This reduces version addition from ~200 lines to just a few attribute annotations.
Example usage:
```rust
#[derive(Versioned)]
pub struct InvokeTxV3 {
#[versioned(v6 = "v6::ResourceBoundsMapping")]
pub resource_bounds: ResourceBoundsMapping,
// other fields...
}
```
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
e3bd68b to
e897bbb
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Problem
Currently, adding a new database version requires manually defining entire types, even if only a few fields changed. This creates hundreds of lines of boilerplate code and makes it error-prone to add new versions.
Solution
The new
versioned_type!macro automatically generates:Fromtrait implementations for conversionsCompressandDecompressimplementations with proper fallback chainChanges
Added macro infrastructure (
macros.rs):versioned_type!macro for generating versioned enumsMigrated existing types:
Documentation:
Example Usage
Adding a new version is now as simple as:
Testing
Benefits
🤖 Generated with Claude Code