@@ -15,7 +15,6 @@ use crate::io::{
1515} ;
1616use crate :: logger:: { log_error, LdkLogger , Logger } ;
1717use crate :: peer_store:: PeerStore ;
18- use crate :: sweep:: DeprecatedSpendableOutputInfo ;
1918use crate :: types:: { Broadcaster , DynStore , KeysManager , Sweeper } ;
2019use crate :: wallet:: ser:: { ChangeSetDeserWrapper , ChangeSetSerWrapper } ;
2120use crate :: { Error , EventQueue , NodeMetrics , PaymentDetails } ;
@@ -33,7 +32,7 @@ use lightning::util::persist::{
3332} ;
3433use lightning:: util:: ser:: { Readable , ReadableArgs , Writeable } ;
3534use lightning:: util:: string:: PrintableString ;
36- use lightning:: util:: sweep:: { OutputSpendStatus , OutputSweeper } ;
35+ use lightning:: util:: sweep:: OutputSweeper ;
3736
3837use bdk_chain:: indexer:: keychain_txout:: ChangeSet as BdkIndexerChangeSet ;
3938use bdk_chain:: local_chain:: ChangeSet as BdkLocalChainChangeSet ;
@@ -258,103 +257,6 @@ pub(crate) fn read_output_sweeper(
258257 } )
259258}
260259
261- /// Read previously persisted spendable output information from the store and migrate to the
262- /// upstreamed `OutputSweeper`.
263- ///
264- /// We first iterate all `DeprecatedSpendableOutputInfo`s and have them tracked by the new
265- /// `OutputSweeper`. In order to be certain the initial output spends will happen in a single
266- /// transaction (and safe on-chain fees), we batch them to happen at current height plus two
267- /// blocks. Lastly, we remove the previously persisted data once we checked they are tracked and
268- /// awaiting their initial spend at the correct height.
269- ///
270- /// Note that this migration will be run in the `Builder`, i.e., at the time when the migration is
271- /// happening no background sync is ongoing, so we shouldn't have a risk of interleaving block
272- /// connections during the migration.
273- pub ( crate ) fn migrate_deprecated_spendable_outputs < L : Deref > (
274- sweeper : Arc < Sweeper > , kv_store : Arc < DynStore > , logger : L ,
275- ) -> Result < ( ) , std:: io:: Error >
276- where
277- L :: Target : LdkLogger ,
278- {
279- let best_block = sweeper. current_best_block ( ) ;
280-
281- for stored_key in kv_store. list (
282- DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
283- DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
284- ) ? {
285- let mut reader = Cursor :: new ( kv_store. read (
286- DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
287- DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
288- & stored_key,
289- ) ?) ;
290- let output = DeprecatedSpendableOutputInfo :: read ( & mut reader) . map_err ( |e| {
291- log_error ! ( logger, "Failed to deserialize SpendableOutputInfo: {}" , e) ;
292- std:: io:: Error :: new (
293- std:: io:: ErrorKind :: InvalidData ,
294- "Failed to deserialize SpendableOutputInfo" ,
295- )
296- } ) ?;
297- let descriptors = vec ! [ output. descriptor. clone( ) ] ;
298- let spend_delay = Some ( best_block. height + 2 ) ;
299- sweeper
300- . track_spendable_outputs ( descriptors, output. channel_id , true , spend_delay)
301- . map_err ( |_| {
302- log_error ! ( logger, "Failed to track spendable outputs. Aborting migration, will retry in the future." ) ;
303- std:: io:: Error :: new (
304- std:: io:: ErrorKind :: InvalidData ,
305- "Failed to track spendable outputs. Aborting migration, will retry in the future." ,
306- )
307- } ) ?;
308-
309- if let Some ( tracked_spendable_output) =
310- sweeper. tracked_spendable_outputs ( ) . iter ( ) . find ( |o| o. descriptor == output. descriptor )
311- {
312- match tracked_spendable_output. status {
313- OutputSpendStatus :: PendingInitialBroadcast { delayed_until_height } => {
314- if delayed_until_height == spend_delay {
315- kv_store. remove (
316- DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
317- DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
318- & stored_key,
319- false ,
320- ) ?;
321- } else {
322- debug_assert ! ( false , "Unexpected status in OutputSweeper migration." ) ;
323- log_error ! ( logger, "Unexpected status in OutputSweeper migration." ) ;
324- return Err ( std:: io:: Error :: new (
325- std:: io:: ErrorKind :: Other ,
326- "Failed to migrate OutputSweeper state." ,
327- ) ) ;
328- }
329- } ,
330- _ => {
331- debug_assert ! ( false , "Unexpected status in OutputSweeper migration." ) ;
332- log_error ! ( logger, "Unexpected status in OutputSweeper migration." ) ;
333- return Err ( std:: io:: Error :: new (
334- std:: io:: ErrorKind :: Other ,
335- "Failed to migrate OutputSweeper state." ,
336- ) ) ;
337- } ,
338- }
339- } else {
340- debug_assert ! (
341- false ,
342- "OutputSweeper failed to track and persist outputs during migration."
343- ) ;
344- log_error ! (
345- logger,
346- "OutputSweeper failed to track and persist outputs during migration."
347- ) ;
348- return Err ( std:: io:: Error :: new (
349- std:: io:: ErrorKind :: Other ,
350- "Failed to migrate OutputSweeper state." ,
351- ) ) ;
352- }
353- }
354-
355- Ok ( ( ) )
356- }
357-
358260pub ( crate ) fn read_node_metrics < L : Deref > (
359261 kv_store : Arc < DynStore > , logger : L ,
360262) -> Result < NodeMetrics , std:: io:: Error >
0 commit comments