@@ -390,6 +390,69 @@ impl From<&ClaimableHTLC> for events::ClaimedHTLC {
390
390
}
391
391
}
392
392
393
+ #[derive(Clone, PartialEq, Eq)]
394
+ pub struct StubChannel {
395
+ pub channel_id: ChannelId,
396
+ pub funding_outpoint: OutPoint,
397
+ pub channel_value_stoshis: u64,
398
+ pub channel_keys_id: [u8;32],
399
+ pub commitment_secrets: CounterpartyCommitmentSecrets,
400
+ pub counterparty_node_id: PublicKey,
401
+ }
402
+
403
+ impl StubChannel {
404
+ pub fn new(channel_id: ChannelId, funding_outpoint: OutPoint, channel_value_stoshis: u64, channel_keys_id: [u8; 32], commitment_secrets: CounterpartyCommitmentSecrets, counterparty_node_id: PublicKey) -> Self {
405
+ StubChannel {
406
+ channel_id,
407
+ funding_outpoint,
408
+ channel_value_stoshis,
409
+ channel_keys_id,
410
+ commitment_secrets,
411
+ counterparty_node_id,
412
+ }
413
+ }
414
+ }
415
+
416
+ impl_writeable_tlv_based!(StubChannel, {
417
+ (0, channel_id, required),
418
+ (2, channel_keys_id, required),
419
+ (4, channel_value_stoshis, required),
420
+ (6, funding_outpoint, required),
421
+ (8, commitment_secrets, required),
422
+ (10, counterparty_node_id, required),
423
+ });
424
+
425
+ #[derive(Clone, PartialEq, Eq)]
426
+ pub struct OurPeerStorage {
427
+ pub version: u32,
428
+ pub timestamp: u32,
429
+ pub channels: Vec<StubChannel>,
430
+ }
431
+
432
+ impl OurPeerStorage {
433
+ pub fn new() -> Self {
434
+ let duration_since_epoch = std::time::SystemTime::now()
435
+ .duration_since(std::time::SystemTime::UNIX_EPOCH)
436
+ .expect("Time must be > 1970");
437
+
438
+ Self {
439
+ version: 1,
440
+ timestamp: duration_since_epoch.as_secs() as u32,
441
+ channels: Vec::new(),
442
+ }
443
+ }
444
+
445
+ pub fn stub_channel(&mut self, chan: StubChannel) {
446
+ self.channels.push(chan);
447
+ }
448
+ }
449
+
450
+ impl_writeable_tlv_based!(OurPeerStorage, {
451
+ (0, version, (default_value, 1)),
452
+ (2, timestamp, required),
453
+ (4, channels, optional_vec),
454
+ });
455
+
393
456
/// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
394
457
/// a payment and ensure idempotency in LDK.
395
458
///
@@ -1432,6 +1495,7 @@ where
1432
1495
entropy_source: ES,
1433
1496
node_signer: NS,
1434
1497
signer_provider: SP,
1498
+ our_peer_storage: FairRwLock<OurPeerStorage>,
1435
1499
1436
1500
logger: L,
1437
1501
}
@@ -2527,6 +2591,7 @@ where
2527
2591
entropy_source,
2528
2592
node_signer,
2529
2593
signer_provider,
2594
+ our_peer_storage: FairRwLock::new(OurPeerStorage::new()),
2530
2595
logger,
2531
2596
}
2532
2597
}
@@ -10844,6 +10909,8 @@ where
10844
10909
let mut close_background_events = Vec::new();
10845
10910
let mut funding_txo_to_channel_id = hash_map_with_capacity(channel_count as usize);
10846
10911
let mut peer_storage_dir: HashMap<PublicKey, Vec<u8>> = HashMap::new();
10912
+ let mut our_peer_storage: OurPeerStorage = OurPeerStorage::new();
10913
+
10847
10914
for _ in 0..channel_count {
10848
10915
let mut channel: Channel<SP> = Channel::read(reader, (
10849
10916
&args.entropy_source, &args.signer_provider, best_block_height, &provided_channel_type_features(&args.default_config)
@@ -10852,6 +10919,15 @@ where
10852
10919
let funding_txo = channel.context.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
10853
10920
funding_txo_to_channel_id.insert(funding_txo, channel.context.channel_id());
10854
10921
funding_txo_set.insert(funding_txo.clone());
10922
+ let stub_chan = StubChannel::new(
10923
+ channel.context.channel_id(),
10924
+ funding_txo,
10925
+ channel.context.get_value_satoshis(),
10926
+ channel.context.get_channel_keys_id(),
10927
+ channel.context.get_commitment_secret(),
10928
+ channel.context.get_counterparty_node_id(),
10929
+ );
10930
+ our_peer_storage.stub_channel(stub_chan);
10855
10931
if let Some(ref mut monitor) = args.channel_monitors.get_mut(&funding_txo) {
10856
10932
// Load Peer_storage from ChannelMonitor to memory.
10857
10933
peer_storage_dir.insert(channel.context.get_counterparty_node_id(), monitor.get_peer_storage());
@@ -11682,6 +11758,7 @@ where
11682
11758
entropy_source: args.entropy_source,
11683
11759
node_signer: args.node_signer,
11684
11760
signer_provider: args.signer_provider,
11761
+ our_peer_storage: FairRwLock::new(our_peer_storage),
11685
11762
logger: args.logger,
11686
11763
default_configuration: args.default_config,
11687
11764
};
0 commit comments