Skip to content

Commit 5f6c91f

Browse files
committed
fixup! Start storing ForwardedPayments using PaginatedKVStore.
1 parent 2d68138 commit 5f6c91f

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

ldk-server/src/main.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,14 @@ fn main() {
8686
},
8787
};
8888

89-
let paginated_store = Arc::new(
90-
SqliteStore::new(PathBuf::from(config_file.storage_dir_path), None, None).unwrap(),
91-
);
89+
let paginated_store =
90+
Arc::new(match SqliteStore::new(PathBuf::from(config_file.storage_dir_path), None, None) {
91+
Ok(store) => store,
92+
Err(e) => {
93+
eprintln!("Failed to create SqliteStore: {:?}", e);
94+
std::process::exit(-1);
95+
},
96+
});
9297

9398
println!("Starting up...");
9499
match node.start_with_runtime(Arc::clone(&runtime)) {
@@ -142,7 +147,7 @@ fn main() {
142147
);
143148
event_node.event_handled();
144149
},
145-
payment_forwarded_event @ Event::PaymentForwarded {
150+
Event::PaymentForwarded {
146151
prev_channel_id,
147152
next_channel_id,
148153
prev_user_channel_id,
@@ -157,12 +162,21 @@ fn main() {
157162
outbound_amount_forwarded_msat.unwrap_or(0), total_fee_earned_msat.unwrap_or(0), prev_channel_id, next_channel_id
158163
);
159164

160-
let forwarded_payment = forwarded_payment_to_proto(payment_forwarded_event);
165+
let forwarded_payment = forwarded_payment_to_proto(
166+
prev_channel_id,
167+
next_channel_id,
168+
prev_user_channel_id,
169+
next_user_channel_id,
170+
total_fee_earned_msat,
171+
skimmed_fee_msat,
172+
claim_from_onchain_tx,
173+
outbound_amount_forwarded_msat
174+
);
161175

162176
// We don't expose this payment-id to the user, it is a temporary measure to generate
163177
// some unique identifiers until we have forwarded-payment-id available in ldk.
164178
// Currently, this is the expected user handling behaviour for forwarded payments.
165-
let mut forwarded_payment_id:[u8;32];
179+
let mut forwarded_payment_id = [0u8;32];
166180
rand::thread_rng().fill(&mut forwarded_payment_id);
167181

168182
let forwarded_payment_creation_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs() as i64;

ldk-server/src/util/proto_adapter.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use bytes::Bytes;
22
use hex::prelude::*;
33
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
4+
use ldk_node::lightning::ln::types::ChannelId;
45
use ldk_node::payment::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
5-
use ldk_node::{ChannelDetails, Event, LightningBalance, PendingSweepBalance};
6+
use ldk_node::{ChannelDetails, Event, LightningBalance, PendingSweepBalance, UserChannelId};
67
use ldk_server_protos::types::lightning_balance::BalanceType::{
78
ClaimableAwaitingConfirmations, ClaimableOnChannelClose, ContentiousClaimable,
89
CounterpartyRevokedOutputClaimable, MaybePreimageClaimableHtlc, MaybeTimeoutClaimableHtlc,
@@ -321,29 +322,20 @@ pub(crate) fn pending_sweep_balance_to_proto(
321322
}
322323
}
323324

324-
pub(crate) fn forwarded_payment_to_proto(payment_forwarded_event: Event) -> ForwardedPayment {
325-
if let Event::PaymentForwarded {
326-
prev_channel_id,
327-
next_channel_id,
328-
prev_user_channel_id,
329-
next_user_channel_id,
325+
pub(crate) fn forwarded_payment_to_proto(
326+
prev_channel_id: ChannelId, next_channel_id: ChannelId,
327+
prev_user_channel_id: Option<UserChannelId>, next_user_channel_id: Option<UserChannelId>,
328+
total_fee_earned_msat: Option<u64>, skimmed_fee_msat: Option<u64>, claim_from_onchain_tx: bool,
329+
outbound_amount_forwarded_msat: Option<u64>,
330+
) -> ForwardedPayment {
331+
ForwardedPayment {
332+
prev_channel_id: prev_channel_id.to_string(),
333+
next_channel_id: next_channel_id.to_string(),
334+
prev_user_channel_id: prev_user_channel_id.expect("").0.to_string(),
335+
next_user_channel_id: next_user_channel_id.map(|u| u.0.to_string()),
330336
total_fee_earned_msat,
331337
skimmed_fee_msat,
332338
claim_from_onchain_tx,
333339
outbound_amount_forwarded_msat,
334-
} = payment_forwarded_event
335-
{
336-
ForwardedPayment {
337-
prev_channel_id: prev_channel_id.to_string(),
338-
next_channel_id: next_channel_id.to_string(),
339-
prev_user_channel_id: prev_user_channel_id.expect("").0.to_string(),
340-
next_user_channel_id: next_user_channel_id.map(|u| u.0.to_string()),
341-
total_fee_earned_msat,
342-
skimmed_fee_msat,
343-
claim_from_onchain_tx,
344-
outbound_amount_forwarded_msat,
345-
}
346-
} else {
347-
panic!("Expected Event::PaymentForwarded variant.");
348340
}
349341
}

0 commit comments

Comments
 (0)