Skip to content

Commit 5b81f38

Browse files
authored
Merge pull request #123 from TheBlueMatt/main
Upgrade to LDK 0.0.118
2 parents 941cab5 + 37da86a commit 5b81f38

File tree

7 files changed

+131
-90
lines changed

7 files changed

+131
-90
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ edition = "2018"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
lightning = { version = "0.0.117", features = ["max_level_trace"] }
12-
lightning-block-sync = { version = "0.0.117", features = [ "rpc-client", "tokio" ] }
13-
lightning-invoice = { version = "0.25.0" }
14-
lightning-net-tokio = { version = "0.0.117" }
15-
lightning-persister = { version = "0.0.117" }
16-
lightning-background-processor = { version = "0.0.117", features = [ "futures" ] }
17-
lightning-rapid-gossip-sync = { version = "0.0.117" }
11+
lightning = { version = "0.0.118", features = ["max_level_trace"] }
12+
lightning-block-sync = { version = "0.0.118", features = [ "rpc-client", "tokio" ] }
13+
lightning-invoice = { version = "0.26.0" }
14+
lightning-net-tokio = { version = "0.0.118" }
15+
lightning-persister = { version = "0.0.118" }
16+
lightning-background-processor = { version = "0.0.118", features = [ "futures" ] }
17+
lightning-rapid-gossip-sync = { version = "0.0.118" }
1818

1919
base64 = "0.13.0"
2020
bitcoin = "0.29.0"
2121
bitcoin-bech32 = "0.12"
2222
bech32 = "0.8"
23-
hex = "0.3"
2423
libc = "0.2"
2524

2625
chrono = { version = "0.4", default-features = false, features = ["clock"] }

src/bitcoind_client.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use bitcoin::{OutPoint, Script, TxOut, WPubkeyHash, XOnlyPublicKey};
1515
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
1616
use lightning::events::bump_transaction::{Utxo, WalletSource};
1717
use lightning::log_error;
18-
use lightning::routing::utxo::{UtxoLookup, UtxoResult};
1918
use lightning::util::logger::Logger;
2019
use lightning_block_sync::http::HttpEndpoint;
2120
use lightning_block_sync::rpc::RpcClient;
@@ -76,10 +75,23 @@ impl BitcoindClient {
7675
"Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
7776
})?;
7877
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::new();
79-
fees.insert(ConfirmationTarget::MempoolMinimum, AtomicU32::new(MIN_FEERATE));
80-
fees.insert(ConfirmationTarget::Background, AtomicU32::new(MIN_FEERATE));
81-
fees.insert(ConfirmationTarget::Normal, AtomicU32::new(2000));
82-
fees.insert(ConfirmationTarget::HighPriority, AtomicU32::new(5000));
78+
fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
79+
fees.insert(
80+
ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
81+
AtomicU32::new(25 * 250),
82+
);
83+
fees.insert(
84+
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
85+
AtomicU32::new(MIN_FEERATE),
86+
);
87+
fees.insert(
88+
ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
89+
AtomicU32::new(MIN_FEERATE),
90+
);
91+
fees.insert(ConfirmationTarget::AnchorChannelFee, AtomicU32::new(MIN_FEERATE));
92+
fees.insert(ConfirmationTarget::NonAnchorChannelFee, AtomicU32::new(2000));
93+
fees.insert(ConfirmationTarget::ChannelCloseMinimum, AtomicU32::new(MIN_FEERATE));
94+
8395
let client = Self {
8496
bitcoind_rpc_client: Arc::new(bitcoind_rpc_client),
8597
host,
@@ -163,18 +175,28 @@ impl BitcoindClient {
163175
}
164176
};
165177

166-
fees.get(&ConfirmationTarget::MempoolMinimum)
178+
fees.get(&ConfirmationTarget::OnChainSweep)
179+
.unwrap()
180+
.store(high_prio_estimate, Ordering::Release);
181+
fees.get(&ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee)
182+
.unwrap()
183+
.store(std::cmp::max(25 * 250, high_prio_estimate * 10), Ordering::Release);
184+
fees.get(&ConfirmationTarget::MinAllowedAnchorChannelRemoteFee)
167185
.unwrap()
168186
.store(mempoolmin_estimate, Ordering::Release);
169-
fees.get(&ConfirmationTarget::Background)
187+
fees.get(&ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee)
188+
.unwrap()
189+
.store(background_estimate - 250, Ordering::Release);
190+
fees.get(&ConfirmationTarget::AnchorChannelFee)
170191
.unwrap()
171192
.store(background_estimate, Ordering::Release);
172-
fees.get(&ConfirmationTarget::Normal)
193+
fees.get(&ConfirmationTarget::NonAnchorChannelFee)
173194
.unwrap()
174195
.store(normal_estimate, Ordering::Release);
175-
fees.get(&ConfirmationTarget::HighPriority)
196+
fees.get(&ConfirmationTarget::ChannelCloseMinimum)
176197
.unwrap()
177-
.store(high_prio_estimate, Ordering::Release);
198+
.store(background_estimate, Ordering::Release);
199+
178200
tokio::time::sleep(Duration::from_secs(60)).await;
179201
}
180202
});
@@ -204,7 +226,8 @@ impl BitcoindClient {
204226
// LDK gives us feerates in satoshis per KW but Bitcoin Core here expects fees
205227
// denominated in satoshis per vB. First we need to multiply by 4 to convert weight
206228
// units to virtual bytes, then divide by 1000 to convert KvB to vB.
207-
"fee_rate": self.get_est_sat_per_1000_weight(ConfirmationTarget::Normal) as f64 / 250.0,
229+
"fee_rate": self
230+
.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee) as f64 / 250.0,
208231
// While users could "cancel" a channel open by RBF-bumping and paying back to
209232
// themselves, we don't allow it here as its easy to have users accidentally RBF bump
210233
// and pay to the channel funding address, which results in loss of funds. Real
@@ -296,13 +319,6 @@ impl BroadcasterInterface for BitcoindClient {
296319
}
297320
}
298321

299-
impl UtxoLookup for BitcoindClient {
300-
fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
301-
// P2PGossipSync takes None for a UtxoLookup, so this will never be called.
302-
todo!();
303-
}
304-
}
305-
306322
impl WalletSource for BitcoindClient {
307323
fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()> {
308324
let utxos = tokio::task::block_in_place(move || {

src/cli.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::disk::{self, INBOUND_PAYMENTS_FNAME, OUTBOUND_PAYMENTS_FNAME};
22
use crate::hex_utils;
33
use crate::{
4-
ChannelManager, HTLCStatus, MillisatAmount, NetworkGraph, OnionMessenger, PaymentInfo,
5-
PaymentInfoStorage, PeerManager,
4+
ChannelManager, HTLCStatus, InboundPaymentInfoStorage, MillisatAmount, NetworkGraph,
5+
OnionMessenger, OutboundPaymentInfoStorage, PaymentInfo, PeerManager,
66
};
77
use bitcoin::hashes::sha256::Hash as Sha256;
88
use bitcoin::hashes::Hash;
@@ -12,7 +12,7 @@ use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
1212
use lightning::ln::msgs::SocketAddress;
1313
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
1414
use lightning::onion_message::OnionMessagePath;
15-
use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents};
15+
use lightning::onion_message::{Destination, OnionMessageContents};
1616
use lightning::routing::gossip::NodeId;
1717
use lightning::routing::router::{PaymentParameters, RouteParameters};
1818
use lightning::sign::{EntropySource, KeysManager};
@@ -48,7 +48,7 @@ struct UserOnionMessageContents {
4848
data: Vec<u8>,
4949
}
5050

51-
impl CustomOnionMessageContents for UserOnionMessageContents {
51+
impl OnionMessageContents for UserOnionMessageContents {
5252
fn tlv_type(&self) -> u64 {
5353
self.tlv_type
5454
}
@@ -63,9 +63,9 @@ impl Writeable for UserOnionMessageContents {
6363
pub(crate) fn poll_for_user_input(
6464
peer_manager: Arc<PeerManager>, channel_manager: Arc<ChannelManager>,
6565
keys_manager: Arc<KeysManager>, network_graph: Arc<NetworkGraph>,
66-
onion_messenger: Arc<OnionMessenger>, inbound_payments: Arc<Mutex<PaymentInfoStorage>>,
67-
outbound_payments: Arc<Mutex<PaymentInfoStorage>>, ldk_data_dir: String, network: Network,
68-
logger: Arc<disk::FilesystemLogger>, fs_store: Arc<FilesystemStore>,
66+
onion_messenger: Arc<OnionMessenger>, inbound_payments: Arc<Mutex<InboundPaymentInfoStorage>>,
67+
outbound_payments: Arc<Mutex<OutboundPaymentInfoStorage>>, ldk_data_dir: String,
68+
network: Network, logger: Arc<disk::FilesystemLogger>, fs_store: Arc<FilesystemStore>,
6969
) {
7070
println!(
7171
"LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit."
@@ -445,7 +445,7 @@ pub(crate) fn poll_for_user_input(
445445
let message_path = OnionMessagePath { intermediate_nodes, destination };
446446
match onion_messenger.send_onion_message(
447447
message_path,
448-
OnionMessageContents::Custom(UserOnionMessageContents { tlv_type, data }),
448+
UserOnionMessageContents { tlv_type, data },
449449
None,
450450
) {
451451
Ok(()) => println!("SUCCESS: forwarded onion message to first hop"),
@@ -553,7 +553,9 @@ fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<Netw
553553
println!("]");
554554
}
555555

556-
fn list_payments(inbound_payments: &PaymentInfoStorage, outbound_payments: &PaymentInfoStorage) {
556+
fn list_payments(
557+
inbound_payments: &InboundPaymentInfoStorage, outbound_payments: &OutboundPaymentInfoStorage,
558+
) {
557559
print!("[");
558560
for (payment_hash, payment_info) in &inbound_payments.payments {
559561
println!("");
@@ -684,12 +686,12 @@ fn open_channel(
684686

685687
fn send_payment(
686688
channel_manager: &ChannelManager, invoice: &Bolt11Invoice,
687-
outbound_payments: &mut PaymentInfoStorage, fs_store: Arc<FilesystemStore>,
689+
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
688690
) {
689-
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
691+
let payment_id = PaymentId((*invoice.payment_hash()).into_inner());
690692
let payment_secret = Some(*invoice.payment_secret());
691693
outbound_payments.payments.insert(
692-
payment_hash,
694+
payment_id,
693695
PaymentInfo {
694696
preimage: None,
695697
secret: payment_secret,
@@ -708,25 +710,25 @@ fn send_payment(
708710
Err(e) => {
709711
println!("ERROR: failed to send payment: {:?}", e);
710712
print!("> ");
711-
outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed;
713+
outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
712714
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
713715
}
714716
};
715717
}
716718

717719
fn keysend<E: EntropySource>(
718720
channel_manager: &ChannelManager, payee_pubkey: PublicKey, amt_msat: u64, entropy_source: &E,
719-
outbound_payments: &mut PaymentInfoStorage, fs_store: Arc<FilesystemStore>,
721+
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
720722
) {
721723
let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
722-
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
724+
let payment_id = PaymentId(Sha256::hash(&payment_preimage.0[..]).into_inner());
723725

724726
let route_params = RouteParameters::from_payment_params_and_value(
725727
PaymentParameters::for_keysend(payee_pubkey, 40, false),
726728
amt_msat,
727729
);
728730
outbound_payments.payments.insert(
729-
payment_hash,
731+
payment_id,
730732
PaymentInfo {
731733
preimage: None,
732734
secret: None,
@@ -738,7 +740,7 @@ fn keysend<E: EntropySource>(
738740
match channel_manager.send_spontaneous_payment_with_retry(
739741
Some(payment_preimage),
740742
RecipientOnionFields::spontaneous_empty(),
741-
PaymentId(payment_hash.0),
743+
payment_id,
742744
route_params,
743745
Retry::Timeout(Duration::from_secs(10)),
744746
) {
@@ -749,16 +751,16 @@ fn keysend<E: EntropySource>(
749751
Err(e) => {
750752
println!("ERROR: failed to send payment: {:?}", e);
751753
print!("> ");
752-
outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed;
754+
outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
753755
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
754756
}
755757
};
756758
}
757759

758760
fn get_invoice(
759-
amt_msat: u64, inbound_payments: &mut PaymentInfoStorage, channel_manager: &ChannelManager,
760-
keys_manager: Arc<KeysManager>, network: Network, expiry_secs: u32,
761-
logger: Arc<disk::FilesystemLogger>,
761+
amt_msat: u64, inbound_payments: &mut InboundPaymentInfoStorage,
762+
channel_manager: &ChannelManager, keys_manager: Arc<KeysManager>, network: Network,
763+
expiry_secs: u32, logger: Arc<disk::FilesystemLogger>,
762764
) {
763765
let currency = match network {
764766
Network::Bitcoin => Currency::Bitcoin,

src/disk.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{cli, NetworkGraph, PaymentInfoStorage};
1+
use crate::{cli, InboundPaymentInfoStorage, NetworkGraph, OutboundPaymentInfoStorage};
22
use bitcoin::secp256k1::PublicKey;
33
use bitcoin::Network;
44
use chrono::Utc;
@@ -86,13 +86,22 @@ pub(crate) fn read_network(
8686
NetworkGraph::new(network, logger)
8787
}
8888

89-
pub(crate) fn read_payment_info(path: &Path) -> PaymentInfoStorage {
89+
pub(crate) fn read_inbound_payment_info(path: &Path) -> InboundPaymentInfoStorage {
9090
if let Ok(file) = File::open(path) {
91-
if let Ok(info) = PaymentInfoStorage::read(&mut BufReader::new(file)) {
91+
if let Ok(info) = InboundPaymentInfoStorage::read(&mut BufReader::new(file)) {
9292
return info;
9393
}
9494
}
95-
PaymentInfoStorage { payments: HashMap::new() }
95+
InboundPaymentInfoStorage { payments: HashMap::new() }
96+
}
97+
98+
pub(crate) fn read_outbound_payment_info(path: &Path) -> OutboundPaymentInfoStorage {
99+
if let Ok(file) = File::open(path) {
100+
if let Ok(info) = OutboundPaymentInfoStorage::read(&mut BufReader::new(file)) {
101+
return info;
102+
}
103+
}
104+
OutboundPaymentInfoStorage { payments: HashMap::new() }
96105
}
97106

98107
pub(crate) fn read_scorer(

0 commit comments

Comments
 (0)