Skip to content

Commit a915f78

Browse files
fix(dash-spv): improve wallet birth height hint handling
- Update wallet_birth_height_hint to return None for unknown network variants instead of defaulting to Dash. - Enhance process_block to only consider wallets with known birth heights, returning None if none are found. This change improves the robustness of network handling and ensures accurate wallet birth height tracking.
1 parent c79298e commit a915f78

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

dash-spv/src/sync/sequential/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ impl<
144144

145145
/// Get the earliest wallet birth height hint for the configured network, if available.
146146
pub async fn wallet_birth_height_hint(&self) -> Option<u32> {
147+
// Map the dashcore network to wallet network, returning None for unknown variants
147148
let wallet_network = match self.config.network {
148149
dashcore::Network::Dash => WalletNetwork::Dash,
149150
dashcore::Network::Testnet => WalletNetwork::Testnet,
150151
dashcore::Network::Devnet => WalletNetwork::Devnet,
151152
dashcore::Network::Regtest => WalletNetwork::Regtest,
152-
_ => WalletNetwork::Dash,
153+
_ => return None, // Unknown network variant - return None instead of defaulting
153154
};
154155

156+
// Only acquire the wallet lock if we have a valid network mapping
155157
let wallet_guard = self.wallet.read().await;
156158
let result = wallet_guard.earliest_required_height(wallet_network).await;
157159
drop(wallet_guard);

key-wallet-manager/src/wallet_manager/process_block.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,18 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletInterface for WalletM
122122
let mut earliest: Option<CoreBlockHeight> = None;
123123

124124
for info in self.wallet_infos.values() {
125-
// Only consider wallets that actually track this network
125+
// Only consider wallets that actually track this network AND have a known birth height
126126
if info.accounts(network).is_some() {
127-
let birth_height = info.birth_height().unwrap_or(0);
128-
earliest = Some(match earliest {
129-
Some(current) => current.min(birth_height),
130-
None => birth_height,
131-
});
127+
if let Some(birth_height) = info.birth_height() {
128+
earliest = Some(match earliest {
129+
Some(current) => current.min(birth_height),
130+
None => birth_height,
131+
});
132+
}
132133
}
133134
}
134135

136+
// Return None if no wallets with known birth heights were found for this network
135137
earliest
136138
}
137139
}

0 commit comments

Comments
 (0)