Skip to content

Commit 503390d

Browse files
devin-ai-integration[bot]kariyclaude[bot]
committed
feat(cli): database pruning tool for historical trie data (#123)
* feat(db): add database pruning tool for historical trie data - Add prune subcommand to katana db utility - Support two modes: prune all history or keep last N blocks - Include safety checks and proper error handling - Efficiently handle bulk deletions using database cursors * feat: add progress monitoring and visualization for database pruning - Add indicatif dependency for progress bar visualization - Implement multi-level progress bars showing overall and per-table progress - Add counting passes to determine total entries for accurate progress tracking - Show table names, current/total entries, elapsed time, and entries per second - Visual progress bars with cyan/blue styling for better user experience --------- Co-authored-by: Ammar Arif <evergreenkary@gmail.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
1 parent 7f2ffc2 commit 503390d

File tree

22 files changed

+1048
-191
lines changed

22 files changed

+1048
-191
lines changed

AGENT.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Katana Development Guide
2+
3+
## Build Commands
4+
- `cargo build` - Build the project
5+
- `cargo test` - Run all tests
6+
- `cargo test <test_name>` - Run a specific test
7+
- `cargo test -p <crate_name>` - Run tests for a specific crate
8+
- `cargo clippy` - Run linter
9+
- `make test-artifacts` - Prepare test database and SNOS artifacts
10+
11+
## Code Style
12+
- **Formatting**: Uses rustfmt with 100 char width, group imports by StdExternalCrate
13+
- **Imports**: std → external crates → local crates, use explicit paths `use crate::module::Type`
14+
- **Naming**: snake_case functions, constructors use `new()`, `from_*()`, `with_*()` patterns
15+
- **Error Handling**: Use `thiserror` for custom errors, `anyhow` for general error handling, always use `Result<T>` types
16+
- **Visibility**: Clear `pub` boundaries, comprehensive `///` docs for public APIs
17+
- **Async**: Use `async/await` with `?` operator for error propagation
18+
- **Types**: Use `Arc<>` for shared ownership, prefer owned types over references in function signatures
19+
20+
## Testing
21+
- Test modules use `#[cfg(test)]`
22+
- Use descriptive test names that explain the scenario being tested
23+
- Use `rstest` for parameterized tests, `assert_matches` for pattern matching
24+
- Run `make test-artifacts` before running tests that need database fixtures
25+
26+
## Architecture
27+
- Workspace with multiple crates under `crates/` directory
28+
- Each crate focuses on specific functionality (rpc, storage, executor, etc.)
29+
- Use workspace dependencies for consistent versioning across crates

Cargo.lock

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ cairo-lang-starknet-classes = "2.11.2"
100100
cairo-lang-utils = "2.11.2"
101101
# Some types that we used from cairo-vm implements the `Arbitrary` trait,
102102
# only under the `test_utils` feature. So we expose through this feature.
103-
cairo-vm = { version = "1.0.2", features = [ "test_utils" ] }
104103
anyhow = "1.0.89"
105104
arbitrary = { version = "1.3.2", features = [ "derive" ] }
106105
assert_fs = "1.1"
@@ -109,6 +108,7 @@ async-trait = "0.1.82"
109108
auto_impl = "1.2.0"
110109
base64 = "0.21.2"
111110
bigdecimal = "0.4.1"
111+
cairo-vm = { version = "1.0.2", features = [ "test_utils" ] }
112112
camino = { version = "1.1.2", features = [ "serde1" ] }
113113
chrono = { version = "0.4.24", features = [ "serde" ] }
114114
clap = { version = "4.5.16", features = [ "derive", "env" ] }
@@ -194,13 +194,13 @@ tonic-build = "0.11"
194194
tonic-reflection = "0.11"
195195
tonic-web = "0.11"
196196
# WASM-compatible gRPC deps
197+
criterion = "0.5.1"
198+
pprof = { version = "0.13.0", features = [ "criterion", "flamegraph" ] }
199+
slot = { git = "https://github.com/cartridge-gg/slot", rev = "1298a30" }
197200
tonic-web-wasm-client = "0.6.0"
198201
wasm-prost = { version = "0.13", package = "prost" }
199202
wasm-tonic = { version = "0.12", default-features = false, features = [ "codegen", "gzip", "prost" ], package = "tonic" }
200203
wasm-tonic-build = { version = "0.12", default-features = false, features = [ "prost" ], package = "tonic-build" }
201-
criterion = "0.5.1"
202-
pprof = { version = "0.13.0", features = [ "criterion", "flamegraph" ] }
203-
slot = { git = "https://github.com/cartridge-gg/slot", rev = "1298a30" }
204204
# alloy core
205205
alloy-primitives = { version = "0.8", default-features = false }
206206
alloy-sol-types = { version = "0.8", default-features = false }
@@ -213,10 +213,10 @@ alloy-rpc-types-eth = { version = "0.4", default-features = false }
213213
alloy-signer = { version = "0.4", default-features = false }
214214
alloy-transport = { version = "0.4", default-features = false }
215215

216+
bitvec = "1.0.1"
216217
starknet = "0.14.0"
217218
starknet-crypto = "0.7.1"
218219
starknet-types-core = { version = "0.1.8", features = [ "arbitrary", "hash" ] }
219-
bitvec = "1.0.1"
220220
# macro
221221
proc-macro2 = "1.0"
222222
quote = "1.0"
@@ -238,3 +238,10 @@ opentelemetry-stackdriver = { version = "0.27.0", features = [ "propagator" ] }
238238
# alloy
239239
# macro
240240
blockifier = { git = "https://github.com/dojoengine/sequencer", rev = "5d737b9c9", default-features = false }
241+
242+
[patch.crates-io]
243+
# NOTE: remove this patch once this PR is merged <https://github.com/starknet-io/types-rs/pull/132>
244+
#
245+
# This patch fixes an issue where we're unable to correctly evaluate the accurate size
246+
# for constructing `Felt` from unstructured data (Arbitrary).
247+
starknet-types-core = { git = "https://github.com/kariy/types-rs", rev = "0f6ae31" }

bin/katana/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version.workspace = true
99
[dependencies]
1010
katana-chain-spec.workspace = true
1111
katana-cli.workspace = true
12-
katana-db.workspace = true
12+
katana-db = { workspace = true, features = [ "arbitrary" ] }
1313
katana-primitives.workspace = true
1414
katana-rpc-types.workspace = true
1515
katana-utils.workspace = true
@@ -22,6 +22,7 @@ clap.workspace = true
2222
clap_complete.workspace = true
2323
comfy-table = "7.1.1"
2424
const_format = "0.2.33"
25+
indicatif = "0.17.8"
2526
inquire = "0.7.5"
2627
piltover = { git = "https://github.com/keep-starknet-strange/piltover.git", rev = "45263e8" }
2728
rand.workspace = true
@@ -39,9 +40,14 @@ vergen = { version = "9.0.0", features = [ "build", "cargo", "emit_and_set" ] }
3940
vergen-gitcl = { version = "1.0.0", features = [ "build", "cargo", "rustc", "si" ] }
4041

4142
[dev-dependencies]
43+
katana-provider.workspace = true
44+
45+
arbitrary.workspace = true
4246
assert_matches.workspace = true
47+
proptest = "1.0"
4348
rstest.workspace = true
4449
starknet.workspace = true
50+
tempfile.workspace = true
4551

4652
[features]
4753
default = [ "cartridge", "init-slot", "jemalloc", "katana-cli/explorer" ]

bin/katana/src/cli/db.rs

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)