-
Notifications
You must be signed in to change notification settings - Fork 10
chore: remove chain state unused fields #339
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
base: v0.42-dev
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThis PR removes network-specific initialization from ChainState and eliminates several fields including masternode engine, filter tip, chainlock hash, and masternode diff height from both the in-memory struct and FFI representation, simplifying the chain state abstraction and its serialization. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
🧹 Nitpick comments (1)
dash-spv/src/types.rs (1)
300-309: Verifynetworkparameter necessity ininit_from_checkpoint.The
networkparameter is now only used for logging. Consider whether it's worth keeping as a parameter just for the log message, or if the caller could log it instead.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
dash-spv-ffi/src/types.rsdash-spv-ffi/tests/unit/test_type_conversions.rsdash-spv/src/chain/chainlock_test.rsdash-spv/src/client/core.rsdash-spv/src/client/lifecycle.rsdash-spv/src/client/status_display.rsdash-spv/src/storage/state.rsdash-spv/src/types.rsdash-spv/tests/header_sync_test.rs
💤 Files with no reviewable changes (3)
- dash-spv-ffi/src/types.rs
- dash-spv-ffi/tests/unit/test_type_conversions.rs
- dash-spv/src/storage/state.rs
🧰 Additional context used
📓 Path-based instructions (6)
dash-spv/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
dash-spv/**/*.rs: Use async/await throughout the codebase, built on tokio runtime
Use Arc for trait objects to enable runtime polymorphism for NetworkManager and StorageManager
Use Tokio channels for inter-component message passing between async tasks
Maintain minimum Rust version (MSRV) of 1.89 and use only compatible syntax and features
Files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
dash-spv/src/client/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
Use the DashSpvClient high-level API with proper configuration via ClientConfig for client initialization
Files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/client/lifecycle.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: MSRV (Minimum Supported Rust Version) is 1.89; ensure compatibility with this version for all builds
Unit tests should live alongside code with#[cfg(test)]annotation; integration tests use thetests/directory
Usesnake_casefor function and variable names
UseUpperCamelCasefor types and traits
UseSCREAMING_SNAKE_CASEfor constants
Format code withrustfmtbefore commits; ensurecargo fmt --allis run
Runcargo clippy --workspace --all-targets -- -D warningsfor linting; avoid warnings in CI
Preferasync/awaitviatokiofor asynchronous operations
**/*.rs: Never hardcode network parameters, addresses, or keys in Rust code
Use proper error types (thiserror) and propagate errors appropriately in Rust
Use tokio runtime for async operations in Rust
Use conditional compilation with feature flags for optional features
Write unit tests for new functionality in Rust
Format code using cargo fmt
Run clippy with all features and all targets, treating warnings as errors
Never log or expose private keys in any code
Always validate inputs from untrusted sources in Rust
Use secure random number generation for keys
Files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
**/*test*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*test*.rs: Test both mainnet and testnet configurations
Use proptest for property-based testing where appropriate
Files:
dash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rs
dash-spv/tests/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
dash-spv/tests/**/*.rs: Organize tests into unit tests (in-module), integration tests (tests/ directory), real network tests (with live Dash Core nodes), and performance benchmarks
Integration tests should gracefully handle unavailable Dash Core nodes at 127.0.0.1:9999 without failing the test suite
Files:
dash-spv/tests/header_sync_test.rs
**/tests/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/tests/**/*.rs: Use descriptive test names (e.g.,test_parse_address_mainnet)
Mark network-dependent or long-running tests with#[ignore]and run with-- --ignored
Files:
dash-spv/tests/header_sync_test.rs
🧠 Learnings (23)
📓 Common learnings
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T16:01:37.609Z
Learning: The mempool tracking infrastructure (UnconfirmedTransaction, MempoolState, configuration, and mempool_filter.rs) is fully implemented and integrated in the Dash SPV client as of this PR, including client logic, FFI APIs, and tests.
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/sync/**/*.rs : Implement sequential phase-based synchronization via SyncManager with phases progressing in order: Headers → Masternode List → Filter Headers → Filters → Blocks
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/storage/**/*.rs : Store headers in 10,000-header segments with index files in headers/ directory, filter headers and compact block filters in filters/ directory, and state in state/ directory
Applied to files:
dash-spv/src/client/core.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-06-26T16:01:37.609Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T16:01:37.609Z
Learning: The mempool tracking infrastructure (UnconfirmedTransaction, MempoolState, configuration, and mempool_filter.rs) is fully implemented and integrated in the Dash SPV client as of this PR, including client logic, FFI APIs, and tests.
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/validation/**/*.rs : Implement three validation modes: ValidationMode::None (no validation), ValidationMode::Basic (structure and timestamp validation), and ValidationMode::Full (complete PoW and chain validation)
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/client/**/*.rs : Use the DashSpvClient high-level API with proper configuration via ClientConfig for client initialization
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/error.rs : Use domain-specific error types (NetworkError, StorageError, SyncError, ValidationError, SpvError) rather than generic error handling
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/network/**/*.rs : Use DNS-first peer discovery with automatic DNS seeds (dnsseed.dash.org, testnet-seed.dashdot.io) when no explicit peers are configured; implement immediate startup with 10-second delay only for subsequent peer searches
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Use async/await throughout the codebase, built on tokio runtime
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/client/status_display.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Use Arc<dyn TraitName> for trait objects to enable runtime polymorphism for NetworkManager and StorageManager
Applied to files:
dash-spv/src/client/core.rsdash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-06-26T15:54:02.509Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T15:54:02.509Z
Learning: The `StorageManager` trait in `dash-spv/src/storage/mod.rs` uses `&mut self` methods but is also `Send + Sync`, and implementations often use interior mutability for concurrency. This can be confusing, so explicit documentation should clarify thread-safety expectations and the rationale for the API design.
Applied to files:
dash-spv/src/client/core.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Maintain minimum Rust version (MSRV) of 1.89 and use only compatible syntax and features
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/tests/**/*.rs : Organize tests into unit tests (in-module), integration tests (tests/ directory), real network tests (with live Dash Core nodes), and performance benchmarks
Applied to files:
dash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/tests/**/*.rs : Integration tests should gracefully handle unavailable Dash Core nodes at 127.0.0.1:9999 without failing the test suite
Applied to files:
dash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Always validate network consistency when deriving or validating addresses; never mix mainnet and testnet operations
Applied to files:
dash-spv/src/chain/chainlock_test.rsdash-spv/tests/header_sync_test.rs
📚 Learning: 2025-12-30T22:00:57.000Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-30T22:00:57.000Z
Learning: Applies to **/*test*.rs : Test both mainnet and testnet configurations
Applied to files:
dash-spv/src/chain/chainlock_test.rs
📚 Learning: 2025-12-30T22:00:57.000Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-30T22:00:57.000Z
Learning: Applies to **/*integration*.rs : Write integration tests for network operations
Applied to files:
dash-spv/src/chain/chainlock_test.rs
📚 Learning: 2025-12-22T17:59:51.097Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-22T17:59:51.097Z
Learning: Applies to **/tests/**/*.rs : Use descriptive test names (e.g., `test_parse_address_mainnet`)
Applied to files:
dash-spv/src/chain/chainlock_test.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Use Tokio channels for inter-component message passing between async tasks
Applied to files:
dash-spv/src/chain/chainlock_test.rsdash-spv/src/types.rs
📚 Learning: 2025-12-22T17:59:51.097Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-22T17:59:51.097Z
Learning: Cover critical parsing, networking, SPV, and wallet flows in tests; add regression tests for fixes; consider property tests with `proptest`
Applied to files:
dash-spv/src/chain/chainlock_test.rs
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/src/**/*.rs : Add cbindgen annotations for complex types in FFI functions
Applied to files:
dash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/network/**/*.rs : Implement configurable timeouts with recovery mechanisms for network operations
Applied to files:
dash-spv/src/types.rsdash-spv/src/client/lifecycle.rs
📚 Learning: 2025-06-26T15:51:03.126Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T15:51:03.126Z
Learning: In Rust network code, using unwrap() on SystemTime::now().duration_since(UNIX_EPOCH) can panic if the system clock is before UNIX_EPOCH. Use unwrap_or with a safe fallback (e.g., Duration::from_secs(0)) to prevent panics in edge cases.
Applied to files:
dash-spv/src/types.rs
🧬 Code graph analysis (2)
dash-spv/src/client/core.rs (1)
dash-spv/src/client/lifecycle.rs (1)
new(30-94)
dash-spv/src/client/status_display.rs (1)
dash-spv/src/client/core.rs (1)
storage(163-165)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
- GitHub Check: Windows / spv
- GitHub Check: macOS / spv
- GitHub Check: Ubuntu ARM / spv
- GitHub Check: fuzz (hashes_cbor)
- GitHub Check: fuzz (hashes_sha512_256)
- GitHub Check: fuzz (hashes_ripemd160)
- GitHub Check: fuzz (hashes_sha512)
- GitHub Check: fuzz (dash_deserialize_script)
- GitHub Check: fuzz (dash_outpoint_string)
- GitHub Check: fuzz (hashes_json)
- GitHub Check: Pre-commit (macos-latest)
- GitHub Check: Pre-commit (ubuntu-latest)
- GitHub Check: Pre-commit (windows-latest)
- GitHub Check: Address Sanitizer
- GitHub Check: Thread Sanitizer
🔇 Additional comments (8)
dash-spv/src/types.rs (1)
244-260: Clean simplification of ChainState struct.The removal of
current_filter_tip,masternode_engine, andlast_masternode_diff_heightfields simplifies the struct nicely. The network-agnosticnew()constructor returningSelf::default()is idiomatic Rust.dash-spv/src/chain/chainlock_test.rs (1)
5-5: LGTM - Consistent with API changes.The import and constructor updates align with the removal of
new_for_network(). These ChainLock tests verify lock processing logic rather than network-specific behavior, so a network-agnosticChainStateis appropriate here.Also applies to: 14-14
dash-spv/src/client/core.rs (1)
216-220: LGTM - Consistent reset to network-agnostic baseline.The change from
ChainState::new_for_network(self.config.network)toChainState::new()is consistent with the constructor inlifecycle.rs. The network configuration remains accessible viaself.config.networkwhen needed.dash-spv/src/client/status_display.rs (1)
119-138: Good migration to storage-based masternode height retrieval.The masternode height is now correctly fetched from storage via
load_masternode_state()rather than from the now-removedChainState.last_masternode_diff_heightfield. The error handling chain with.ok().flatten().map().unwrap_or(0)is appropriate for graceful degradation.dash-spv/tests/header_sync_test.rs (2)
36-36: LGTM - Test updated to use network-agnostic constructor.The test correctly uses
ChainState::new()while still configuring the network viaClientConfig::new(Network::Dash)where network-specific behavior is actually needed. The header sync logic being tested is network-agnostic.
376-383: LGTM - Parameterized test correctly updated.Both
ChainStateinstances intest_prepare_syncare correctly updated to use the network-agnostic constructor. Thesync_base_heightis still set explicitly on line 377 for checkpoint sync testing.dash-spv/src/client/lifecycle.rs (2)
40-40: LGTM - Constructor updated to network-agnostic initialization.The change from
ChainState::new_for_network(config.network)toChainState::new()is correct. Network-specific configuration is still handled viaClientConfigwhere needed.
314-328: Good refactoring of checkpoint initialization flow.The updated
init_from_checkpointcall with the new signature(checkpoint.height, self.config.network)is correct. The pattern of:
- Initializing chain state from checkpoint
- Cloning before dropping the write lock
- Storing the checkpoint header and chain state separately
...properly avoids potential deadlocks and maintains clear separation of concerns.
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
… the storage MasternodeState stored
c2915c3 to
b2f511f
Compare
b2f511f to
4857c46
Compare
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
🧹 Nitpick comments (3)
dash-spv/src/storage/state.rs (3)
33-37: Consider using async file existence check.
path.exists()is a synchronous operation that blocks the async runtime. In high-throughput scenarios, prefertokio::fs::try_exists()or attempt to read and handleNotFounderror.♻️ Suggested refactor
- if !path.exists() { - return Ok(None); - } + match tokio::fs::metadata(&path).await { + Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None), + Err(e) => return Err(e.into()), + Ok(_) => {} + }
74-89: Same syncpath.exists()pattern as noted above.Consider the same async-friendly approach for consistency.
154-158: Silent deserialization failure could mask data corruption.When
bincode::deserializefails, the error is silently ignored. Consider logging a warning to help diagnose corrupted chain lock files.♻️ Suggested improvement
- if let Ok(chain_lock) = bincode::deserialize(&data) { - chain_locks.push((height, chain_lock)); - } + match bincode::deserialize(&data) { + Ok(chain_lock) => chain_locks.push((height, chain_lock)), + Err(e) => { + tracing::warn!( + "Failed to deserialize chain lock at height {}: {}", + height, + e + ); + } + }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
dash-spv-ffi/src/types.rsdash-spv-ffi/tests/unit/test_type_conversions.rsdash-spv/src/chain/chainlock_test.rsdash-spv/src/client/chainlock.rsdash-spv/src/client/core.rsdash-spv/src/client/lifecycle.rsdash-spv/src/client/status_display.rsdash-spv/src/storage/chainstate.rsdash-spv/src/storage/state.rsdash-spv/src/types.rsdash-spv/tests/header_sync_test.rs
💤 Files with no reviewable changes (4)
- dash-spv/src/client/chainlock.rs
- dash-spv/src/storage/chainstate.rs
- dash-spv-ffi/src/types.rs
- dash-spv-ffi/tests/unit/test_type_conversions.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- dash-spv/src/chain/chainlock_test.rs
- dash-spv/src/client/core.rs
🧰 Additional context used
📓 Path-based instructions (7)
dash-spv/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
dash-spv/**/*.rs: Use async/await throughout the codebase, built on tokio runtime
Use Arc for trait objects to enable runtime polymorphism for NetworkManager and StorageManager
Use Tokio channels for inter-component message passing between async tasks
Maintain minimum Rust version (MSRV) of 1.89 and use only compatible syntax and features
Files:
dash-spv/src/client/status_display.rsdash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
dash-spv/src/client/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
Use the DashSpvClient high-level API with proper configuration via ClientConfig for client initialization
Files:
dash-spv/src/client/status_display.rsdash-spv/src/client/lifecycle.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: MSRV (Minimum Supported Rust Version) is 1.89; ensure compatibility with this version for all builds
Unit tests should live alongside code with#[cfg(test)]annotation; integration tests use thetests/directory
Usesnake_casefor function and variable names
UseUpperCamelCasefor types and traits
UseSCREAMING_SNAKE_CASEfor constants
Format code withrustfmtbefore commits; ensurecargo fmt --allis run
Runcargo clippy --workspace --all-targets -- -D warningsfor linting; avoid warnings in CI
Preferasync/awaitviatokiofor asynchronous operations
**/*.rs: Never hardcode network parameters, addresses, or keys in Rust code
Use proper error types (thiserror) and propagate errors appropriately in Rust
Use tokio runtime for async operations in Rust
Use conditional compilation with feature flags for optional features
Write unit tests for new functionality in Rust
Format code using cargo fmt
Run clippy with all features and all targets, treating warnings as errors
Never log or expose private keys in any code
Always validate inputs from untrusted sources in Rust
Use secure random number generation for keys
Files:
dash-spv/src/client/status_display.rsdash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
dash-spv/tests/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
dash-spv/tests/**/*.rs: Organize tests into unit tests (in-module), integration tests (tests/ directory), real network tests (with live Dash Core nodes), and performance benchmarks
Integration tests should gracefully handle unavailable Dash Core nodes at 127.0.0.1:9999 without failing the test suite
Files:
dash-spv/tests/header_sync_test.rs
**/tests/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/tests/**/*.rs: Use descriptive test names (e.g.,test_parse_address_mainnet)
Mark network-dependent or long-running tests with#[ignore]and run with-- --ignored
Files:
dash-spv/tests/header_sync_test.rs
**/*test*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*test*.rs: Test both mainnet and testnet configurations
Use proptest for property-based testing where appropriate
Files:
dash-spv/tests/header_sync_test.rs
dash-spv/src/storage/**/*.rs
📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
Store headers in 10,000-header segments with index files in headers/ directory, filter headers and compact block filters in filters/ directory, and state in state/ directory
Files:
dash-spv/src/storage/state.rs
🧠 Learnings (20)
📓 Common learnings
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T16:01:37.609Z
Learning: The mempool tracking infrastructure (UnconfirmedTransaction, MempoolState, configuration, and mempool_filter.rs) is fully implemented and integrated in the Dash SPV client as of this PR, including client logic, FFI APIs, and tests.
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/sync/**/*.rs : Implement sequential phase-based synchronization via SyncManager with phases progressing in order: Headers → Masternode List → Filter Headers → Filters → Blocks
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-06-26T16:01:37.609Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T16:01:37.609Z
Learning: The mempool tracking infrastructure (UnconfirmedTransaction, MempoolState, configuration, and mempool_filter.rs) is fully implemented and integrated in the Dash SPV client as of this PR, including client logic, FFI APIs, and tests.
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Maintain minimum Rust version (MSRV) of 1.89 and use only compatible syntax and features
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Use async/await throughout the codebase, built on tokio runtime
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/storage/**/*.rs : Store headers in 10,000-header segments with index files in headers/ directory, filter headers and compact block filters in filters/ directory, and state in state/ directory
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/error.rs : Use domain-specific error types (NetworkError, StorageError, SyncError, ValidationError, SpvError) rather than generic error handling
Applied to files:
dash-spv/src/client/status_display.rsdash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/tests/**/*.rs : Organize tests into unit tests (in-module), integration tests (tests/ directory), real network tests (with live Dash Core nodes), and performance benchmarks
Applied to files:
dash-spv/tests/header_sync_test.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/network/**/*.rs : Use DNS-first peer discovery with automatic DNS seeds (dnsseed.dash.org, testnet-seed.dashdot.io) when no explicit peers are configured; implement immediate startup with 10-second delay only for subsequent peer searches
Applied to files:
dash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/tests/**/*.rs : Integration tests should gracefully handle unavailable Dash Core nodes at 127.0.0.1:9999 without failing the test suite
Applied to files:
dash-spv/tests/header_sync_test.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Use Arc<dyn TraitName> for trait objects to enable runtime polymorphism for NetworkManager and StorageManager
Applied to files:
dash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Always validate network consistency when deriving or validating addresses; never mix mainnet and testnet operations
Applied to files:
dash-spv/tests/header_sync_test.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/network/**/*.rs : Implement configurable timeouts with recovery mechanisms for network operations
Applied to files:
dash-spv/tests/header_sync_test.rsdash-spv/src/client/lifecycle.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/client/**/*.rs : Use the DashSpvClient high-level API with proper configuration via ClientConfig for client initialization
Applied to files:
dash-spv/src/client/lifecycle.rsdash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/src/validation/**/*.rs : Implement three validation modes: ValidationMode::None (no validation), ValidationMode::Basic (structure and timestamp validation), and ValidationMode::Full (complete PoW and chain validation)
Applied to files:
dash-spv/src/client/lifecycle.rsdash-spv/src/types.rsdash-spv/src/storage/state.rs
📚 Learning: 2025-06-26T15:51:03.126Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T15:51:03.126Z
Learning: In Rust network code, using unwrap() on SystemTime::now().duration_since(UNIX_EPOCH) can panic if the system clock is before UNIX_EPOCH. Use unwrap_or with a safe fallback (e.g., Duration::from_secs(0)) to prevent panics in edge cases.
Applied to files:
dash-spv/src/types.rs
📚 Learning: 2025-12-16T09:03:55.811Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv/CLAUDE.md:0-0
Timestamp: 2025-12-16T09:03:55.811Z
Learning: Applies to dash-spv/**/*.rs : Use Tokio channels for inter-component message passing between async tasks
Applied to files:
dash-spv/src/types.rs
📚 Learning: 2025-06-26T15:54:02.509Z
Learnt from: DCG-Claude
Repo: dashpay/rust-dashcore PR: 0
File: :0-0
Timestamp: 2025-06-26T15:54:02.509Z
Learning: The `StorageManager` trait in `dash-spv/src/storage/mod.rs` uses `&mut self` methods but is also `Send + Sync`, and implementations often use interior mutability for concurrency. This can be confusing, so explicit documentation should clarify thread-safety expectations and the rationale for the API design.
Applied to files:
dash-spv/src/storage/state.rs
📚 Learning: 2025-12-01T07:59:58.608Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: dash-spv-ffi/CLAUDE.md:0-0
Timestamp: 2025-12-01T07:59:58.608Z
Learning: Applies to dash-spv-ffi/src/**/*.rs : Use thread-local storage for error propagation via `dash_spv_ffi_get_last_error()` function
Applied to files:
dash-spv/src/storage/state.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/managed_account/**/*.rs : Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together
Applied to files:
dash-spv/src/storage/state.rs
🧬 Code graph analysis (4)
dash-spv/src/client/status_display.rs (1)
dash-spv/src/client/core.rs (1)
storage(163-165)
dash-spv/tests/header_sync_test.rs (1)
dash-spv/src/client/lifecycle.rs (1)
new(30-94)
dash-spv/src/types.rs (1)
dash-spv-ffi/src/broadcast.rs (1)
dashcore(36-36)
dash-spv/src/storage/state.rs (5)
dash-spv/src/storage/io.rs (1)
atomic_write(24-57)dash-spv/src/storage/chainstate.rs (4)
store_chain_state(13-13)store_chain_state(43-58)load_chain_state(15-15)load_chain_state(60-84)dash-spv/src/storage/masternode.rs (4)
store_masternode_state(12-12)store_masternode_state(42-57)load_masternode_state(14-14)load_masternode_state(59-75)dash-spv/src/storage/metadata.rs (4)
store_metadata(12-12)store_metadata(41-50)load_metadata(14-14)load_metadata(52-61)dash-spv/src/storage/filters.rs (9)
store_filter_headers(14-14)store_filter_headers(83-85)load_filter_headers(16-16)load_filter_headers(87-89)get_filter_header(18-36)get_filter_tip_height(38-38)get_filter_tip_height(91-93)store_filter(45-45)store_filter(134-136)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: Ubuntu ARM / tools
- GitHub Check: Windows / tools
- GitHub Check: Windows / rpc
- GitHub Check: fuzz (dash_script_bytes_to_asm_fmt)
- GitHub Check: fuzz (dash_outpoint_string)
- GitHub Check: fuzz (dash_deserialize_script)
- GitHub Check: fuzz (hashes_cbor)
- GitHub Check: fuzz (hashes_sha512_256)
- GitHub Check: fuzz (dash_deserialize_amount)
- GitHub Check: fuzz (hashes_ripemd160)
- GitHub Check: fuzz (dash_deser_net_msg)
- GitHub Check: Address Sanitizer
- GitHub Check: fuzz (hashes_sha256)
- GitHub Check: Thread Sanitizer
- GitHub Check: fuzz (hashes_sha1)
- GitHub Check: fuzz (hashes_sha512)
- GitHub Check: fuzz (dash_deserialize_address)
- GitHub Check: Pre-commit (ubuntu-latest)
- GitHub Check: Pre-commit (macos-latest)
- GitHub Check: Pre-commit (windows-latest)
🔇 Additional comments (12)
dash-spv/src/types.rs (3)
20-20: LGTM!Import cleanup correctly removes the now-unused
FilterHeader,MasternodeListEngine, and network extension types, aligning with the removedChainStatefields.
244-266: LGTM!The simplified
ChainStatestruct with onlylast_chainlock_heightandsync_base_heightis clean and appropriate. Theinit_from_checkpointmethod correctly sets the sync base height and provides useful logging.
268-275: LGTM!Debug implementation correctly reflects the simplified
ChainStatestructure.dash-spv/src/client/status_display.rs (1)
119-138: LGTM!Good refactor to derive
masternode_heightfrom storage rather than the now-removed in-memoryChainStatefield. The error handling chain (.ok().flatten().map(...).unwrap_or(0)) gracefully handles missing or failed state loads.dash-spv/tests/header_sync_test.rs (2)
36-36: LGTM!Correctly updated to use the network-agnostic
ChainState::new()constructor.
375-382: LGTM!Test correctly migrated to use
ChainState::new(). Thesync_base_heightis still set explicitly where needed (line 376), maintaining test validity.dash-spv/src/client/lifecycle.rs (2)
40-40: LGTM!Correctly updated to use the network-agnostic
ChainState::new()constructor.
314-328: LGTM! Improved lock handling.The refactored flow correctly:
- Initializes chain state from checkpoint
- Clones the state before dropping the write lock
- Releases the
RwLockbefore acquiring the storageMutexfor I/OThis avoids holding the chain state lock during potentially slow disk operations.
dash-spv/src/storage/state.rs (4)
187-230: LGTM!The
clear()implementation follows a safe pattern: stopping the background worker, clearing in-memory state, removing disk files with retry logic for race conditions, recreating subdirectories, and restarting the worker.
254-304: LGTM!Mempool storage is correctly implemented as in-memory only, appropriate for transient mempool data. Based on learnings, the mempool tracking infrastructure is fully implemented in this PR.
306-493: LGTM!The
StorageManagertrait implementation correctly delegates to the inherent methods. The use ofis_none_or()(lines 317, 321) is compatible with MSRV 1.89 as per coding guidelines.
495-668: LGTM!Comprehensive test coverage including:
- Basic header storage/retrieval
- Checkpoint-based storage with height offset and index rebuilding
- Persistence verification across shutdown/reload
Tests follow the coding guidelines for organization and use appropriate assertions.
Summary by CodeRabbit
Release Notes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.