Skip to content

Conversation

@ZocoLini
Copy link
Collaborator

@ZocoLini ZocoLini commented Jan 19, 2026

Needs #370

Summary by CodeRabbit

  • Refactor
    • Configuration API restructured from direct setters to a builder-based pattern for initialization
    • Network-specific builder functions replace direct config creation with fluent configuration methods
    • Final build() call required to finalize configuration before use

✏️ Tip: You can customize this high-level summary in your review settings.

@ZocoLini ZocoLini marked this pull request as draft January 19, 2026 21:24
@github-actions
Copy link

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@github-actions github-actions bot added the merge-conflict The PR conflicts with the target branch. label Jan 19, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

This pull request refactors the FFI and Rust configuration APIs from direct manipulation to a builder pattern. FFIClientConfigBuilder replaces direct FFIClientConfig functions, ClientConfigBuilder is introduced in Rust with derive macros for configuration, and validation logic is restructured into trait-based validators. Storage and accessor patterns are updated throughout to use the new builder-derived configurations and method calls instead of direct field access.

Changes

Cohort / File(s) Summary
FFI API Documentation & Type Definitions
dash-spv-ffi/FFI_API.md, dash-spv-ffi/dash_spv_ffi.h, dash-spv-ffi/include/dash_spv_ffi.h
Introduced FFIClientConfigBuilder struct and transitioned all config setters from dash_spv_ffi_config_set_* to builder variants. Added builder lifecycle functions (build, destroy) and renamed getters (e.g., get_data_dirget_storage_path). Added new accessors for config queries (network, storage_path, mempool tracking).
FFI Examples & Rust Examples
dash-spv-ffi/examples/basic_usage.c, dash-spv-ffi/examples/wallet_manager_usage.rs, dash-spv/examples/filter_sync.rs, dash-spv/examples/simple_sync.rs, dash-spv/examples/spv_with_wallet.rs
Updated config initialization from direct creation to builder pattern. Replaced dash_spv_ffi_config_testnet() with dash_spv_ffi_config_builder_testnet() + build(). Storage managers now initialized with config reference instead of path. Wallet initialization uses config.network() method call.
FFI CLI & Client Implementation
dash-spv-ffi/src/bin/ffi_cli.rs, dash-spv-ffi/src/client.rs, dash-spv-ffi/src/config.rs
Core FFI implementation migrated to builder pattern. FFIClientConfigBuilder struct added with From conversion from ClientConfigBuilder. Builder setters, build, and destroy functions implemented. Removed dash_spv_ffi_client_enable_mempool_tracking. Storage path handling simplified to use config-derived paths.
FFI Test Updates
dash-spv-ffi/tests/c_tests/test_*.c, dash-spv-ffi/tests/c_tests/test_*.rs, dash-spv-ffi/tests/integration/test_*.rs, dash-spv-ffi/tests/security/test_*.rs, dash-spv-ffi/tests/test_*.rs
Updated all FFI test code to use builder pattern. Replaced dash_spv_ffi_config_set_* with builder variants. Removed deprecated test_config.rs. Updated assertions and config instantiation across ~15 test files.
Rust Configuration & Builder
dash-spv/src/client/config.rs
Introduced ClientConfigBuilder with derive macros (Builder, Getters, CopyGetters). Converted all public fields to private with generated accessors. Added network-specific builders (mainnet, testnet, devnet, regtest). Implemented validation, JSON deserialization, and dynamic peer management. Changed default storage_path to "./dash-spv-storage".
Rust Core & Lifecycle
dash-spv/src/client/core.rs, dash-spv/src/client/lifecycle.rs, dash-spv/src/client/mod.rs
Updated all direct field access to use method calls (e.g., config.networkconfig.network()). Migrated config setters to use builder pattern in tests. Removed explicit config validation from DashSpvClient::new. Adjusted module visibility (config changed from pub mod to private mod with selective re-exports).
Rust Validation Refactoring
dash-spv/src/validation/header.rs, dash-spv/src/validation/instantlock.rs, dash-spv/src/validation/mod.rs
Replaced standalone validate_headers() function with BlockHeaderValidator struct implementing Validator trait. Refactored InstantLockValidator to require MasternodeListEngine at construction and use trait-based validate. Added public Validator trait. Removed validation module from public sync headers API.
Rust Storage & Manager Refactoring
dash-spv/src/storage/mod.rs, dash-spv/src/client/message_handler.rs, dash-spv/src/client/mempool.rs, dash-spv/src/client/sync_coordinator.rs, dash-spv/src/sync/*.rs
DiskStorageManager::new signature changed from (path: impl Into<PathBuf>) to (config: &ClientConfig). Updated all direct config field access to method calls throughout message handling, mempool, sync coordination, and header/masternode managers. Removed public config_start_height accessor.
Rust Network & Dependencies
dash-spv/src/lib.rs, dash-spv/src/main.rs, dash-spv/src/network/manager.rs, dash-spv/src/mempool_filter.rs, dash-spv/src/network/handshake.rs, dash-spv/Cargo.toml
Added ClientConfigBuilder and MempoolStrategy to public re-exports. Updated main.rs to use builder-based config construction and network() accessor. Refactored network manager to use config.storage_path(), config.network(), and config.peers() methods. Updated MempoolStrategy import path. Added derive_builder and getset dependencies.
Rust Benchmarks & Integration Tests
dash-spv/benches/storage.rs, dash-spv/tests/block_download_test.rs, dash-spv/tests/chainlock_simple_test.rs, dash-spv/tests/edge_case_filter_sync_test.rs, dash-spv/tests/filter_header_verification_test.rs, dash-spv/tests/handshake_test.rs, dash-spv/tests/header_sync_test.rs, dash-spv/tests/peer_test.rs, dash-spv/tests/smart_fetch_integration_test.rs, dash-spv/tests/test_handshake_logic.rs, dash-spv/tests/wallet_integration_test.rs
Refactored ~15 test files to use ClientConfigBuilder pattern. Updated DiskStorageManager calls to pass &config instead of paths. Adjusted WalletManager initialization to use config.network() method. Removed direct TempDir handling in favor of builder-based storage_path configuration. Updated MempoolStrategy import paths.
Rust Type & Helper Updates
dash-spv/src/client/config_test.rs, dash-spv/src/client/message_handler_test.rs, dash-spv/src/client/status_display.rs, dash-spv/src/sync/headers/manager.rs, dash-spv/src/sync/headers/mod.rs, dash-spv/src/sync/manager.rs, dash-spv/src/sync/masternodes/manager.rs, dash-spv/src/sync/post_sync.rs, dash-spv/src/sync/transitions.rs, dash-spv/src/types.rs
Deleted config_test.rs. Introduced ReorgConfig struct for header sync. Removed pub mod validation from headers/mod.rs. Updated all config field accesses to method calls throughout sync pipeline. Simplified test setup by removing explicit mutability where mempool tracking mutations were removed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • QuantumExplorer

Poem

🐰 Hops through the builder pattern so fine,
Config now flows in a cleaner design,
No more direct field access with glee,
Method calls reign o'er the spree,
Validation traits make the code shine!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main architectural change: introducing a builder pattern for configuration that can be constructed from JSON readers, replacing direct FFI config creation and setter methods.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ZocoLini ZocoLini changed the base branch from v0.42-dev to refacor/config-builder January 19, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR conflicts with the target branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants