Repository navigation
chore: catch up master to v0.44.0 - #1207
Merged
Merged
Conversation
…463) Emit `SyncComplete` on every not-synced to synced transition instead of only once, with a cycle field (0 = initial, 1+ = incremental) so consumers can distinguish sync phases. Duration logging measures per-cycle time instead of time since client start. Co-authored-by: Kevin Rombach <35775977+xdustinface@users.noreply.github.com>
Set `RUST_BACKTRACE=1` in CI workflows so test failures print full backtraces.
Cleanup dead code.
At the moment `None` managers use `unwrap_or(0.0)` which dragged down the percentage when only some managers are active like when filters are disabled, only block headers are active. With this PR only phases that have actually started contribute to the average.
`dash_spv_ffi_sync_progress_destroy` didn't cleanup the nested progress pointers which leads to leaks on cleanup. This PR merges `dash_spv_ffi_sync_progress_destroy` into `dash_spv_ffi_manager_sync_progress_destroy`.
The PR #474 somehow sneaked a failure into the CI.
We currently just silently ignore any failure inside the sync coordinator or `monitor_network` thread. This PR propagates them and also adds a FFI callback structure which can be set to receive notifications about errors inside the SPV client.
Use `allow_addr2line=1` so ASAN falls back to the pre-installed `addr2line` for symbolization. This avoids LLVM version mismatch issues between the system `llvm-symbolizer` and nightly Rust's LLVM, and works regardless of which LLVM version nightly uses. Also enable `force-frame-pointers` for more complete stack traces.
…rs (#467) - Moves initialization logic out of the `SyncManager::initialize()` trait method and into each manager's constructor. - Genesis block is now stored before managers are created, so they can read the tip during construction. - The `SyncCoordinator` seeds initial progress from actual manager state instead of default and uses `WatchStream::from_changes` to avoid re-emitting all initial progresses.
Introduce new functions in `MetadataStorage` to save/load the last known target height, and integrate it into the block headers manager. This allows the UI to show a more realistic state after restart during sync before connections are established.
Send the current sync progress to a newly registered callback immediately on registration, so callers don't have to wait for the next progress update to get the current state.
…in `ManagedWalletInfo` (#483)
Add a required `clear_in_flight_state()` method to the `SyncManager` trait and implement it for all managers. This gets called by the default `stop_sync()` implementation to force every manager to handle disconnect cleanup.
…485) Adds a `thread_local` flag to `LoggingConfig` that uses `tracing::subscriber::set_default` (thread-local) instead of `try_init` (global). This allows multiple independent loggers in the same process, primarily for parallel tests where each test needs its own log subscriber. The `LoggingGuard` now holds an optional `DefaultGuard` to keep the thread-local subscriber alive. Additionally, the FFI client's tokio runtime builder propagates the caller's tracing dispatcher to worker threads via `on_thread_start`, so spawned async tasks capture logs through the correct subscriber.
Deduplicate `GetHeaders` → `GetHeaders2` upgrade logic from `send_to_single_peer` and `send_distributed` into a shared `send_message_to_peer` method.
When synced, `handle_headers_pipeline` always calls `send_pending()` after receiving each new block header, triggering a follow-up `GetHeaders` that always returned empty. This causes lot of unnecessary round-trips and leaves the tip segment in a pending state that rejected the next actual header as "unrequested headers". Use `tip_was_complete` to distinguish unsolicited headers from active catch-up responses. Only skip `send_pending()` and mark the tip complete for the unsolicited case, so multi-batch catch-up still works correctly.
Inspired by #492 but integrated into the existing workflows.
Codecov requires one flag per upload. Switch from per-crate flags to group-based flags matching CI matrix groups (core, spv, wallet, ffi, rpc). Exclude the tools group from coverage since fuzz targets produce unusable reports.
* feat: add `dashd` integration tests for SPV sync Adds comprehensive integration tests that verify SPV sync against a real `dashd` instance with pre-generated regtest blockchain: [dashpay/regtest-blockchain](https://github.com/dashpay/regtest-blockchain) - CI infrastructure: `contrib/setup-dashd.py` for cross-platform dashd/test-data setup, GitHub Actions caching and log retention on test failure - Shared test utilities in `dash-spv/src/test_utils/`: `DashCoreNode` (`dashd` process management, RPC), `DashdTestContext` (common setup), filesystem helpers - FFI test utilities in `dash-spv-ffi/src/test_utils/`: `CallbackTracker` (callback verification), `FFITestContext` (FFI client wrapper lifecycle management) - SPV tests: basic sync, empty wallet, multi-wallet, restart consistency, restart with fresh wallet, multiple restarts, random restarts, peer disconnection (exclusive and non-exclusive mode), incremental transactions (single block, across blocks) - FFI tests: wallet sync, incremental sync, restart consistency, all-callbacks verification, post-sync transaction and disconnect callbacks * replace `dashd_sync.rs` with `dashd_sync/main.rs` * make `copy_dir` less public * restructure FFI dashd integration tests into dashd_sync/
Let's make patch coverage checks informal for now to avoid simple changes like #505 getting blocked. I generally think we should enforce it, but rather after we fixed the test coverage of the repo to be much higher than what is currently then it's less likely for changes like this to be flagged.
While the `informational: true` was unblocking merges the `target`/`threshold` still causing the check to show as failed/red which is misleading. With this the patch coverage should become truly informational.
`Swatinem/rust-cache@v2` defaults to `cache-bin: true`, which caches `~/.cargo/bin`. On macOS aarch64 the rustup proxies are hardlinks to a single binary, and after a partial (prefix-match) cache restore `cargo` can end up pointing to the `rustup-init` installer instead of the rustup proxy, making every `cargo test` invocation fail with `error: unexpected argument 'test' found`. Disable bin caching so the toolchain is always reinstalled by `dtolnay/rust-toolchain@stable`. Bump `prefix-key` to `v1-rust` to invalidate the existing poisoned caches, since GitHub Actions cache rejects saves to an existing key and prefix-match restore would otherwise keep pulling the bad tar.
…ce (#769) * feat(key-wallet): ApplyChainLockOutcome surfaces metadata advance flag Replace the BTreeMap return of `WalletInfoInterface::apply_chain_lock` with an explicit `ApplyChainLockOutcome { per_account, metadata_advanced }` so the wallet-manager-level emitter can fire one event per effect: `TransactionsChainlocked` when records were promoted, and a separate event whenever `last_applied_chain_lock` advanced (added in the next commit). The two effects fire independently — a quiescent wallet that sees a chainlock above its history still advances the finality boundary even though no record is promoted. Durable consumers that persist `last_applied_chain_lock` (e.g. the platform-wallet bridge that uses it to build a `ChainAssetLockProof` for `InBlock` asset-lock TXs on restart) need a signal on every boundary advance, not just on the promotion path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(key-wallet-manager): emit ChainLockApplied event on metadata advance Add a new `WalletEvent::ChainLockApplied { wallet_id, chain_lock }` variant that fires whenever a wallet's `last_applied_chain_lock` metadata advances forward (or moves from `None` to `Some`), and route it through the FFI dispatcher. `apply_chain_lock` now reads `ApplyChainLockOutcome` from the wallet info and emits up to two events per wallet, in this order: 1. `ChainLockApplied` when the metadata advanced, so persisters that need to mirror `last_applied_chain_lock` to durable storage have a single hook regardless of whether any record was promoted. This is the gap the platform-wallet bridge had to live with: a chainlock that advanced the boundary without promoting anything was completely invisible, and the persisted `last_applied_chain_lock` went stale, which broke restart-time `ChainAssetLockProof` construction for `InBlock` asset-lock TXs. 2. `TransactionsChainlocked` when at least one record was promoted from `InBlock` to `InChainLockedBlock` (unchanged contract). Ordering matters: `ChainLockApplied` fires FIRST so a persister listening to both events can write durable metadata before the promotion record. FFI: adds `OnWalletChainLockAppliedCallback` and an `on_chain_lock_applied` field appended to `FFIWalletEventCallbacks` (before `user_data`) so existing offsets stay stable for C consumers. Event-tests updated to reflect the new two-event contract on chainlock promotion, the metadata-only advance path, and the higher-replay path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(dash-spv-ffi): preserve user_data ABI offset + test ChainLockApplied dispatch CodeRabbit caught that the new `on_chain_lock_applied` field was inserted before `user_data` in `FFIWalletEventCallbacks`, which shifted `user_data`'s byte offset and contradicted the layout-stability claim in the doc comment — C-side consumers hand-allocating this struct from older headers (i.e. without regenerating via cbindgen) rely on `user_data` staying where it was. Move the new field strictly to the end so every prior field — including `user_data` — keeps its previous offset, and rewrite the field's doc comment to reflect the new placement and the actual ABI guarantee. Also adds the `ChainLockApplied` dispatch unit test CodeRabbit suggested as a nice-to-have, sitting alongside the existing dispatch tests at the bottom of `callbacks.rs`. The test registers an `extern "C"` callback, fires a `WalletEvent::ChainLockApplied` carrying a synthetic `ChainLock::dummy(777)`, and asserts the callback received `cl_height == 777` — pinning the dispatch path against silent regressions. Refs: #769 (comment) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(dash-spv-ffi): wire on_chain_lock_applied into dashd_sync test fixture Appending `on_chain_lock_applied` to `FFIWalletEventCallbacks` broke the integration-test fixture in `dashd_sync/callbacks.rs`, which constructs the struct with all fields named explicitly (no `..Default::default()` spread). CI under `cargo test -p dash-spv-ffi --all-features` failed with `error[E0063]: missing field on_chain_lock_applied`, which cascaded into every job that builds the FFI test suite (ffi matrix, pre-commit, address-sanitizer). The new wallet-event tests don't need this callback, so wire it as `None` — same shape as the freshly-added `on_transactions_chainlocked` slot right above it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * style: rustfmt over-long assert_eq! lines in event_tests Two `assert_eq!` calls added earlier on this branch (commits 3a6e452 / de28922) exceed the workspace rustfmt width and now fail the `cargo fmt` pre-commit hook on macOS/Ubuntu/Windows. Straight `cargo fmt --all` output — no behaviour change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(key-wallet-manager): fold ChainLockApplied into ChainLockProcessed Per @xdustinface's review on #769: keep chainlock fan-out atomic by collapsing the two-event split (`ChainLockApplied` + `TransactionsChainlocked`) into a single `WalletEvent::ChainLockProcessed`, fired whenever the wallet's `last_applied_chain_lock` advances. Net-new per-account promotions ride along in `locked_transactions` — possibly empty when the chainlock advanced the metadata boundary without promoting any record (durable consumers that persist the chainlock proof still observe those empty-promotion events). Surface changes: * `WalletEvent::TransactionsChainlocked` → `WalletEvent::ChainLockProcessed` * `ApplyChainLockOutcome.per_account` → `locked_transactions` (matching the event field name; outcome and event speak the same vocabulary) * `WalletEvent::ChainLockApplied` removed entirely * `OnWalletTransactionsChainlockedCallback` → `OnWalletChainLockProcessedCallback`, signature unchanged * `FFIWalletEventCallbacks.on_transactions_chainlocked` → `on_chain_lock_processed`; the separate `on_chain_lock_applied` slot is gone, so `FFIWalletEventCallbacks` shrinks by one callback pointer (a hard ABI break for the unreleased addition, fine since v0.42 hasn't shipped) * `ffi_cli`'s `on_wallet_transactions_chainlocked` printer renamed `on_wallet_chain_lock_processed`; emits "[Wallet] ChainLock processed" Emission semantics: `process_block.rs` now sends one event per wallet per chainlock, gated on `outcome.metadata_advanced`. Replays of the same chainlock height are silent. Tests in `key-wallet-manager/src/event_tests.rs` and `key-wallet/src/tests/keep_finalized_transactions_tests.rs` updated to the merged shape, including the empty-`locked_transactions` case for chainlocks that advance the boundary without promoting any record. Dispatch test coverage strengthened per CodeRabbit's nitpick on #769#discussion (1203-1218): replaces the height-only assertion with two tests at the bottom of `dash-spv-ffi/src/callbacks.rs`: * `test_chain_lock_processed_dispatch_round_trips_every_field` — registers an `extern "C"` callback, captures every wired argument into a typed `Captured` struct, fires a `ChainLockProcessed` with two distinct accounts (one txid each), and asserts wallet_id hex-encoding, height, 32-byte block hash, 96-byte signature, and `finalized_count == 2` (counts (account, txid) pairs, not accounts). * `test_chain_lock_processed_dispatch_fires_with_empty_promotions` — empty `locked_transactions` must still fire the callback with `finalized_count == 0`; pins the contract for durable consumers that persist the chainlock proof even when no record was promoted. Closes the design pushback on #769; addresses the dispatch-test nitpick in the same review. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…#773) `dash/embedded` has been non-buildable since #521 dropped `no-std` support from `dashcore`: it requests a `dashcore` `no-std` feature that no longer exists, so its committed `Cargo.lock` can no longer be regenerated. That stale lockfile was the source of Dependabot security alerts (`linked_list_allocator` 0.8.11, RUSTSEC-2022-0063 out-of-bounds writes, pulled via the abandoned `alloc-cortex-m`, plus the yanked `core2`). The example is not a member of the root workspace and is not built in CI, so it is dead code. `fuzz` is a member of the root workspace, so cargo always resolves it against the gitignored root `Cargo.lock`. The committed `fuzz/Cargo.lock` is never read by any build (confirmed via `cargo locate-project --workspace`) and only served to surface Dependabot advisories (`atty`, `ansi_term`, `memmap`) for a file nothing uses. Removing both eliminates the Dependabot alerts at their source with no behavior change.
…766) The helper's `BlockProcessed { chain_lock: Some(_), .. }` branch returned the tx's own block height instead of the chainlock's height, which broke `test_chainlock_promotes_in_block_tx` whenever the SPV client processed the tx's block after the chainlock had already arrived (the common ordering when filter sync runs ahead of block delivery). In that case the wallet emits `BlockProcessed` with the chainlock attached, the helper returned the tx block height, and the test's `promoted_at >= cl_height` assertion failed even though the tx was correctly chainlocked.
…h` (#772) `DashSpvClient::run()` took an external `CancellationToken` and the client separately tracked `running: Arc<RwLock<bool>>`, two mechanisms for one concept. Shutdown also relied on the `running` flag being observed only on the next 100ms `sync_coordinator` tick. Both are now a single `Arc<watch::Sender<bool>>`: `true` while running, `false` once a stop is requested. `run()` drops its parameter, subscribes before the internal `start()`, and breaks its loop immediately when the value flips, so `stop()` is an event rather than a poll. `start()`/`stop()` use `send_replace`, so they are correct with zero receivers (the normal state during `run -> stop -> run` and when `stop()` is called without `run()`). `is_running()` keeps its signature, reading the watch via `borrow()`. `stop()` now flips the state before tearing down the sync coordinator, so a concurrent `run()` loop wakes and exits before it can lock the coordinator again. This removes the window where a tick could race the shutdown.
* feat(dash-spv): log version with git commit for dev builds Add a `build.rs` that captures the git commit, a dirty flag, and whether `HEAD` is at a `v*` release tag, exposed through a `version_info()` helper next to `VERSION`. `DashSpvClient::new()` logs it once on creation. Tagged clean builds render just `dash-spv <version>`, while development builds include the commit (with a `-dirty` marker for uncommitted changes) so they are recognizable as non-release. Falls back to the bare version when git is unavailable, such as packaged builds. * fix(dash-spv): watch active branch ref in `build.rs` rerun-if-changed `.git/HEAD` only changes when switching branches, not when committing on the current one, so watching `HEAD`/`index`/`packed-refs` could leave `DASH_SPV_GIT_HASH` stale across metadata-driven rebuilds. Also watch the symbolic HEAD target's ref file. Addresses CodeRabbit review comment on PR #770 #770 (comment) * fix(dash-spv): resolve git dirty state via compile-time macro `DASH_SPV_GIT_DIRTY` was baked by `build.rs`, but `git status` reflects the whole repository while a build script only reruns when one of its declared `rerun-if-changed` paths changes. An unstaged edit under `dash-spv`, a sibling crate like `key-wallet`, or `Cargo.toml` rebuilds the crate without rerunning the script, so the flag kept its cached value until the next stage or commit. Widening the watched paths cannot cover the unbounded working tree, and forcing the script to rerun every build recompiles the crate on every build (`rust-lang/cargo#3404`). A procedural macro is expanded as part of compiling the invoking crate, so it re-evaluates exactly when the crate is recompiled, which is precisely when an unstaged edit (here or in a dependency) takes effect, and not at all on a no-op build, so there is no per-build cost. The new `git-state` crate exposes `git_dirty!()`, which runs `git status` against `CARGO_MANIFEST_DIR` at expansion and degrades to `false` when git or the source tree is unavailable. `build.rs` keeps emitting the hash and tag, and its `.git` watching now doubles as the trigger that recompiles the crate (and re-runs the macro) on commit, keeping the dirty flag correct there too. The crate is named generically rather than after dash-spv since the macro is repository-agnostic. Addresses ZocoLini review comment on PR #770 #770 (comment) * ci: exclude `git-state` crate from test groups `verify-groups` fails when a workspace crate is in neither a group nor the excluded list. `git-state` is a compile-time proc-macro with no test target. Its behavior is covered transitively by the `dash-spv` `version_info` test, so it goes in the excluded section with a reason, like the other non-unit-tested crates.
Co-authored-by: QuantumExplorer <11468583+QuantumExplorer@users.noreply.github.com>
…#778) * chore: migrate from `vX.Y-dev` branching model to single `dev` branch Switch the development model away from per-release `vX.Y-dev` branches (`v0.40-dev`, `v0.41-dev`, `v0.42-dev`, each going stale after its release) to a single permanent `dev` branch as the default for active development, with `master` renamed to `main` to track the latest tagged release. Release branches (`chore/release-vX.Y.Z`) are still cut from `dev` per release for the review window, then merged back. Updates the file-level references that hardcode the old model: - CI workflow triggers (`pre-commit`, `rust`, `sanitizer`, `conflict-check`) now fire on pushes to `main` / `dev` instead of `master` / `v**-dev`. - `CLAUDE.md`, `AGENTS.md`, `CONTRIBUTING.md`, `README.md` describe the new branching model and target branches. - README codecov badges point at `branch/main` and `branch/dev`. The actual GitHub-side actions (rename `master` -> `main`, rename `v0.42-dev` -> `dev`, change default branch, update branch-protection rules) are repo settings and must be performed by an admin separately. Order matters: tag `v0.42.0` from `v0.42-dev` first, then perform the GitHub renames, then merge this PR against `dev`. To fix it up locally just run: ``` git branch -m v0.42-dev dev git fetch origin git branch -u origin/dev dev git remote set-head origin -a ``` * Update CONTRIBUTING.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ons` (#768) * fix(dash-spv): defer `Syncing` transition in `send_qrinfo_for_tip` until after send A `BlockHeaderSyncComplete` event delivered while `MasternodesManager` is in `WaitingForConnections` reaches `send_qrinfo_for_tip` with no peers connected. The previous order set state to `Syncing` before `requests.request_qr_info(...)?` propagated `Err("No connected peers")`, leaving the manager in `Syncing` with `qrinfo_in_flight = None`. `tick` only retries when `qrinfo_in_flight.is_some()` so the manager was stuck until the next external event. Reorder so the state mutation only happens after the send and the in-flight bookkeeping have committed. On send failure the manager remains in `WaitingForConnections` and the next `start_sync` (or buffered `BlockHeaderSyncComplete` after reconnect) cleanly retries. * fix(dash-spv): drop `ChainLockManager` sync events while waiting for connections `MasternodeStateUpdated` is a one-shot trigger that flips `masternode_ready` and forces `Synced`. A buffered event consumed while the manager is in `WaitingForConnections` (between `stop_sync` and the next `start_sync`) would force a peerless `Synced`, contradicting the network state. Gate `handle_sync_event` on `WaitingForConnections`. `on_disconnect` already resets `masternode_ready`, and `MasternodesManager` re-emits `MasternodeStateUpdated` from both `verify_and_complete` and `complete_incremental_pipeline` on the next sync cycle after reconnect, so dropping the buffered event loses nothing. * fix(dash-spv): drop `InstantSendManager` sync events while waiting for connections A buffered `MasternodeStateUpdated` consumed during `WaitingForConnections` would run `validate_pending` against state that `on_disconnect` already cleared. The existing `set_state(Synced)` was already gated on `Syncing | WaitForEvents` so state transitions were not affected, but the validation work itself is meaningless while peerless. Gate `handle_sync_event` on `WaitingForConnections`. `MasternodesManager` re-emits `MasternodeStateUpdated` on the next sync cycle after reconnect.
* fix(dash): return known genesis hash for `Network::Devnet` The static height-0 devnet genesis block has a deterministic hash (verified by the existing `devnet_genesis_full_block` test). Returning `None` here caused `dash-spv` to fail with `"No known genesis hash for network"` when initializing storage for a devnet. Only the height-1 "devnet genesis" varies per devnet name, height 0 does not. * fix(dash): use `LlmqtypeDevnetPlatform` for `Network::Devnet` platform quorum `platform_type()` returned `LlmqtypeDevnet`, but Dash Core's devnet defaults use `LLMQ_DEVNET_PLATFORM` for `llmqTypePlatform` (see `chainparams.cpp:651`). This matches the standard devnet config `llmqplatform=llmq_devnet_platform`. * feat(dash-spv): add `devnet` to `--network` CLI Allows targeting `Network::Devnet` from the `dash-spv` binary. Required for SPV-syncing a devnet, since previously only mainnet, testnet, and regtest were exposed. * feat(dash-spv): add `--devnet-name` for devnet handshake compatibility Dash Core nodes on devnet check that incoming peers carry `devnet.<network-id>` in their user agent and disconnect otherwise (see `net_processing.cpp:3957-3967`). The `network-id` is `devnet-<name>` per `ArgsManager::GetDevNetName`, so the substring required for the `paloma` devnet is `devnet.devnet-paloma`. The new flag is required whenever `--network=devnet`, and the user agent is rebuilt as `/rust-dash-spv:<version>(devnet.devnet-<name>)/` so devnet peers accept the handshake. * feat: support `LLMQ_DEVNET` params override via `ClientConfig` Dash Core's `-llmqdevnetparams=<size>:<threshold>` lets a devnet adjust the `LLMQ_DEVNET` quorum size and threshold (`chainparams.cpp:UpdateLLMQDevnetParameters`). Without matching params, the SPV client picks the wrong masternodes when reconstructing the signing set, so ChainLock and legacy InstantSend signatures cannot be verified on devnets that use the override. `ClientConfig::llmq_devnet_params: Option<(u32, u32)>` carries the override and `DashSpvClient::new` applies it after `validate`. Internally this writes to a `OnceLock` in `dashcore::sml::llmq_type` that `LLMQType::params()` consults for `LlmqtypeDevnet`, mirroring Dash Core's chainparams-as-global model without exposing the setter beyond the lib. Only `LLMQ_DEVNET` is affected (matches Dash Core, the DIP0024 and platform devnet quorums are not adjusted by this flag). The `dash-spv` binary exposes the override as `--llmq-devnet-params=<size>:<threshold>`, valid only with `--network=devnet`. * fix(dash): make `set_llmq_devnet_params` idempotent for identical values The `apply_global_overrides` doc claimed idempotent behavior, but `OnceLock::set` rejected every second call regardless of value. Constructing multiple `DashSpvClient` instances with the same devnet config in one process therefore failed on the second call. Now the setter compares against the existing value and returns `Ok(())` when it matches, only erroring on a genuine conflict. Addresses CodeRabbit review comment on PR #784 #784 (comment) * test(dash): cover `LLMQ_DEVNET` override contract Add a single test that walks through valid initial set, idempotent reapplication of the same values, and rejection of a conflicting reapplication. The three checks share one test because `LLMQ_DEVNET_OVERRIDE` is a process-global `OnceLock` that cannot be reset between tests. Addresses CodeRabbit review comment on PR #784 #784 (comment) * refactor(dash): use `LlmqDevnetParams` struct instead of `(u32, u32)` tuple `Option<(u32, u32)>` was unreadable at call sites — `with_llmq_devnet_params(13, 9)` is one transposition away from a silent bug. Introduce a named struct in `dashcore::sml::llmq_type` so the size/threshold meaning is explicit everywhere it crosses an API boundary. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Quantum Explorer <quantum@dash.org> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
#781) `check_compact_filters_for_addresses` ran `address.script_pubkey()` per address per filter batch, pushing OP_DUP / OP_HASH160 / hash / OP_EQUALVERIFY / OP_CHECKSIG into a fresh `ScriptBuf` every call. A dhat profile of a full testnet sync showed `ScriptBuf::new_p2pkh` was hit ~7 million times for ~172 MB of lifetime bytes, dominated by this path. `AddressInfo` already stores `script_pubkey: ScriptBuf` from address generation. Read from that cache instead of reconstructing: - `AddressPool`, `ManagedAccountType`, `ManagedAccountRef`, and `ManagedAccountTrait` expose `all_script_pubkeys` alongside `all_addresses`. - `WalletInfoInterface` and `WalletInterface` expose `monitored_script_pubkeys` and `monitored_script_pubkeys_for`. The parallel `Vec<Address>` accessor is dropped, no remaining caller. - `BlockProcessingResult.new_scripts` and `SyncEvent::BlockProcessed.new_scripts` carry `Vec<ScriptBuf>` so the rescan path on `FiltersBatch` consumes cached scripts directly. - `check_compact_filters_for_addresses` becomes `check_compact_filters_for_script_pubkeys`, taking `&[ScriptBuf]` and handing the inner bytes to `BlockFilter::match_any`.
…788) * fix(dash): decode `LlmqtypeDevnetPlatform` from `u8` `From<u8> for LLMQType` was missing the `107 => LlmqtypeDevnetPlatform` arm, so wire decoders silently mapped Platform quorum messages to `LlmqtypeUnknown`. Add it so devnet Platform routing can be observed by SPV when overrides are exercised. * feat(dash): add devnet LLMQ routing overrides Mirror Dash Core's `-llmqchainlocks`, `-llmqinstantsenddip0024`, and `-llmqplatform` flags with process-global `OnceLock` setters and getters. Wire them into `NetworkLLMQExt::{chain_locks_type, isd_llmq_type, platform_type}` so the `Network::Devnet` arms honor any active override. Setters reject types outside Dash Core's devnet allowlist (`50_60`, `60_75`, `400_60`, `400_85`, `100_67`, `devnet`, `devnet_dip0024`, `devnet_platform`) and enforce the rotation invariants Core applies in `chainparams.cpp`: ChainLocks must not rotate, InstantSend DIP24 must rotate, Platform has no rotation constraint. Setters are idempotent on identical re-set and error on conflict, matching the existing `set_llmq_devnet_params` contract. `enabled_llmq_types(Devnet)` expands to all eight devnet-registered LLMQ types so DKG window scheduling tracks any legal routing target. `devnet_llmq_type_from_name` parses the Dash-Core name set, accepting `llmq_dev_platform` as a defensive alias for this crate's local spelling of `LLMQ_DEV_PLATFORM`. * feat(dash-spv): consolidate devnet knobs into `DevnetConfig` Replace `ClientConfig.llmq_devnet_params` and the free-floating `--devnet-name` CLI flag with a single `Option<DevnetConfig>` field on `ClientConfig`. The struct collects every devnet-only setting in one place and surfaces the routing overrides added in the previous commit (`-llmqchainlocks`, `-llmqinstantsenddip0024`, `-llmqplatform`). `ClientConfig::validate` collapses to a biconditional: `devnet.is_some() == (network == Network::Devnet)`. The devnet user-agent suffix (`/rust-dash-spv:VERSION(devnet.devnet-NAME)/`) moves off `main.rs` and onto `DevnetConfig::user_agent`, so library consumers building a devnet client get the same handshake string without re-implementing it. `main.rs` gains `--llmq-chainlocks`, `--llmq-instantsend-dip0024`, `--llmq-platform` flags and extracts `build_client_config(&Args, PathBuf)` so the `Args` → `ClientConfig` mapping is unit-testable. * test: cover `DevnetConfig` validation and CLI mapping `config_test.rs` adds round-trip, user-agent format, table-driven validation matrix, empty-name rejection, and a single-test forwarding check that exercises all four `apply_global_overrides` slots in one shot. The forwarding test owns the process-global `OnceLock`s for the whole binary, comment block calls that out so future tests don't accidentally collide. `main.rs` gains a `tests` module that drives the extracted `build_devnet_config`, `build_client_config`, and `parse_llmq_devnet_params` helpers via clap's `try_parse_from`: covers missing `--devnet-name`, devnet flags rejected on non-devnet networks, minimal devnet build, full five-flag compose, parse-error shapes, and unknown quorum-name rejection. * chore: pr cleanup Hoist three duplicate `use crate::sml::llmq_type::network::NetworkLLMQExt;` lines out of individual lifecycle tests in `dash/src/sml/llmq_type/mod.rs` into the `mod tests` module top, and pull `use dashcore::sml::llmq_type::{...}` out of `test_apply_global_overrides_forwards_all_slots` in `dash-spv/src/client/config_test.rs`. Replace inline fully-qualified paths in `dash-spv/src/main.rs`: `dash_spv::ValidationMode` and `dash_spv::LLMQType::*` become normal imports; `tempfile::TempDir::new()` in the test module uses `use tempfile::TempDir;` instead. Trim cross-referencing comments that named sibling tests or caller flows. Fold `test_devnet_llmq_type_from_name_rejects_unknown_names` into `test_devnet_llmq_type_from_name`. Swap a `;` clause separator for `.` in a `DevnetConfig` doc comment.
* feat(key-wallet): add network-scoped wallet-id derivation The existing wallet id (`compute_wallet_id_from_root_extended_pub_key`) hashes only `root_public_key || root_chain_code`, which is identical across networks for a given seed — the same mnemonic yields the same id on mainnet/testnet/devnet/regtest. Some consumers need the option of a network-scoped id so one mnemonic maps to distinct ids per network. Add an opt-in, purely additive API: - `compute_network_scoped_wallet_id_from_root_extended_pub_key(root, Option<Network>)` hashes `pubkey || chain_code || DOMAIN_TAG || network_byte`. - `compute_network_scoped_wallet_id(&self)` instance method mirroring `compute_wallet_id`, folding in `self.network`. The network byte uses an explicit, wire-stable mapping (None=0xFF, Mainnet=0x00, Testnet=0x01, Devnet=0x02, Regtest=0x03) rather than `Network as u8`, since the enum repr can drift. A domain-separation tag (`DASH_WALLET_ID_NET_V1`) is appended before the network byte so a scoped id can never collide with the legacy unscoped digest. Network is optional. The legacy `compute_wallet_id_from_root_extended_pub_key` is unchanged byte-for-byte, and construction still stamps the legacy id into `self.wallet_id`. Flipping the default and any downstream re-keying are intentionally out of scope. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(key-wallet): cover scoped-id keyless-wallet branch Add a test asserting compute_network_scoped_wallet_id returns the construction-time id verbatim for WatchOnly and ExternalSignable wallets (no root key on hand), matching compute_wallet_id. This was the one documented behavior branch the existing tests did not exercise. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs(key-wallet): avoid rustdoc private-intra-doc-link errors The public compute_network_scoped_wallet_id_from_root_extended_pub_key doc linked to two private items (NETWORK_SCOPED_WALLET_ID_DOMAIN and network_scoped_wallet_id_discriminant), which fails `cargo doc` under RUSTDOCFLAGS=-D warnings (rustdoc::private_intra_doc_links). Reference them as plain inline code instead of intra-doc links. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(key-wallet): make None network reproduce the legacy wallet id Per review feedback, the network-scoped derivation is now backwards compatible: passing `network = None` produces a digest byte-for-byte identical to the legacy unscoped id (`compute_wallet_id_from_root_extended_pub_key`). The domain tag + discriminant byte are only appended for a concrete `Some(network)`, so a scoped id still cannot collide with the legacy/`None` digest. - Drop the `None => 0xFF` sentinel; the discriminant helper now takes `Network` directly (still an exhaustive match enforcing a byte per variant). - Update docs to spell out the `None` == legacy contract. - Tests: `None` now asserts equality with the legacy id (test_no_network_matches_legacy_id); `Some(network)` still asserts inequality. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * refactor(key-wallet): shorten wallet-id domain tag to b"N" Replace the verbose b"DASH_WALLET_ID_NET_V1" domain-separation tag with b"N" and condense the constant's doc. The tag's only job is to make a Some(network) scoped preimage diverge from the legacy/None preimage; any non-empty suffix achieves that, since the legacy preimage is a strict prefix of the scoped one. No persisted scoped ids exist yet and no test hardcodes a scoped digest, so this is safe. The legacy/None digest is unaffected (the tag is never appended there). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * refactor(key-wallet): fold network scoping into the existing wallet-id fn Now that `None` reproduces the legacy digest byte-for-byte, a separate `compute_network_scoped_wallet_id_from_root_extended_pub_key` was pure redundancy: calling it with `None` was identical to the legacy `compute_wallet_id_from_root_extended_pub_key`. Merge them. - `compute_wallet_id_from_root_extended_pub_key` now takes `network: Option<Network>`. `None` = legacy unscoped id (unchanged bytes); `Some(net)` = network-scoped id (domain tag + discriminant). - Delete the redundant scoped free function. The instance accessors stay: `compute_wallet_id()` calls it with `None`, `compute_network_scoped_wallet_id()` with `Some(self.network)`. - Update the 3 in-crate call sites (initialization.rs) and tests to pass `None`. Drop the now-tautological no-network-vs-legacy test; the known-answer test already locks `fn(.., None)` to the legacy digest. API note: this changes the signature of the public free function (callers add `None`). The crate is 0.x; the digest output for existing `None` callers is unchanged, so no persisted ids shift. Only in-crate call sites exist; `key-wallet-manager` uses the no-arg instance method and is unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(key-wallet)!: make wallet id network-scoped by default Per design decision, abandon backwards compatibility and flip the default: a wallet's id is now network-scoped everywhere. - Construction (`from_wallet_type` → from_mnemonic/from_seed/new_random, plus `from_xpub`/`from_external_signable`) now stamps `compute_wallet_id_from_root_extended_pub_key(root, Some(network))`. - `compute_wallet_id(&self)` now folds in `self.network` (was unscoped), keeping it consistent with the stamped `self.wallet_id`. - Remove the now-redundant `compute_network_scoped_wallet_id(&self)` instance method — it would be identical to `compute_wallet_id`. The free function keeps its `Option<Network>` param: `Some(network)` is the scoped id (default), `None` still yields the network-independent digest (`pubkey || chain_code`) for callers that explicitly want one id shared across networks. BREAKING: every wallet id derived from a given seed now differs per network. Previously persisted ids (which used the unscoped derivation) will not match and must be re-keyed by consumers. The network-independent form remains available via `…_from_root_extended_pub_key(root, None)`. Tests updated: two pre-existing tests that asserted cross-network id equality now assert distinctness (matching their intent), and the network-scoped unit tests cover the new default plus the `None` known answer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(key-wallet): pin a network-scoped wallet-id known answer The known-answer test only locked the `None` (network-independent) digest. Since the network-scoped id is now the default and the b"N" domain tag + discriminant bytes are a wire-stable contract, add a hard-coded expected hex for the Some(Network::Mainnet) digest so any change to the tag or a discriminant byte fails the test instead of silently shifting persisted ids. Merges both assertions into test_wallet_id_known_answers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* feat(dash-spv): storage truncation primitives for reorg support Add `truncate_above(height)` to `BlockHeaderStorage`, `FilterHeaderStorage`, `FilterStorage`, and `BlockStorage`, backed by a new `SegmentCache::truncate_above` that drops segments above the target and resets the boundary segment's tail slots to the persistable sentinel. Dropped segment files are queued for deletion on the next `persist`, and `PersistentBlockHeaderStorage` also prunes its `header_hash_index` so orphaned hashes no longer resolve to a height. This is the foundational primitive for upcoming fork/reorg handling in storage. No callers are wired up yet. * fix(dash-spv): reject `get_items` ranges past tip in `SegmentCache` After a within-segment `truncate_above`, the boundary segment is not in `to_delete`, so the loop guard in `get_items` does not catch overruns into its sentinel tail. In debug builds this panicked on the `last_valid_offset` assertion, in release builds it returned sentinel-filled data. Add an entry guard that fails fast when the requested end exceeds `next_height()`, plus a within-segment regression test alongside the existing cross-boundary one. Addresses CodeRabbit review comment on PR #790 #790 (comment) * test(dash-spv): consolidate truncate_above storage tests Merge two noop edge cases in segments.rs into a single test. Fold the block_headers noop assertion into the index-prune test. Collapse the blocks, filter_headers, and filters wrappers to one smoke test each since the underlying SegmentCache::truncate_above engine is already exhaustively covered in segments.rs.
`QuorumSnapshot::consensus_encode` wrote the active-members bitset without the leading compact-size bit count that `consensus_decode` reads (and that Dash Core's `DYNBITSET(activeQuorumMembers)` serializes), so encode and decode were asymmetric and any re-serialized `QuorumSnapshot` desynced on decode. This never surfaced because the only consensus-encode path for the type is serializing an outgoing `QRInfo` response (`message.rs`), which an SPV client never produces, and the only existing test was decode-only. Adds a round-trip test.
* fix: decode SML ProTx v3 entries
Dash Core 23.1 introduced ProTx version 3 (`ProTxVersion::ExtAddr`). `CSimplifiedMNListEntry` gates two things on `nVersion >= 3`: the service address switches from the legacy fixed 18-byte `MnNetInfo` to a variable-length `ExtNetInfo`, and Evo nodes no longer serialize the inline `platformHTTPPort` (only `platformNodeID` is inline, the HTTP port lives in `ExtNetInfo` under `PLATFORM_HTTPS`). The previous decoder always read a fixed 18-byte address, desyncing the stream on v3 entries and failing with `Invalid MasternodeType variant`.
Add a faithful `net_info` module with `Bip155Network`, `NetInfoEntry`, `NetInfoPurpose` and `ExtNetInfo` types decoding the ADDRV2/BIP155 wire form (per-network address-length validation, big-endian ports, version short-circuit). Introduce `MasternodeNetInfo::{Legacy, Extended}` for `MasternodeListEntry::service_address` with a version-driven decode/encode branch and a `primary_service_address()` accessor that reconstructs IPv4/IPv6 `SocketAddr`s. Inline the `mn_type` codec into the entry path so v3 Evo entries read only `platform_node_id` and source `platform_http_port` from the `PLATFORM_HTTPS` entry, while v2 Evo entries keep the inline port.
`MasternodeNetInfo` carries a hand-written `bincode` codec whose `Legacy` arm reuses the bare `SocketAddr` layout so existing persisted engine snapshots keep decoding.
Also fix `QuorumSnapshot::consensus_encode` to write the compact-size `activeQuorumMembers` count that the decoder already consumed, which the byte-exact `qrinfo` round-trip requires.
Consumers (`peer_addresses`, `masternode_helpers`, `masternode-seeds-fetcher`) now go through `primary_service_address()`.
* fix: bound `ExtNetInfo` decode pre-allocation against malicious counts
`consensus_decode_ext` sized `purposes`/`entries` with attacker-controlled compact-size counts straight off the wire, letting a tiny `qrinfo` trigger an unbounded `Vec::with_capacity`. Cap both like the existing `Vec` decoder using `MAX_VEC_SIZE`.
* fix(key-wallet): correct CoinJoin derivation path and denominations CoinJoin addresses were derived at `m/9'/coin'/account'/index` instead of Dash Core's `m/9'/coin'/4'/account'/0/index`, so the SPV client monitored the wrong scriptPubKeys and matched none of the wallet's CoinJoin outputs against BIP158 filters. Insert the hardened `4'` feature level and derive the pool on the `/0` branch (via the external pool) to match Dash Core. The CoinJoin denomination constants in `has_denomination_outputs` omitted the per-round fee (`100_000_000` etc. instead of `100_001_000` etc.), so real mixing rounds were classified `Standard`. Use the protocol denominations from `coinjoin/common.h`. * fix(key-wallet): check all fund accounts for tx ownership, demote CoinJoin classification to a label `get_relevant_account_types` routed `TransactionType::Standard` and `TransactionType::CoinJoin` to disjoint account sets, so a transaction's shape gated which fund-bearing accounts were checked for ownership. A misclassified tx (for example a small denomination spend that the `>= 3 in/out` heuristic labels `Standard`, or a CoinJoin-shaped tx touching standard collateral and change) therefore skipped the account that actually owned its coins and was dropped. Match Dash Core, where ownership is membership-based and never depends on a transaction's type or shape: `AddToWalletIfInvolvingMe` records a tx iff `IsMine || IsFromMe`, and `IsMine` tests each scriptPubKey against all script-pubkey managers uniformly (regular external, internal, and the CoinJoin descriptor). Denomination/CoinJoin classification is purely a downstream annotation, never a precondition for discovery. Both the `Standard` and `CoinJoin` arms now return the full set of fund-bearing account types via a shared `fund_bearing_account_types` helper (StandardBIP44, StandardBIP32, CoinJoin, DashpayReceivingFunds, DashpayExternalAccount). The `is_coinjoin_transaction` heuristic is unchanged: it now only sets the stored `TransactionType` label, never which accounts are consulted. Checking extra accounts introduces no false positives because an account matches only when a scriptPubKey or spent UTXO genuinely belongs to it.
#806) * feat(key-wallet): add normalize_phrase and is_word_in_language helpers Add two BIP39 input helpers to Mnemonic so consumers don't re-implement wordlist/normalization logic on top of the bip39 crate: - normalize_phrase: NFKD + lowercase + whitespace-collapse (lenient input normalization for validation/membership; NOT BIP39 seed normalization, which to_seed already performs) - is_word_in_language: exact wordlist membership for a given language Re-export Language from the crate root + prelude, and add the unicode-normalization dependency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(key-wallet): validate real phrase for each bundled language Mnemonic::validate was exercised only for English (test_mnemonic_validation) and Portuguese (test_portuguese_mnemonic); the other bundled languages were built via from_entropy in test_multiple_languages but never validate()'d. Add a test that builds a real 12-word phrase per language (French, Spanish, Italian, Japanese, Korean, Czech, ChineseSimplified, ChineseTraditional) and asserts validate() succeeds, plus a cross-language negative. This brings the per-language validate coverage home to key-wallet (it previously lived only in the dashwallet platform FFI facade). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(key-wallet): add word_list + cleanup_phrase recover-flow primitives Push BIP-39 recover-flow primitives down into key-wallet so the platform FFI layer can stay a thin C marshalling surface (per reviewer feedback on platform #3842): - Language::word_list(): public accessor for the raw 2048-word BIP-39 wordlist — the low-level primitive callers compose for word validation. - Mnemonic::cleanup_phrase(): minimal recover-input cleanup + CJK ideographic auto-split (DashSync DSBIP39Mnemonic cleanupPhrase: parity), built on module-private all-language wordlist/validate unions. Also drop the interim Mnemonic::is_word_in_language() helper (added earlier in this same unmerged branch) — too granular; callers use word_list() and do membership themselves. Net diff vs master is purely additive. cleanup_phrase / word_list tests live here since they exercise key-wallet logic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(key-wallet): canonicalize all whitespace in cleanup_phrase + correct word_list doc Address CodeRabbit review on #806: - cleanup_phrase: canonicalize every Unicode whitespace to an ASCII space in step (2), not just '\n'. Step (1) keeps all whitespace and the valid-phrase early return hands the string back verbatim, so a pasted CRLF/tab-delimited recovery phrase previously came back with '\r' / '\t' still in it. Seed-equivalent (BIP-39 NFKD maps U+3000 et al. to U+0020). Adds a regression test (cleanup_canonicalizes_crlf_and_tabs). - word_list doc: drop the "accent tolerance" claim — normalize_phrase does NFKD + lowercase + whitespace folding but preserves diacritics as combining marks, so "cafe" still won't match "café". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: PastaClaw <thepastaclaw@users.noreply.github.com>
…th AddressPrefix (#802)
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
Merged
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
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.
masterhas been stuck atv0.41.1whilev0.42.0,v0.43.0andv0.44.0were released from thedevline. This PR bringsmasterup tov0.44.0.