Skip to content

Commit 5560b65

Browse files
committed
Stop migrating spendable outputs from pre-v0.3 format
As part of the version v0.3 release we switched to the upstreamed `OutputSweeper` which slightly changed our serialization format, having us run a migration step on startup for backwards compatibility ever since. Here we drop the migration code running on startup, for simplicity's sake, but also because it's going to be async going forward and we currently don't have a runtime available on startup (which might change soon, but still). As the v0.3 release now well over a year ago, it's very unlikely that there are any v0.2 (or even v0.3) users left. If there are any affected users left, they'll first have to upgrade to any version pre-v0.7, startup, and then upgrade to v0.7 or later.
1 parent d2cadd0 commit 5560b65

File tree

6 files changed

+12
-170
lines changed

6 files changed

+12
-170
lines changed

src/balance.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use crate::sweep::value_from_descriptor;
9-
108
use lightning::chain::channelmonitor::Balance as LdkBalance;
119
use lightning::chain::channelmonitor::BalanceSource;
1210
use lightning::ln::types::ChannelId;
11+
use lightning::sign::SpendableOutputDescriptor;
1312
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};
1413

1514
use lightning_types::payment::{PaymentHash, PaymentPreimage};
1615

1716
use bitcoin::secp256k1::PublicKey;
18-
use bitcoin::{BlockHash, Txid};
17+
use bitcoin::{Amount, BlockHash, Txid};
1918

2019
/// Details of the known available balances returned by [`Node::list_balances`].
2120
///
@@ -385,3 +384,11 @@ impl PendingSweepBalance {
385384
}
386385
}
387386
}
387+
388+
fn value_from_descriptor(descriptor: &SpendableOutputDescriptor) -> Amount {
389+
match &descriptor {
390+
SpendableOutputDescriptor::StaticOutput { output, .. } => output.value,
391+
SpendableOutputDescriptor::DelayedPaymentOutput(output) => output.output.value,
392+
SpendableOutputDescriptor::StaticPaymentOutput(output) => output.output.value,
393+
}
394+
}

src/builder.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::io::{
2525
use crate::liquidity::{
2626
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LiquiditySourceBuilder,
2727
};
28-
use crate::logger::{log_error, log_info, LdkLogger, LogLevel, LogWriter, Logger};
28+
use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger};
2929
use crate::message_handler::NodeCustomMessageHandler;
3030
use crate::peer_store::PeerStore;
3131
use crate::tx_broadcaster::TransactionBroadcaster;
@@ -1593,20 +1593,6 @@ fn build_with_store_internal(
15931593
},
15941594
};
15951595

1596-
match io::utils::migrate_deprecated_spendable_outputs(
1597-
Arc::clone(&output_sweeper),
1598-
Arc::clone(&kv_store),
1599-
Arc::clone(&logger),
1600-
) {
1601-
Ok(()) => {
1602-
log_info!(logger, "Successfully migrated OutputSweeper data.");
1603-
},
1604-
Err(e) => {
1605-
log_error!(logger, "Failed to migrate OutputSweeper data: {}", e);
1606-
return Err(BuildError::ReadFailed);
1607-
},
1608-
}
1609-
16101596
let event_queue = match io::utils::read_event_queue(Arc::clone(&kv_store), Arc::clone(&logger))
16111597
{
16121598
Ok(event_queue) => Arc::new(event_queue),

src/io/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ pub(crate) const PEER_INFO_PERSISTENCE_KEY: &str = "peers";
2727
pub(crate) const PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str = "payments";
2828
pub(crate) const PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";
2929

30-
/// The spendable output information used to persisted under this prefix until LDK Node v0.3.0.
31-
pub(crate) const DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str =
32-
"spendable_outputs";
33-
pub(crate) const DEPRECATED_SPENDABLE_OUTPUT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";
34-
3530
/// The node metrics will be persisted under this key.
3631
pub(crate) const NODE_METRICS_PRIMARY_NAMESPACE: &str = "";
3732
pub(crate) const NODE_METRICS_SECONDARY_NAMESPACE: &str = "";

src/io/utils.rs

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::io::{
1515
};
1616
use crate::logger::{log_error, LdkLogger, Logger};
1717
use crate::peer_store::PeerStore;
18-
use crate::sweep::DeprecatedSpendableOutputInfo;
1918
use crate::types::{Broadcaster, DynStore, KeysManager, Sweeper};
2019
use crate::wallet::ser::{ChangeSetDeserWrapper, ChangeSetSerWrapper};
2120
use crate::{Error, EventQueue, NodeMetrics, PaymentDetails};
@@ -33,7 +32,7 @@ use lightning::util::persist::{
3332
};
3433
use lightning::util::ser::{Readable, ReadableArgs, Writeable};
3534
use lightning::util::string::PrintableString;
36-
use lightning::util::sweep::{OutputSpendStatus, OutputSweeper};
35+
use lightning::util::sweep::OutputSweeper;
3736

3837
use bdk_chain::indexer::keychain_txout::ChangeSet as BdkIndexerChangeSet;
3938
use 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-
358260
pub(crate) fn read_node_metrics<L: Deref>(
359261
kv_store: Arc<DynStore>, logger: L,
360262
) -> Result<NodeMetrics, std::io::Error>

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ pub mod logger;
9494
mod message_handler;
9595
pub mod payment;
9696
mod peer_store;
97-
mod sweep;
9897
mod tx_broadcaster;
9998
mod types;
10099
mod wallet;

src/sweep.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)