Skip to content

Commit

Permalink
fixup! Start storing ForwardedPayments using PaginatedKVStore.
Browse files Browse the repository at this point in the history
  • Loading branch information
G8XSU committed Dec 12, 2024
1 parent 2d68138 commit 5f6c91f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
26 changes: 20 additions & 6 deletions ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ fn main() {
},
};

let paginated_store = Arc::new(
SqliteStore::new(PathBuf::from(config_file.storage_dir_path), None, None).unwrap(),
);
let paginated_store =
Arc::new(match SqliteStore::new(PathBuf::from(config_file.storage_dir_path), None, None) {
Ok(store) => store,
Err(e) => {
eprintln!("Failed to create SqliteStore: {:?}", e);
std::process::exit(-1);
},
});

println!("Starting up...");
match node.start_with_runtime(Arc::clone(&runtime)) {
Expand Down Expand Up @@ -142,7 +147,7 @@ fn main() {
);
event_node.event_handled();
},
payment_forwarded_event @ Event::PaymentForwarded {
Event::PaymentForwarded {
prev_channel_id,
next_channel_id,
prev_user_channel_id,
Expand All @@ -157,12 +162,21 @@ fn main() {
outbound_amount_forwarded_msat.unwrap_or(0), total_fee_earned_msat.unwrap_or(0), prev_channel_id, next_channel_id
);

let forwarded_payment = forwarded_payment_to_proto(payment_forwarded_event);
let forwarded_payment = forwarded_payment_to_proto(
prev_channel_id,
next_channel_id,
prev_user_channel_id,
next_user_channel_id,
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat
);

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

let forwarded_payment_creation_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs() as i64;
Expand Down
34 changes: 13 additions & 21 deletions ldk-server/src/util/proto_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use bytes::Bytes;
use hex::prelude::*;
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::lightning::ln::types::ChannelId;
use ldk_node::payment::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
use ldk_node::{ChannelDetails, Event, LightningBalance, PendingSweepBalance};
use ldk_node::{ChannelDetails, Event, LightningBalance, PendingSweepBalance, UserChannelId};
use ldk_server_protos::types::lightning_balance::BalanceType::{
ClaimableAwaitingConfirmations, ClaimableOnChannelClose, ContentiousClaimable,
CounterpartyRevokedOutputClaimable, MaybePreimageClaimableHtlc, MaybeTimeoutClaimableHtlc,
Expand Down Expand Up @@ -321,29 +322,20 @@ pub(crate) fn pending_sweep_balance_to_proto(
}
}

pub(crate) fn forwarded_payment_to_proto(payment_forwarded_event: Event) -> ForwardedPayment {
if let Event::PaymentForwarded {
prev_channel_id,
next_channel_id,
prev_user_channel_id,
next_user_channel_id,
pub(crate) fn forwarded_payment_to_proto(
prev_channel_id: ChannelId, next_channel_id: ChannelId,
prev_user_channel_id: Option<UserChannelId>, next_user_channel_id: Option<UserChannelId>,
total_fee_earned_msat: Option<u64>, skimmed_fee_msat: Option<u64>, claim_from_onchain_tx: bool,
outbound_amount_forwarded_msat: Option<u64>,
) -> ForwardedPayment {
ForwardedPayment {
prev_channel_id: prev_channel_id.to_string(),
next_channel_id: next_channel_id.to_string(),
prev_user_channel_id: prev_user_channel_id.expect("").0.to_string(),
next_user_channel_id: next_user_channel_id.map(|u| u.0.to_string()),
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
} = payment_forwarded_event
{
ForwardedPayment {
prev_channel_id: prev_channel_id.to_string(),
next_channel_id: next_channel_id.to_string(),
prev_user_channel_id: prev_user_channel_id.expect("").0.to_string(),
next_user_channel_id: next_user_channel_id.map(|u| u.0.to_string()),
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
}
} else {
panic!("Expected Event::PaymentForwarded variant.");
}
}

0 comments on commit 5f6c91f

Please sign in to comment.