-
Notifications
You must be signed in to change notification settings - Fork 188
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
refactor(katana-db): database transaction abstractions #2171
Conversation
WalkthroughThe updates introduce traits for database cursor operations and transactions across multiple files in the Changes
Poem
Tip CodeRabbit can approve the review once CodeRabbit's comments are resolvedEnable the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
3f645f6
to
9b8449d
Compare
9b8449d
to
adb3af4
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2171 +/- ##
==========================================
+ Coverage 68.00% 68.06% +0.06%
==========================================
Files 331 332 +1
Lines 42697 42687 -10
==========================================
+ Hits 29035 29057 +22
+ Misses 13662 13630 -32 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- crates/katana/storage/db/src/abstraction/cursor.rs (1 hunks)
- crates/katana/storage/db/src/abstraction/mod.rs (1 hunks)
- crates/katana/storage/db/src/abstraction/transaction.rs (1 hunks)
- crates/katana/storage/db/src/lib.rs (1 hunks)
- crates/katana/storage/db/src/mdbx/cursor.rs (9 hunks)
- crates/katana/storage/db/src/mdbx/mod.rs (2 hunks)
- crates/katana/storage/db/src/mdbx/tx.rs (5 hunks)
- crates/katana/storage/provider/src/providers/db/mod.rs (1 hunks)
- crates/katana/storage/provider/src/providers/db/state.rs (1 hunks)
Files skipped from review due to trivial changes (1)
- crates/katana/storage/db/src/abstraction/mod.rs
Additional comments not posted (33)
crates/katana/storage/db/src/abstraction/transaction.rs (2)
6-33
: DbTx Trait: Ensure Consistent Error Handling.The
DbTx
trait defines methods for managing read-only transactions. Ensure that all methods handle errors consistently and consider adding comments to describe the purpose of each method.
35-68
: DbTxMut Trait: Ensure Consistent Error HandlingThe
DbTxMut
trait defines methods for managing read-write transactions. Ensure that all methods handle errors consistently and consider adding comments to describe the purpose of each method.crates/katana/storage/db/src/lib.rs (1)
8-8
: Verify Integration of Abstraction ModuleThe new
abstraction
module is integrated into thestorage/db
crate. Ensure that the integration follows the project's modular design and verify that all necessary components are included.crates/katana/storage/db/src/mdbx/tx.rs (2)
Line range hint
52-92
:
DbTx Implementation: Ensure Correctness of Database OperationsThe
DbTx
trait is implemented for theTx
struct. Ensure the correctness of the database operations and verify that all error handling is consistent and appropriate.
Line range hint
95-127
:
DbTxMut Implementation: Ensure Correctness of Database OperationsThe
DbTxMut
trait is implemented for theTx
struct. Ensure the correctness of the database operations and verify that all error handling is consistent and appropriate.crates/katana/storage/db/src/mdbx/cursor.rs (4)
38-71
: DbCursor Implementation: Ensure Correctness of Cursor OperationsThe
DbCursor
trait is implemented for theCursor
struct. Ensure the correctness of cursor operations and verify that all error handling is consistent and appropriate.
Line range hint
85-124
:
DbDupSortCursor Implementation: Ensure Correctness of Cursor OperationsThe
DbDupSortCursor
trait is implemented for theCursor
struct. Ensure the correctness of cursor operations and verify that all error handling is consistent and appropriate.
Line range hint
169-214
:
DbCursorMut Implementation: Ensure Correctness of Cursor OperationsThe
DbCursorMut
trait is implemented for theCursor
struct. Ensure the correctness of cursor operations and verify that all error handling is consistent and appropriate.
219-228
: DbDupSortCursorMut Implementation: Ensure Correctness of Cursor OperationsThe
DbDupSortCursorMut
trait is implemented for theCursor
struct. Ensure the correctness of cursor operations and verify that all error handling is consistent and appropriate.crates/katana/storage/db/src/abstraction/cursor.rs (6)
6-39
: Ensure consistent error handling in cursor methods.While the
DbCursor
trait methods' signatures look correct, ensure that the implementations of these methods consistently handle errors and edge cases.
42-57
: Verify transaction integrity in cursor mutation methods.The methods in
DbCursorMut
involve mutations in the database. Ensure that the implementations of these methods maintain transaction integrity and handle rollbacks correctly in case of errors.
60-91
: Check for consistent handling of duplicates in DUPSORT cursor methods.The
DbDupSortCursor
trait methods should ensure consistent handling of duplicate keys and values. Verify that the implementations handle edge cases and maintain cursor state correctly.
94-100
: Ensure atomicity in DUPSORT cursor mutation methods.The methods in
DbDupSortCursorMut
involve complex operations on DUPSORT tables. Ensure that the implementations maintain atomicity and handle rollbacks correctly in case of errors.
110-147
: Confirm iterator correctness inWalker
.The
Walker
struct methods should ensure correct iteration over table items, especially handling the initial cursor position and edge cases.
154-195
: Verify duplicate handling inDupWalker
.The
DupWalker
struct methods should ensure correct iteration over DUPSORT table items, especially handling duplicates and edge cases.crates/katana/storage/provider/src/providers/db/state.rs (4)
Line range hint
15-55
: Ensure proper error handling in state update methods.The methods in the
StateWriter
trait implementation should properly handle errors and ensure database consistency.
Line range hint
56-85
: Ensure proper error handling in contract class update methods.The methods in the
ContractClassWriter
trait implementation should properly handle errors and ensure database consistency.
Line range hint
86-111
: Ensure proper error handling in contract class retrieval methods.The methods in the
ContractClassProvider
trait implementation should properly handle errors and ensure correct retrieval of contract class information.
Line range hint
112-251
: Ensure proper error handling in historical state retrieval methods.The methods in the
StateProvider
trait implementation should properly handle errors and ensure correct retrieval of historical state information.crates/katana/storage/db/src/mdbx/mod.rs (4)
Line range hint
17-37
: Ensure correct database environment setup.The
DbEnv::open
function should correctly set up the database environment, handling errors and edge cases.
Line range hint
39-53
: Ensure correct table creation.The
DbEnv::create_tables
function should correctly create all defined tables, handling errors and ensuring consistency.
Line range hint
69-77
: Ensure transaction integrity inDbEnv::update
.The
DbEnv::update
function should maintain transaction integrity, handling rollbacks correctly in case of errors.
Line range hint
147-389
: Ensure comprehensive test coverage.The tests should comprehensively cover all database operations, including edge cases and error handling.
crates/katana/storage/provider/src/providers/db/mod.rs (10)
Line range hint
22-40
: Ensure proper error handling in state factory methods.The methods in the
StateFactoryProvider
trait implementation should properly handle errors and ensure correct state information retrieval.
Line range hint
42-56
: Ensure proper error handling in block number methods.The methods in the
BlockNumberProvider
trait implementation should properly handle errors and ensure correct block number retrieval.
Line range hint
58-72
: Ensure proper error handling in block hash methods.The methods in the
BlockHashProvider
trait implementation should properly handle errors and ensure correct block hash retrieval.
Line range hint
74-93
: Ensure proper error handling in header methods.The methods in the
HeaderProvider
trait implementation should properly handle errors and ensure correct block header retrieval.
Line range hint
95-140
: Ensure proper error handling in block methods.The methods in the
BlockProvider
trait implementation should properly handle errors and ensure correct block information retrieval.
Line range hint
142-161
: Ensure proper error handling in block status methods.The methods in the
BlockStatusProvider
trait implementation should properly handle errors and ensure correct block status retrieval.
Line range hint
163-180
: Ensure proper error handling in state root methods.The methods in the
StateRootProvider
trait implementation should properly handle errors and ensure correct state root retrieval.
Line range hint
182-247
: Ensure proper error handling in state update methods.The methods in the
StateUpdateProvider
trait implementation should properly handle errors and ensure correct state update retrieval.
Line range hint
249-319
: Ensure proper error handling in transaction methods.The methods in the
TransactionProvider
trait implementation should properly handle errors and ensure correct transaction information retrieval.
Line range hint
387-493
: Ensure proper error handling in block writing methods.The methods in the
BlockWriter
trait implementation should properly handle errors and ensure correct block information writing.
Description
Make the katana database generic over the database tx implementations. Doesnt change any database behaviour.
Right now we only define the traits and implement them on the appropriate structs, replacing the current implementations that are just associated methods.
Later, we will use this trait on the provider level so that we can actually be generic over katana persistent database implementation.
Related issue
Tests
Added to documentation?
Checklist
scripts/prettier.sh
,scripts/rust_fmt.sh
,scripts/cairo_fmt.sh
)scripts/clippy.sh
,scripts/docs.sh
)Summary by CodeRabbit
New Features
Refactor
Chores