From a0df0f0ef26e0fb28aea64a7c0634ee5bbf2a285 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 2 Jan 2026 13:26:10 +0100 Subject: [PATCH] refactor: move `Send + Sync + 'static` bounds into trait definitions These bounds are required almost everywhere anyway, so making them explicit in the trait definitions reduces lots of repetitions. - Add `'static` to `StorageManager`, `NetworkManager`, and `WalletInterface` traits - Remove redundant bounds where traits are used --- dash-spv/src/client/block_processor.rs | 4 +--- dash-spv/src/client/chainlock.rs | 7 +------ dash-spv/src/client/core.rs | 7 +------ dash-spv/src/client/events.rs | 7 +------ dash-spv/src/client/lifecycle.rs | 7 +------ dash-spv/src/client/mempool.rs | 7 +------ dash-spv/src/client/message_handler.rs | 8 +------- dash-spv/src/client/progress.rs | 7 +------ dash-spv/src/client/queries.rs | 7 +------ dash-spv/src/client/status_display.rs | 4 +--- dash-spv/src/client/sync_coordinator.rs | 7 +------ dash-spv/src/client/transactions.rs | 7 +------ dash-spv/src/main.rs | 2 +- dash-spv/src/network/mod.rs | 2 +- dash-spv/src/storage/mod.rs | 2 +- dash-spv/src/sync/filters/download.rs | 4 +--- dash-spv/src/sync/filters/headers.rs | 4 +--- dash-spv/src/sync/filters/manager.rs | 4 +--- dash-spv/src/sync/filters/matching.rs | 4 +--- dash-spv/src/sync/filters/requests.rs | 4 +--- dash-spv/src/sync/filters/retry.rs | 4 +--- dash-spv/src/sync/filters/stats.rs | 4 +--- dash-spv/src/sync/headers/manager.rs | 4 +--- dash-spv/src/sync/manager.rs | 7 +------ dash-spv/src/sync/masternodes/manager.rs | 4 +--- dash-spv/src/sync/message_handlers.rs | 7 +------ dash-spv/src/sync/phase_execution.rs | 7 +------ dash-spv/src/sync/post_sync.rs | 7 +------ key-wallet-manager/src/wallet_interface.rs | 2 +- 29 files changed, 29 insertions(+), 122 deletions(-) diff --git a/dash-spv/src/client/block_processor.rs b/dash-spv/src/client/block_processor.rs index 1b995ae66..0fa11c715 100644 --- a/dash-spv/src/client/block_processor.rs +++ b/dash-spv/src/client/block_processor.rs @@ -38,9 +38,7 @@ pub struct BlockProcessor { failed: bool, } -impl - BlockProcessor -{ +impl BlockProcessor { /// Create a new block processor. pub fn new( receiver: mpsc::UnboundedReceiver, diff --git a/dash-spv/src/client/chainlock.rs b/dash-spv/src/client/chainlock.rs index 553f0b58d..8408189eb 100644 --- a/dash-spv/src/client/chainlock.rs +++ b/dash-spv/src/client/chainlock.rs @@ -16,12 +16,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::DashSpvClient; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Process and validate a ChainLock. pub async fn process_chainlock( &mut self, diff --git a/dash-spv/src/client/core.rs b/dash-spv/src/client/core.rs index a003c8300..ef14717b5 100644 --- a/dash-spv/src/client/core.rs +++ b/dash-spv/src/client/core.rs @@ -146,12 +146,7 @@ pub struct DashSpvClient>, } -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { // ============ Simple Getters ============ /// Get a reference to the wallet. diff --git a/dash-spv/src/client/events.rs b/dash-spv/src/client/events.rs index 1db8f3656..63dcdde97 100644 --- a/dash-spv/src/client/events.rs +++ b/dash-spv/src/client/events.rs @@ -13,12 +13,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::DashSpvClient; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Take the event receiver for external consumption. pub fn take_event_receiver(&mut self) -> Option> { self.event_rx.take() diff --git a/dash-spv/src/client/lifecycle.rs b/dash-spv/src/client/lifecycle.rs index a6acb2a25..a9bac48e5 100644 --- a/dash-spv/src/client/lifecycle.rs +++ b/dash-spv/src/client/lifecycle.rs @@ -25,12 +25,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::{BlockProcessor, ClientConfig, DashSpvClient}; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Create a new SPV client with the given configuration, network, storage, and wallet. pub async fn new( config: ClientConfig, diff --git a/dash-spv/src/client/mempool.rs b/dash-spv/src/client/mempool.rs index 395771ce7..fac807360 100644 --- a/dash-spv/src/client/mempool.rs +++ b/dash-spv/src/client/mempool.rs @@ -17,12 +17,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::{config, DashSpvClient}; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Enable mempool tracking with the specified strategy. pub async fn enable_mempool_tracking( &mut self, diff --git a/dash-spv/src/client/message_handler.rs b/dash-spv/src/client/message_handler.rs index 40b4586c7..0aebea16b 100644 --- a/dash-spv/src/client/message_handler.rs +++ b/dash-spv/src/client/message_handler.rs @@ -24,13 +24,7 @@ pub struct MessageHandler<'a, S: StorageManager, N: NetworkManager, W: WalletInt event_tx: &'a tokio::sync::mpsc::UnboundedSender, } -impl< - 'a, - S: StorageManager + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - W: WalletInterface, - > MessageHandler<'a, S, N, W> -{ +impl<'a, S: StorageManager, N: NetworkManager, W: WalletInterface> MessageHandler<'a, S, N, W> { /// Create a new message handler. #[allow(clippy::too_many_arguments)] pub fn new( diff --git a/dash-spv/src/client/progress.rs b/dash-spv/src/client/progress.rs index 7998560a6..912e780df 100644 --- a/dash-spv/src/client/progress.rs +++ b/dash-spv/src/client/progress.rs @@ -14,12 +14,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::DashSpvClient; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Get current sync progress. pub async fn sync_progress(&self) -> Result { let display = self.create_status_display().await; diff --git a/dash-spv/src/client/queries.rs b/dash-spv/src/client/queries.rs index bb0be8c3b..f6f0b0590 100644 --- a/dash-spv/src/client/queries.rs +++ b/dash-spv/src/client/queries.rs @@ -19,12 +19,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::DashSpvClient; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { // ============ Peer Queries ============ /// Get the number of connected peers. diff --git a/dash-spv/src/client/status_display.rs b/dash-spv/src/client/status_display.rs index 0324fe964..8b7735981 100644 --- a/dash-spv/src/client/status_display.rs +++ b/dash-spv/src/client/status_display.rs @@ -23,9 +23,7 @@ pub struct StatusDisplay<'a, S: StorageManager, W: WalletInterface> { config: &'a ClientConfig, } -impl<'a, S: StorageManager + Send + Sync + 'static, W: WalletInterface + Send + Sync + 'static> - StatusDisplay<'a, S, W> -{ +impl<'a, S: StorageManager, W: WalletInterface> StatusDisplay<'a, S, W> { /// Create a new status display manager. #[cfg(feature = "terminal-ui")] pub fn new( diff --git a/dash-spv/src/client/sync_coordinator.rs b/dash-spv/src/client/sync_coordinator.rs index de06633ec..39c74000e 100644 --- a/dash-spv/src/client/sync_coordinator.rs +++ b/dash-spv/src/client/sync_coordinator.rs @@ -23,12 +23,7 @@ use std::time::{Duration, Instant, SystemTime}; use tokio::sync::mpsc::UnboundedReceiver; use tokio_util::sync::CancellationToken; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Synchronize to the tip of the blockchain. pub async fn sync_to_tip(&mut self) -> Result { let running = self.running.read().await; diff --git a/dash-spv/src/client/transactions.rs b/dash-spv/src/client/transactions.rs index e9abb3463..e45285a2d 100644 --- a/dash-spv/src/client/transactions.rs +++ b/dash-spv/src/client/transactions.rs @@ -8,12 +8,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::DashSpvClient; -impl< - W: WalletInterface + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - S: StorageManager + Send + Sync + 'static, - > DashSpvClient -{ +impl DashSpvClient { /// Broadcast a transaction to all connected peers. pub async fn broadcast_transaction(&self, tx: &dashcore::Transaction) -> Result<()> { let network = self diff --git a/dash-spv/src/main.rs b/dash-spv/src/main.rs index 3d7ada9f5..51c8207ba 100644 --- a/dash-spv/src/main.rs +++ b/dash-spv/src/main.rs @@ -347,7 +347,7 @@ async fn run() -> Result<(), Box> { Ok(()) } -async fn run_client( +async fn run_client( config: ClientConfig, network_manager: dash_spv::network::manager::PeerNetworkManager, storage_manager: S, diff --git a/dash-spv/src/network/mod.rs b/dash-spv/src/network/mod.rs index 89e8bde78..2da61f6f9 100644 --- a/dash-spv/src/network/mod.rs +++ b/dash-spv/src/network/mod.rs @@ -28,7 +28,7 @@ pub use peer::Peer; /// Network manager trait for abstracting network operations. #[async_trait] -pub trait NetworkManager: Send + Sync { +pub trait NetworkManager: Send + Sync + 'static { /// Convert to Any for downcasting. fn as_any(&self) -> &dyn std::any::Any; diff --git a/dash-spv/src/storage/mod.rs b/dash-spv/src/storage/mod.rs index aa8e0387a..4a4359da9 100644 --- a/dash-spv/src/storage/mod.rs +++ b/dash-spv/src/storage/mod.rs @@ -70,7 +70,7 @@ pub use types::*; /// Note that the `&mut self` requirement means only one thread can be mutating the storage /// at a time when using external synchronization, which naturally provides consistency. #[async_trait] -pub trait StorageManager: Send + Sync { +pub trait StorageManager: Send + Sync + 'static { /// Store block headers. async fn store_headers(&mut self, headers: &[BlockHeader]) -> StorageResult<()>; diff --git a/dash-spv/src/sync/filters/download.rs b/dash-spv/src/sync/filters/download.rs index f5c1a4e7b..ce1052671 100644 --- a/dash-spv/src/sync/filters/download.rs +++ b/dash-spv/src/sync/filters/download.rs @@ -21,9 +21,7 @@ use crate::network::NetworkManager; use crate::storage::StorageManager; use crate::types::SyncProgress; -impl - super::manager::FilterSyncManager -{ +impl super::manager::FilterSyncManager { pub async fn verify_cfilter_against_headers( &self, filter_data: &[u8], diff --git a/dash-spv/src/sync/filters/headers.rs b/dash-spv/src/sync/filters/headers.rs index 40ce1622f..2409cc1f3 100644 --- a/dash-spv/src/sync/filters/headers.rs +++ b/dash-spv/src/sync/filters/headers.rs @@ -26,9 +26,7 @@ use crate::error::{SyncError, SyncResult}; use crate::network::NetworkManager; use crate::storage::StorageManager; -impl - super::manager::FilterSyncManager -{ +impl super::manager::FilterSyncManager { pub(super) async fn find_available_header_at_or_before( &self, abs_height: u32, diff --git a/dash-spv/src/sync/filters/manager.rs b/dash-spv/src/sync/filters/manager.rs index aeb726e6b..29a034eff 100644 --- a/dash-spv/src/sync/filters/manager.rs +++ b/dash-spv/src/sync/filters/manager.rs @@ -86,9 +86,7 @@ pub struct FilterSyncManager { pub(super) cfheader_request_timeout: std::time::Duration, } -impl - FilterSyncManager -{ +impl FilterSyncManager { /// Verify that the received compact filter hashes to the expected filter header pub fn new(config: &ClientConfig, received_filter_heights: SharedFilterHeights) -> Self { Self { diff --git a/dash-spv/src/sync/filters/matching.rs b/dash-spv/src/sync/filters/matching.rs index ed119a9d3..56161a148 100644 --- a/dash-spv/src/sync/filters/matching.rs +++ b/dash-spv/src/sync/filters/matching.rs @@ -19,9 +19,7 @@ use crate::error::{SyncError, SyncResult}; use crate::network::NetworkManager; use crate::storage::StorageManager; -impl - super::manager::FilterSyncManager -{ +impl super::manager::FilterSyncManager { pub async fn check_filter_for_matches< W: key_wallet_manager::wallet_interface::WalletInterface, >( diff --git a/dash-spv/src/sync/filters/requests.rs b/dash-spv/src/sync/filters/requests.rs index 6115576b9..e6f61d806 100644 --- a/dash-spv/src/sync/filters/requests.rs +++ b/dash-spv/src/sync/filters/requests.rs @@ -11,9 +11,7 @@ use crate::error::{SyncError, SyncResult}; use crate::network::NetworkManager; use crate::storage::StorageManager; -impl - super::manager::FilterSyncManager -{ +impl super::manager::FilterSyncManager { /// Build a queue of filter requests covering the specified range. /// /// If start_height is None, defaults to (filter_header_tip - DEFAULT_FILTER_SYNC_RANGE). diff --git a/dash-spv/src/sync/filters/retry.rs b/dash-spv/src/sync/filters/retry.rs index f998066d0..86c570564 100644 --- a/dash-spv/src/sync/filters/retry.rs +++ b/dash-spv/src/sync/filters/retry.rs @@ -12,9 +12,7 @@ use crate::network::NetworkManager; use crate::storage::StorageManager; use dashcore::BlockHash; -impl - super::manager::FilterSyncManager -{ +impl super::manager::FilterSyncManager { /// Check if filter header sync has timed out (no progress for SYNC_TIMEOUT_SECONDS). /// /// If timeout is detected, attempts recovery by re-sending the current batch request. diff --git a/dash-spv/src/sync/filters/stats.rs b/dash-spv/src/sync/filters/stats.rs index 1ea30cd60..a51e4249a 100644 --- a/dash-spv/src/sync/filters/stats.rs +++ b/dash-spv/src/sync/filters/stats.rs @@ -4,9 +4,7 @@ use super::types::*; use crate::network::NetworkManager; use crate::storage::StorageManager; -impl - super::manager::FilterSyncManager -{ +impl super::manager::FilterSyncManager { /// Get state (pending count, active count). pub fn get_filter_sync_state(&self) -> (usize, usize) { (self.pending_filter_requests.len(), self.active_filter_requests.len()) diff --git a/dash-spv/src/sync/headers/manager.rs b/dash-spv/src/sync/headers/manager.rs index 8e4a2f41b..b6338ec46 100644 --- a/dash-spv/src/sync/headers/manager.rs +++ b/dash-spv/src/sync/headers/manager.rs @@ -61,9 +61,7 @@ pub struct HeaderSyncManager { cached_sync_base_height: u32, } -impl - HeaderSyncManager -{ +impl HeaderSyncManager { /// Create a new header sync manager pub fn new( config: &ClientConfig, diff --git a/dash-spv/src/sync/manager.rs b/dash-spv/src/sync/manager.rs index af69098b8..6b3f3b76f 100644 --- a/dash-spv/src/sync/manager.rs +++ b/dash-spv/src/sync/manager.rs @@ -100,12 +100,7 @@ pub struct SyncManager pub(super) stats: std::sync::Arc>, } -impl< - S: StorageManager + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - W: WalletInterface, - > SyncManager -{ +impl SyncManager { /// Create a new sequential sync manager pub fn new( config: &ClientConfig, diff --git a/dash-spv/src/sync/masternodes/manager.rs b/dash-spv/src/sync/masternodes/manager.rs index 065f26dbc..f0d5a72e2 100644 --- a/dash-spv/src/sync/masternodes/manager.rs +++ b/dash-spv/src/sync/masternodes/manager.rs @@ -51,9 +51,7 @@ pub struct MasternodeSyncManager { mnlistdiff_retry_count: u8, } -impl - MasternodeSyncManager -{ +impl MasternodeSyncManager { /// Create a new masternode sync manager. pub fn new(config: &ClientConfig) -> Self { let (engine, mnlist_diffs) = if config.enable_masternodes { diff --git a/dash-spv/src/sync/message_handlers.rs b/dash-spv/src/sync/message_handlers.rs index 33a359a91..6a8bbbfd6 100644 --- a/dash-spv/src/sync/message_handlers.rs +++ b/dash-spv/src/sync/message_handlers.rs @@ -16,12 +16,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::manager::SyncManager; use super::phases::SyncPhase; -impl< - S: StorageManager + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - W: WalletInterface, - > SyncManager -{ +impl SyncManager { /// Handle incoming network messages with phase filtering pub async fn handle_message( &mut self, diff --git a/dash-spv/src/sync/phase_execution.rs b/dash-spv/src/sync/phase_execution.rs index 77758d833..af9268b6e 100644 --- a/dash-spv/src/sync/phase_execution.rs +++ b/dash-spv/src/sync/phase_execution.rs @@ -10,12 +10,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::manager::SyncManager; use super::phases::SyncPhase; -impl< - S: StorageManager + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - W: WalletInterface, - > SyncManager -{ +impl SyncManager { /// Execute the current sync phase pub(super) async fn execute_current_phase( &mut self, diff --git a/dash-spv/src/sync/post_sync.rs b/dash-spv/src/sync/post_sync.rs index 15f2df8fa..c505ebf25 100644 --- a/dash-spv/src/sync/post_sync.rs +++ b/dash-spv/src/sync/post_sync.rs @@ -13,12 +13,7 @@ use key_wallet_manager::wallet_interface::WalletInterface; use super::manager::{SyncManager, CHAINLOCK_VALIDATION_MASTERNODE_OFFSET}; use super::phases::SyncPhase; -impl< - S: StorageManager + Send + Sync + 'static, - N: NetworkManager + Send + Sync + 'static, - W: WalletInterface, - > SyncManager -{ +impl SyncManager { /// Handle inventory messages for sequential sync pub async fn handle_inventory( &mut self, diff --git a/key-wallet-manager/src/wallet_interface.rs b/key-wallet-manager/src/wallet_interface.rs index 62af33871..c0dc0bd58 100644 --- a/key-wallet-manager/src/wallet_interface.rs +++ b/key-wallet-manager/src/wallet_interface.rs @@ -10,7 +10,7 @@ use dashcore::{Block, Transaction, Txid}; /// Trait for wallet implementations to receive SPV events #[async_trait] -pub trait WalletInterface: Send + Sync { +pub trait WalletInterface: Send + Sync + 'static { /// Called when a new block is received that may contain relevant transactions /// Returns transaction IDs that were relevant to the wallet async fn process_block(&mut self, block: &Block, height: CoreBlockHeight) -> Vec;