Skip to content

Commit

Permalink
Rename persister in handle_ldk_events to differentiate store
Browse files Browse the repository at this point in the history
Since we now have a `Persist`er which is separate from our
`FilesystemStore`, its useful to use different names to
differentiate the two.
  • Loading branch information
TheBlueMatt committed Oct 15, 2023
1 parent f27446d commit f5d699d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn poll_for_user_input(
keys_manager: Arc<KeysManager>, network_graph: Arc<NetworkGraph>,
onion_messenger: Arc<OnionMessenger>, inbound_payments: Arc<Mutex<PaymentInfoStorage>>,
outbound_payments: Arc<Mutex<PaymentInfoStorage>>, ldk_data_dir: String, network: Network,
logger: Arc<disk::FilesystemLogger>, persister: Arc<FilesystemStore>,
logger: Arc<disk::FilesystemLogger>, fs_store: Arc<FilesystemStore>,
) {
println!(
"LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit."
Expand Down Expand Up @@ -172,7 +172,7 @@ pub(crate) fn poll_for_user_input(
&channel_manager,
&invoice,
&mut outbound_payments.lock().unwrap(),
persister.clone(),
Arc::clone(&fs_store),
);
}
"keysend" => {
Expand Down Expand Up @@ -209,7 +209,7 @@ pub(crate) fn poll_for_user_input(
amt_msat,
&*keys_manager,
&mut outbound_payments.lock().unwrap(),
persister.clone(),
Arc::clone(&fs_store),
);
}
"getinvoice" => {
Expand Down Expand Up @@ -247,7 +247,7 @@ pub(crate) fn poll_for_user_input(
expiry_secs.unwrap(),
Arc::clone(&logger),
);
persister
fs_store
.write("", "", INBOUND_PAYMENTS_FNAME, &inbound_payments.encode())
.unwrap();
}
Expand Down Expand Up @@ -684,7 +684,7 @@ fn open_channel(

fn send_payment(
channel_manager: &ChannelManager, invoice: &Bolt11Invoice,
outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemStore>,
outbound_payments: &mut PaymentInfoStorage, fs_store: Arc<FilesystemStore>,
) {
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
let payment_secret = Some(*invoice.payment_secret());
Expand All @@ -697,7 +697,7 @@ fn send_payment(
amt_msat: MillisatAmount(invoice.amount_milli_satoshis()),
},
);
persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
match pay_invoice(invoice, Retry::Timeout(Duration::from_secs(10)), channel_manager) {
Ok(_payment_id) => {
let payee_pubkey = invoice.recover_payee_pub_key();
Expand All @@ -709,14 +709,14 @@ fn send_payment(
println!("ERROR: failed to send payment: {:?}", e);
print!("> ");
outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed;
persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
}
};
}

fn keysend<E: EntropySource>(
channel_manager: &ChannelManager, payee_pubkey: PublicKey, amt_msat: u64, entropy_source: &E,
outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemStore>,
outbound_payments: &mut PaymentInfoStorage, fs_store: Arc<FilesystemStore>,
) {
let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
Expand All @@ -734,7 +734,7 @@ fn keysend<E: EntropySource>(
amt_msat: MillisatAmount(Some(amt_msat)),
},
);
persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
match channel_manager.send_spontaneous_payment_with_retry(
Some(payment_preimage),
RecipientOnionFields::spontaneous_empty(),
Expand All @@ -750,7 +750,7 @@ fn keysend<E: EntropySource>(
println!("ERROR: failed to send payment: {:?}", e);
print!("> ");
outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed;
persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
}
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async fn handle_ldk_events(
channel_manager: &Arc<ChannelManager>, bitcoind_client: &BitcoindClient,
network_graph: &NetworkGraph, keys_manager: &KeysManager,
bump_tx_event_handler: &BumpTxEventHandler, inbound_payments: Arc<Mutex<PaymentInfoStorage>>,
outbound_payments: Arc<Mutex<PaymentInfoStorage>>, persister: &Arc<FilesystemStore>,
outbound_payments: Arc<Mutex<PaymentInfoStorage>>, fs_store: &Arc<FilesystemStore>,
network: Network, event: Event,
) {
match event {
Expand Down Expand Up @@ -272,7 +272,7 @@ async fn handle_ldk_events(
});
}
}
persister.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap();
fs_store.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap();
}
Event::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => {
let mut outbound = outbound_payments.lock().unwrap();
Expand All @@ -296,7 +296,7 @@ async fn handle_ldk_events(
io::stdout().flush().unwrap();
}
}
persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
}
Event::OpenChannelRequest {
ref temporary_channel_id, ref counterparty_node_id, ..
Expand Down Expand Up @@ -345,7 +345,7 @@ async fn handle_ldk_events(
let payment = outbound.payments.get_mut(&payment_hash).unwrap();
payment.status = HTLCStatus::Failed;
}
persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
}
Event::PaymentForwarded {
prev_channel_id,
Expand Down Expand Up @@ -433,7 +433,7 @@ async fn handle_ldk_events(
let key = hex_utils::hex_str(&keys_manager.get_secure_random_bytes());
// Note that if the type here changes our read code needs to change as well.
let output: SpendableOutputDescriptor = output;
persister.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap();
fs_store.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap();
}
}
Event::ChannelPending { channel_id, counterparty_node_id, .. } => {
Expand Down

0 comments on commit f5d699d

Please sign in to comment.