@@ -7,7 +7,8 @@ use crate::{
77 actions:: { db_update_presigned_txs, db_update_vault_status} ,
88 bitcointx:: RevaultTx ,
99 interface:: {
10- db_cancel_transaction, db_emer_transaction, db_sig_missing, db_unvault_emer_transaction,
10+ db_cancel_transaction_by_txid, db_emer_transaction, db_sig_missing,
11+ db_unvault_emer_transaction,
1112 } ,
1213 schema:: { DbTransaction , DbVault } ,
1314 DatabaseError ,
@@ -18,7 +19,7 @@ use crate::{
1819use revault_net:: transport:: KKTransport ;
1920use revault_tx:: {
2021 bitcoin:: { secp256k1, PublicKey as BitcoinPubKey } ,
21- transactions:: RevaultTransaction ,
22+ transactions:: { transaction_chain_manager , RevaultTransaction } ,
2223} ;
2324
2425use std:: {
@@ -156,7 +157,7 @@ fn maybe_wt_share_signatures(
156157 None => return Ok ( ( ) ) ,
157158 } ;
158159
159- // They should always be there, apart from a very edgy race condition.
160+ // The revocation txs should always be there, apart from a very edgy race condition.
160161 let emer_tx = db_emer_transaction ( db_path, db_vault. id ) ?
161162 . ok_or ( SignatureFetcherError :: MissingTransaction ) ?;
162163 if !emer_tx
@@ -166,15 +167,32 @@ fn maybe_wt_share_signatures(
166167 {
167168 return Ok ( ( ) ) ;
168169 }
169- let cancel_tx = db_cancel_transaction ( db_path, db_vault. id ) ?
170- . ok_or ( SignatureFetcherError :: MissingTransaction ) ?;
171- if !cancel_tx
172- . psbt
173- . unwrap_cancel ( )
174- . is_finalizable ( & revaultd. secp_ctx )
175- {
176- return Ok ( ( ) ) ;
170+
171+ let ( _, cancel_batch) = transaction_chain_manager (
172+ db_vault. deposit_outpoint ,
173+ db_vault. amount ,
174+ & revaultd. deposit_descriptor ,
175+ & revaultd. unvault_descriptor ,
176+ & revaultd. cpfp_descriptor ,
177+ db_vault. derivation_index ,
178+ & revaultd. secp_ctx ,
179+ )
180+ . expect ( "We wouldn't have put a vault with an invalid chain in DB" ) ;
181+ let mut cancel_txs = BTreeMap :: new ( ) ;
182+ for ( amount, cancel_tx) in cancel_batch. feerates_map ( ) {
183+ let cancel_tx = db_cancel_transaction_by_txid ( db_path, & cancel_tx. txid ( ) )
184+ . expect ( "Database must always be available" )
185+ . ok_or ( SignatureFetcherError :: MissingTransaction ) ?;
186+ if !cancel_tx
187+ . psbt
188+ . unwrap_cancel ( )
189+ . is_finalizable ( & revaultd. secp_ctx )
190+ {
191+ return Ok ( ( ) ) ;
192+ }
193+ cancel_txs. insert ( amount, cancel_tx) ;
177194 }
195+
178196 let unemer_tx = db_unvault_emer_transaction ( db_path, db_vault. id ) ?
179197 . ok_or ( SignatureFetcherError :: MissingTransaction ) ?;
180198 if !unemer_tx
@@ -195,7 +213,7 @@ fn maybe_wt_share_signatures(
195213 db_vault. deposit_outpoint ,
196214 db_vault. derivation_index ,
197215 & emer_tx,
198- & cancel_tx ,
216+ & cancel_txs ,
199217 & unemer_tx,
200218 ) ?;
201219
0 commit comments