Skip to content

Commit 861f6e3

Browse files
authored
Merge pull request #748 from tnull/2026-01-fix-backwards-compat
Fix backwards compatibility of `NodeMetrics` reads
2 parents 80a1745 + 93b6b42 commit 861f6e3

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "
8888
proptest = "1.0.0"
8989
regex = "1.5.6"
9090
criterion = { version = "0.7.0", features = ["async_tokio"] }
91+
ldk-node-062 = { package = "ldk-node", version = "=0.6.2" }
9192

9293
[target.'cfg(not(no_download))'.dev-dependencies]
9394
electrsd = { version = "0.36.1", default-features = false, features = ["legacy", "esplora_a33e97e1", "corepc-node_27_2"] }
@@ -103,9 +104,6 @@ clightningrpc = { version = "0.3.0-beta.8", default-features = false }
103104
lnd_grpc_rust = { version = "2.10.0", default-features = false }
104105
tokio = { version = "1.37", features = ["fs"] }
105106

106-
[target.'cfg(vss_test)'.dev-dependencies]
107-
ldk-node-062 = { package = "ldk-node", version = "=0.6.2" }
108-
109107
[build-dependencies]
110108
uniffi = { version = "0.28.3", features = ["build"], optional = true }
111109

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bitcoin::key::Secp256k1;
2020
use bitcoin::secp256k1::PublicKey;
2121
use bitcoin::{BlockHash, Network};
2222
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
23-
use lightning::chain::{chainmonitor, BestBlock, Watch};
23+
use lightning::chain::{chainmonitor, BestBlock};
2424
use lightning::ln::channelmanager::{self, ChainParameters, ChannelManagerReadArgs};
2525
use lightning::ln::msgs::{RoutingMessageHandler, SocketAddress};
2626
use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ impl_writeable_tlv_based!(NodeMetrics, {
18371837
(6, latest_rgs_snapshot_timestamp, option),
18381838
(8, latest_node_announcement_broadcast_timestamp, option),
18391839
// 10 used to be latest_channel_monitor_archival_height
1840-
(10, _legacy_latest_channel_monitor_archival_height, (legacy, Option<u32>, |_: &NodeMetrics| None::<Option<u32>> )),
1840+
(10, _legacy_latest_channel_monitor_archival_height, (legacy, u32, |_: &NodeMetrics| None::<Option<u32>> )),
18411841
});
18421842

18431843
pub(crate) fn total_anchor_channels_reserve_sats(

tests/integration_tests_rust.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use common::{
2727
TestSyncStore,
2828
};
2929
use ldk_node::config::{AsyncPaymentsRole, EsploraSyncConfig};
30+
use ldk_node::entropy::NodeEntropy;
3031
use ldk_node::liquidity::LSPS2ServiceConfig;
3132
use ldk_node::payment::{
3233
ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
@@ -2436,3 +2437,61 @@ async fn payment_persistence_after_restart() {
24362437

24372438
restarted_node_a.stop().unwrap();
24382439
}
2440+
2441+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
2442+
async fn persistence_backwards_compatibility() {
2443+
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
2444+
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
2445+
2446+
let storage_path = common::random_storage_path().to_str().unwrap().to_owned();
2447+
let seed_bytes = [42u8; 64];
2448+
let node_entropy = NodeEntropy::from_seed_bytes(seed_bytes);
2449+
2450+
// Setup a v0.6.2 `Node`
2451+
let (old_balance, old_node_id) = {
2452+
let mut builder_old = ldk_node_062::Builder::new();
2453+
builder_old.set_network(bitcoin::Network::Regtest);
2454+
builder_old.set_storage_dir_path(storage_path.clone());
2455+
builder_old.set_entropy_seed_bytes(seed_bytes);
2456+
builder_old.set_chain_source_esplora(esplora_url.clone(), None);
2457+
let node_old = builder_old.build().unwrap();
2458+
2459+
node_old.start().unwrap();
2460+
let addr_old = node_old.onchain_payment().new_address().unwrap();
2461+
common::premine_and_distribute_funds(
2462+
&bitcoind.client,
2463+
&electrsd.client,
2464+
vec![addr_old],
2465+
bitcoin::Amount::from_sat(100_000),
2466+
)
2467+
.await;
2468+
node_old.sync_wallets().unwrap();
2469+
2470+
let balance = node_old.list_balances().spendable_onchain_balance_sats;
2471+
assert!(balance > 0);
2472+
let node_id = node_old.node_id();
2473+
2474+
node_old.stop().unwrap();
2475+
2476+
(balance, node_id)
2477+
};
2478+
2479+
// Now ensure we can still reinit from the same backend.
2480+
let mut builder_new = Builder::new();
2481+
builder_new.set_network(bitcoin::Network::Regtest);
2482+
builder_new.set_storage_dir_path(storage_path);
2483+
builder_new.set_chain_source_esplora(esplora_url, None);
2484+
2485+
let node_new = builder_new.build(node_entropy).unwrap();
2486+
2487+
node_new.start().unwrap();
2488+
node_new.sync_wallets().unwrap();
2489+
2490+
let new_balance = node_new.list_balances().spendable_onchain_balance_sats;
2491+
let new_node_id = node_new.node_id();
2492+
2493+
assert_eq!(old_node_id, new_node_id);
2494+
assert_eq!(old_balance, new_balance);
2495+
2496+
node_new.stop().unwrap();
2497+
}

0 commit comments

Comments
 (0)