Skip to content

Commit 8098135

Browse files
committed
Upgrade to LDK 0.0.116
1 parent 139e065 commit 8098135

File tree

8 files changed

+131
-64
lines changed

8 files changed

+131
-64
lines changed

Cargo.lock

Lines changed: 14 additions & 14 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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ 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.115", features = ["max_level_trace"] }
12-
lightning-block-sync = { version = "0.0.115", features = [ "rpc-client" ] }
13-
lightning-invoice = { version = "0.23" }
14-
lightning-net-tokio = { version = "0.0.115" }
15-
lightning-persister = { version = "0.0.115" }
16-
lightning-background-processor = { version = "0.0.115", features = [ "futures" ] }
17-
lightning-rapid-gossip-sync = { version = "0.0.115" }
11+
lightning = { version = "0.0.116", features = ["max_level_trace"] }
12+
lightning-block-sync = { version = "0.0.116", features = [ "rpc-client" ] }
13+
lightning-invoice = { version = "0.24.0" }
14+
lightning-net-tokio = { version = "0.0.116" }
15+
lightning-persister = { version = "0.0.116" }
16+
lightning-background-processor = { version = "0.0.116", features = [ "futures" ] }
17+
lightning-rapid-gossip-sync = { version = "0.0.116" }
1818

1919
base64 = "0.13.0"
2020
bitcoin = "0.29.0"

src/bitcoind_client.rs

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::convert::{BlockchainInfo, FeeResponse, FundedTx, NewAddress, RawTx, SignedTx};
1+
use crate::convert::{
2+
BlockchainInfo, FeeResponse, FundedTx, MempoolMinFeeResponse, NewAddress, RawTx, SignedTx,
3+
};
24
use crate::disk::FilesystemLogger;
35
use base64;
46
use bitcoin::blockdata::transaction::Transaction;
@@ -32,6 +34,7 @@ pub struct BitcoindClient {
3234

3335
#[derive(Clone, Eq, Hash, PartialEq)]
3436
pub enum Target {
37+
MempoolMinimum,
3538
Background,
3639
Normal,
3740
HighPriority,
@@ -75,6 +78,7 @@ impl BitcoindClient {
7578
"Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
7679
})?;
7780
let mut fees: HashMap<Target, AtomicU32> = HashMap::new();
81+
fees.insert(Target::MempoolMinimum, AtomicU32::new(MIN_FEERATE));
7882
fees.insert(Target::Background, AtomicU32::new(MIN_FEERATE));
7983
fees.insert(Target::Normal, AtomicU32::new(2000));
8084
fees.insert(Target::HighPriority, AtomicU32::new(5000));
@@ -102,6 +106,16 @@ impl BitcoindClient {
102106
) {
103107
handle.spawn(async move {
104108
loop {
109+
let mempoolmin_estimate = {
110+
let resp = rpc_client
111+
.call_method::<MempoolMinFeeResponse>("getmempoolinfo", &vec![])
112+
.await
113+
.unwrap();
114+
match resp.feerate_sat_per_kw {
115+
Some(feerate) => std::cmp::max(feerate, MIN_FEERATE),
116+
None => MIN_FEERATE,
117+
}
118+
};
105119
let background_estimate = {
106120
let background_conf_target = serde_json::json!(144);
107121
let background_estimate_mode = serde_json::json!("ECONOMICAL");
@@ -151,6 +165,9 @@ impl BitcoindClient {
151165
}
152166
};
153167

168+
fees.get(&Target::MempoolMinimum)
169+
.unwrap()
170+
.store(mempoolmin_estimate, Ordering::Release);
154171
fees.get(&Target::Background)
155172
.unwrap()
156173
.store(background_estimate, Ordering::Release);
@@ -238,6 +255,9 @@ impl BitcoindClient {
238255
impl FeeEstimator for BitcoindClient {
239256
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
240257
match confirmation_target {
258+
ConfirmationTarget::MempoolMinimum => {
259+
self.fees.get(&Target::MempoolMinimum).unwrap().load(Ordering::Acquire)
260+
}
241261
ConfirmationTarget::Background => {
242262
self.fees.get(&Target::Background).unwrap().load(Ordering::Acquire)
243263
}
@@ -252,29 +272,33 @@ impl FeeEstimator for BitcoindClient {
252272
}
253273

254274
impl BroadcasterInterface for BitcoindClient {
255-
fn broadcast_transaction(&self, tx: &Transaction) {
256-
let bitcoind_rpc_client = self.bitcoind_rpc_client.clone();
257-
let tx_serialized = encode::serialize_hex(tx);
258-
let tx_json = serde_json::json!(tx_serialized);
259-
let logger = Arc::clone(&self.logger);
260-
self.handle.spawn(async move {
261-
// This may error due to RL calling `broadcast_transaction` with the same transaction
262-
// multiple times, but the error is safe to ignore.
263-
match bitcoind_rpc_client
264-
.call_method::<Txid>("sendrawtransaction", &vec![tx_json])
265-
.await
266-
{
267-
Ok(_) => {}
268-
Err(e) => {
269-
let err_str = e.get_ref().unwrap().to_string();
270-
log_error!(logger,
271-
"Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\nTransaction: {}",
272-
err_str,
273-
tx_serialized);
274-
print!("Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n> ", err_str);
275-
}
276-
}
277-
});
275+
fn broadcast_transactions(&self, txs: &[&Transaction]) {
276+
// TODO: Rather than calling `sendrawtransaction` in a a loop, we should probably use
277+
// `submitpackage` once it becomes available.
278+
for tx in txs {
279+
let bitcoind_rpc_client = Arc::clone(&self.bitcoind_rpc_client);
280+
let tx_serialized = encode::serialize_hex(tx);
281+
let tx_json = serde_json::json!(tx_serialized);
282+
let logger = Arc::clone(&self.logger);
283+
self.handle.spawn(async move {
284+
// This may error due to RL calling `broadcast_transactions` with the same transaction
285+
// multiple times, but the error is safe to ignore.
286+
match bitcoind_rpc_client
287+
.call_method::<Txid>("sendrawtransaction", &vec![tx_json])
288+
.await
289+
{
290+
Ok(_) => {}
291+
Err(e) => {
292+
let err_str = e.get_ref().unwrap().to_string();
293+
log_error!(logger,
294+
"Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\nTransaction: {}",
295+
err_str,
296+
tx_serialized);
297+
print!("Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: {}\n> ", err_str);
298+
}
299+
}
300+
});
301+
}
278302
}
279303
}
280304

src/cli.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ use bitcoin::hashes::sha256::Hash as Sha256;
88
use bitcoin::hashes::Hash;
99
use bitcoin::network::constants::Network;
1010
use bitcoin::secp256k1::PublicKey;
11-
use lightning::chain::keysinterface::{EntropySource, KeysManager};
1211
use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
1312
use lightning::ln::msgs::NetAddress;
1413
use lightning::ln::{PaymentHash, PaymentPreimage};
14+
use lightning::onion_message::OnionMessagePath;
1515
use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents};
1616
use lightning::routing::gossip::NodeId;
1717
use lightning::routing::router::{PaymentParameters, RouteParameters};
18+
use lightning::sign::{EntropySource, KeysManager};
1819
use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
1920
use lightning::util::persist::KVStorePersister;
2021
use lightning::util::ser::{Writeable, Writer};
2122
use lightning_invoice::payment::pay_invoice;
22-
use lightning_invoice::{utils, Currency, Invoice};
23+
use lightning_invoice::{utils, Bolt11Invoice, Currency};
2324
use lightning_persister::FilesystemPersister;
2425
use std::env;
2526
use std::io;
@@ -150,7 +151,7 @@ pub(crate) async fn poll_for_user_input(
150151
continue;
151152
}
152153

153-
let invoice = match Invoice::from_str(invoice_str.unwrap()) {
154+
let invoice = match Bolt11Invoice::from_str(invoice_str.unwrap()) {
154155
Ok(inv) => inv,
155156
Err(e) => {
156157
println!("ERROR: invalid invoice: {:?}", e);
@@ -387,7 +388,7 @@ pub(crate) async fn poll_for_user_input(
387388
);
388389
continue;
389390
}
390-
let mut node_pks = Vec::new();
391+
let mut intermediate_nodes = Vec::new();
391392
let mut errored = false;
392393
for pk_str in path_pks_str.unwrap().split(",") {
393394
let node_pubkey_vec = match hex_utils::to_vec(pk_str) {
@@ -406,7 +407,7 @@ pub(crate) async fn poll_for_user_input(
406407
break;
407408
}
408409
};
409-
node_pks.push(node_pubkey);
410+
intermediate_nodes.push(node_pubkey);
410411
}
411412
if errored {
412413
continue;
@@ -425,10 +426,10 @@ pub(crate) async fn poll_for_user_input(
425426
continue;
426427
}
427428
};
428-
let destination_pk = node_pks.pop().unwrap();
429+
let destination = Destination::Node(intermediate_nodes.pop().unwrap());
430+
let message_path = OnionMessagePath { intermediate_nodes, destination };
429431
match onion_messenger.send_onion_message(
430-
&node_pks,
431-
Destination::Node(destination_pk),
432+
message_path,
432433
OnionMessageContents::Custom(UserOnionMessageContents { tlv_type, data }),
433434
None,
434435
) {
@@ -666,7 +667,7 @@ fn open_channel(
666667
}
667668

668669
fn send_payment(
669-
channel_manager: &ChannelManager, invoice: &Invoice,
670+
channel_manager: &ChannelManager, invoice: &Bolt11Invoice,
670671
outbound_payments: &mut PaymentInfoStorage, persister: Arc<FilesystemPersister>,
671672
) {
672673
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
@@ -705,7 +706,7 @@ fn keysend<E: EntropySource>(
705706
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
706707

707708
let route_params = RouteParameters {
708-
payment_params: PaymentParameters::for_keysend(payee_pubkey, 40),
709+
payment_params: PaymentParameters::for_keysend(payee_pubkey, 40, false),
709710
final_value_msat: amt_msat,
710711
};
711712
outbound_payments.payments.insert(

src/convert.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ impl TryInto<FeeResponse> for JsonResponse {
7474
}
7575
}
7676

77+
pub struct MempoolMinFeeResponse {
78+
pub feerate_sat_per_kw: Option<u32>,
79+
pub errored: bool,
80+
}
81+
82+
impl TryInto<MempoolMinFeeResponse> for JsonResponse {
83+
type Error = std::io::Error;
84+
fn try_into(self) -> std::io::Result<MempoolMinFeeResponse> {
85+
let errored = !self.0["errors"].is_null();
86+
assert_eq!(self.0["maxmempool"].as_u64(), Some(300000000));
87+
Ok(MempoolMinFeeResponse {
88+
errored,
89+
feerate_sat_per_kw: match self.0["mempoolminfee"].as_f64() {
90+
// Bitcoin Core gives us a feerate in BTC/KvB, which we need to convert to
91+
// satoshis/KW. Thus, we first multiply by 10^8 to get satoshis, then divide by 4
92+
// to convert virtual-bytes into weight units.
93+
Some(feerate_btc_per_kvbyte) => {
94+
Some((feerate_btc_per_kvbyte * 100_000_000.0 / 4.0).round() as u32)
95+
}
96+
None => None,
97+
},
98+
})
99+
}
100+
}
101+
77102
pub struct BlockchainInfo {
78103
pub latest_height: usize,
79104
pub latest_blockhash: BlockHash,

src/disk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{cli, NetworkGraph, PaymentInfoStorage};
22
use bitcoin::secp256k1::PublicKey;
33
use bitcoin::Network;
44
use chrono::Utc;
5-
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
5+
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringDecayParameters};
66
use lightning::util::logger::{Logger, Record};
77
use lightning::util::ser::{Readable, ReadableArgs, Writer};
88
use std::collections::HashMap;
@@ -98,7 +98,7 @@ pub(crate) fn read_payment_info(path: &Path) -> PaymentInfoStorage {
9898
pub(crate) fn read_scorer(
9999
path: &Path, graph: Arc<NetworkGraph>, logger: Arc<FilesystemLogger>,
100100
) -> ProbabilisticScorer<Arc<NetworkGraph>, Arc<FilesystemLogger>> {
101-
let params = ProbabilisticScoringParameters::default();
101+
let params = ProbabilisticScoringDecayParameters::default();
102102
if let Ok(file) = File::open(path) {
103103
let args = (params.clone(), Arc::clone(&graph), Arc::clone(&logger));
104104
if let Ok(scorer) = ProbabilisticScorer::read(&mut BufReader::new(file), args) {

0 commit comments

Comments
 (0)