diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs index 6439ad9e0..c214ff02f 100644 --- a/bitcoin/src/lib.rs +++ b/bitcoin/src/lib.rs @@ -811,7 +811,11 @@ impl BitcoinCoreApi for BitcoinCore { .rpc .list_transactions(Some(SWEEP_ADDRESS), Some(DEFAULT_MAX_TX_COUNT), None, None)? .into_iter() - .filter_map(|tx| tx.info.blockheight) + // we want to return None if there is no sweep tx for full nodes or new + // pruned nodes and we should return an error if any tx is still in the mempool + .map(|tx| tx.info.blockheight.ok_or(Error::ConfirmationError)) + .collect::, _>>()? + .into_iter() .min()) } @@ -1080,7 +1084,6 @@ impl BitcoinCoreApi for BitcoinCore { } log::info!("Sweeping {} from {} utxos", amount, utxos.len()); - let mut outputs = serde_json::Map::::new(); outputs.insert(address.to_string(), serde_json::Value::from(amount.to_btc())); diff --git a/vault/src/issue.rs b/vault/src/issue.rs index 6f135ee10..4d9ee5d4b 100644 --- a/vault/src/issue.rs +++ b/vault/src/issue.rs @@ -166,7 +166,7 @@ pub async fn add_keys_from_past_issue_request( // privkey let btc_end_height = bitcoin_core.get_block_count().await? as usize; let btc_pruned_start_height = bitcoin_core.get_pruned_height().await? as usize; - let btc_max_sweep_height = bitcoin_core.get_last_sweep_height().await?; + let btc_last_sweep_height = bitcoin_core.get_last_sweep_height().await?; let issues = issue_requests.clone().into_iter().map(|(_key, issue)| issue).collect(); scanning_status.update(issues, btc_end_height); @@ -184,7 +184,7 @@ pub async fn add_keys_from_past_issue_request( .into_iter() .filter_map(|(_, request)| { // only import if address is AFTER last sweep height and BEFORE current pruning height - if btc_max_sweep_height.is_some_and(|sweep_height| request.btc_height > sweep_height) + if btc_last_sweep_height.map_or(true, |sweep_height| request.btc_height > sweep_height) && (request.btc_height as usize) < btc_pruned_start_height { Some(request.btc_address.to_address(bitcoin_core.network()).ok()?) diff --git a/vault/src/lib.rs b/vault/src/lib.rs index a93685643..8dac97932 100644 --- a/vault/src/lib.rs +++ b/vault/src/lib.rs @@ -1,6 +1,5 @@ #![recursion_limit = "256"] #![feature(array_zip)] -#![feature(is_some_and)] mod cancellation; mod cli; diff --git a/vault/src/system.rs b/vault/src/system.rs index a3463b4fe..99f8bfb8a 100644 --- a/vault/src/system.rs +++ b/vault/src/system.rs @@ -323,6 +323,14 @@ impl VaultIdManager { btc_rpc_shared.import_private_key(&private_key, false)?; } + // only sweep if using pruned node and there is no sweep tx yet to shared-v2 + if btc_rpc_shared.get_pruned_height().await? != 0 && self.btc_rpc_shared_wallet_v2.get_last_sweep_height().await?.is_none() { + // sweep to old shared wallet which will then sweep again to the v2 wallet + let shared_wallet_address = btc_rpc_shared.get_new_address().await?; + let txid = btc_rpc.sweep_funds(shared_wallet_address).await?; + tracing::info!("Sent sweep tx: {txid}"); + } + tracing::info!("Initializing metrics..."); let metrics = PerCurrencyMetrics::new(&vault_id); let data = VaultData { @@ -435,7 +443,7 @@ impl VaultIdManager { pub struct VaultService { btc_parachain: InterBtcParachain, btc_rpc_master_wallet: DynBitcoinCoreApi, - btc_rpc_shared_wallet: DynBitcoinCoreApi, + btc_rpc_shared_wallet_v2: DynBitcoinCoreApi, config: VaultServiceConfig, monitoring_config: MonitoringConfig, shutdown: ShutdownSender, @@ -547,7 +555,7 @@ impl VaultService { Self { btc_parachain: btc_parachain.clone(), btc_rpc_master_wallet: btc_rpc_master_wallet.clone(), - btc_rpc_shared_wallet: btc_rpc_shared_wallet.clone(), + btc_rpc_shared_wallet_v2: btc_rpc_shared_wallet_v2.clone(), config, monitoring_config, shutdown, @@ -673,7 +681,7 @@ impl VaultService { tracing::info!("Adding keys from past issues..."); issue::add_keys_from_past_issue_request( - &self.btc_rpc_shared_wallet, + &self.btc_rpc_shared_wallet_v2, &self.btc_parachain, &self.vault_id_manager.db, )