Skip to content

Commit 9e6de1b

Browse files
committed
Upgrade to LDK 0.0.124/rust-bitcoin 0.32
1 parent 6d171e0 commit 9e6de1b

File tree

7 files changed

+145
-108
lines changed

7 files changed

+145
-108
lines changed

Cargo.toml

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

1919
base64 = "0.13.0"
20-
bitcoin = "0.30.2"
20+
bitcoin = "0.32"
2121
bitcoin-bech32 = "0.12"
2222
bech32 = "0.8"
2323
libc = "0.2"

src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::cli::LdkUserInfo;
2-
use bitcoin::network::constants::Network;
2+
use bitcoin::network::Network;
33
use lightning::ln::msgs::SocketAddress;
44
use std::collections::HashMap;
55
use std::env;

src/bitcoind_client.rs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use crate::convert::{
55
use crate::disk::FilesystemLogger;
66
use crate::hex_utils;
77
use base64;
8-
use bitcoin::address::{Address, Payload, WitnessVersion};
8+
use bitcoin::address::Address;
99
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
1010
use bitcoin::blockdata::script::ScriptBuf;
1111
use bitcoin::blockdata::transaction::Transaction;
1212
use bitcoin::consensus::{encode, Decodable, Encodable};
1313
use bitcoin::hash_types::{BlockHash, Txid};
1414
use bitcoin::hashes::Hash;
1515
use bitcoin::key::XOnlyPublicKey;
16-
use bitcoin::psbt::PartiallySignedTransaction;
16+
use bitcoin::psbt::Psbt;
1717
use bitcoin::{Network, OutPoint, TxOut, WPubkeyHash};
1818
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
1919
use lightning::events::bump_transaction::{Utxo, WalletSource};
@@ -80,7 +80,8 @@ impl BitcoindClient {
8080
"Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
8181
})?;
8282
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::new();
83-
fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
83+
fees.insert(ConfirmationTarget::MaximumFeeEstimate, AtomicU32::new(50000));
84+
fees.insert(ConfirmationTarget::UrgentOnChainSweep, AtomicU32::new(5000));
8485
fees.insert(
8586
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
8687
AtomicU32::new(MIN_FEERATE),
@@ -92,6 +93,7 @@ impl BitcoindClient {
9293
fees.insert(ConfirmationTarget::AnchorChannelFee, AtomicU32::new(MIN_FEERATE));
9394
fees.insert(ConfirmationTarget::NonAnchorChannelFee, AtomicU32::new(2000));
9495
fees.insert(ConfirmationTarget::ChannelCloseMinimum, AtomicU32::new(MIN_FEERATE));
96+
fees.insert(ConfirmationTarget::OutputSpendingFee, AtomicU32::new(MIN_FEERATE));
9597

9698
let client = Self {
9799
bitcoind_rpc_client: Arc::new(bitcoind_rpc_client),
@@ -177,7 +179,27 @@ impl BitcoindClient {
177179
}
178180
};
179181

180-
fees.get(&ConfirmationTarget::OnChainSweep)
182+
let very_high_prio_estimate = {
183+
let high_prio_conf_target = serde_json::json!(2);
184+
let high_prio_estimate_mode = serde_json::json!("CONSERVATIVE");
185+
let resp = rpc_client
186+
.call_method::<FeeResponse>(
187+
"estimatesmartfee",
188+
&vec![high_prio_conf_target, high_prio_estimate_mode],
189+
)
190+
.await
191+
.unwrap();
192+
193+
match resp.feerate_sat_per_kw {
194+
Some(feerate) => std::cmp::max(feerate, MIN_FEERATE),
195+
None => 50000,
196+
}
197+
};
198+
199+
fees.get(&ConfirmationTarget::MaximumFeeEstimate)
200+
.unwrap()
201+
.store(very_high_prio_estimate, Ordering::Release);
202+
fees.get(&ConfirmationTarget::UrgentOnChainSweep)
181203
.unwrap()
182204
.store(high_prio_estimate, Ordering::Release);
183205
fees.get(&ConfirmationTarget::MinAllowedAnchorChannelRemoteFee)
@@ -195,6 +217,9 @@ impl BitcoindClient {
195217
fees.get(&ConfirmationTarget::ChannelCloseMinimum)
196218
.unwrap()
197219
.store(background_estimate, Ordering::Release);
220+
fees.get(&ConfirmationTarget::OutputSpendingFee)
221+
.unwrap()
222+
.store(background_estimate, Ordering::Release);
198223

199224
tokio::time::sleep(Duration::from_secs(60)).await;
200225
}
@@ -335,24 +360,26 @@ impl WalletSource for BitcoindClient {
335360
.into_iter()
336361
.filter_map(|utxo| {
337362
let outpoint = OutPoint { txid: utxo.txid, vout: utxo.vout };
338-
match utxo.address.payload.clone() {
339-
Payload::WitnessProgram(wp) => match wp.version() {
340-
WitnessVersion::V0 => WPubkeyHash::from_slice(wp.program().as_bytes())
341-
.map(|wpkh| Utxo::new_v0_p2wpkh(outpoint, utxo.amount, &wpkh))
342-
.ok(),
363+
let value = bitcoin::Amount::from_sat(utxo.amount);
364+
match utxo.address.witness_program() {
365+
Some(prog) if prog.is_p2wpkh() => {
366+
WPubkeyHash::from_slice(prog.program().as_bytes())
367+
.map(|wpkh| Utxo::new_v0_p2wpkh(outpoint, value, &wpkh))
368+
.ok()
369+
},
370+
Some(prog) if prog.is_p2tr() => {
343371
// TODO: Add `Utxo::new_v1_p2tr` upstream.
344-
WitnessVersion::V1 => XOnlyPublicKey::from_slice(wp.program().as_bytes())
372+
XOnlyPublicKey::from_slice(prog.program().as_bytes())
345373
.map(|_| Utxo {
346374
outpoint,
347375
output: TxOut {
348-
value: utxo.amount,
349-
script_pubkey: ScriptBuf::new_witness_program(&wp),
376+
value,
377+
script_pubkey: utxo.address.script_pubkey(),
350378
},
351379
satisfaction_weight: 1 /* empty script_sig */ * WITNESS_SCALE_FACTOR as u64 +
352380
1 /* witness items */ + 1 /* schnorr sig len */ + 64, /* schnorr sig */
353381
})
354-
.ok(),
355-
_ => None,
382+
.ok()
356383
},
357384
_ => None,
358385
}
@@ -366,7 +393,7 @@ impl WalletSource for BitcoindClient {
366393
})
367394
}
368395

369-
fn sign_psbt(&self, tx: PartiallySignedTransaction) -> Result<Transaction, ()> {
396+
fn sign_psbt(&self, tx: Psbt) -> Result<Transaction, ()> {
370397
let mut tx_bytes = Vec::new();
371398
let _ = tx.unsigned_tx.consensus_encode(&mut tx_bytes).map_err(|_| ());
372399
let tx_hex = hex_utils::hex_str(&tx_bytes);

src/cli.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@ use crate::disk::{self, INBOUND_PAYMENTS_FNAME, OUTBOUND_PAYMENTS_FNAME};
22
use crate::hex_utils;
33
use crate::{
44
ChannelManager, HTLCStatus, InboundPaymentInfoStorage, MillisatAmount, NetworkGraph,
5-
OnionMessenger, OutboundPaymentInfoStorage, PaymentInfo, PeerManager,
5+
OutboundPaymentInfoStorage, PaymentInfo, PeerManager,
66
};
77
use bitcoin::hashes::sha256::Hash as Sha256;
88
use bitcoin::hashes::Hash;
9-
use bitcoin::network::constants::Network;
9+
use bitcoin::network::Network;
1010
use bitcoin::secp256k1::PublicKey;
11+
use lightning::ln::bolt11_payment::payment_parameters_from_invoice;
12+
use lightning::ln::bolt11_payment::payment_parameters_from_zero_amount_invoice;
1113
use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
14+
use lightning::ln::invoice_utils as utils;
1215
use lightning::ln::msgs::SocketAddress;
13-
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
16+
use lightning::ln::types::ChannelId;
1417
use lightning::offers::offer::{self, Offer};
1518
use lightning::routing::gossip::NodeId;
1619
use lightning::routing::router::{PaymentParameters, RouteParameters};
1720
use lightning::sign::{EntropySource, KeysManager};
21+
use lightning::types::payment::{PaymentHash, PaymentPreimage};
1822
use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
1923
use lightning::util::persist::KVStore;
20-
use lightning::util::ser::{Writeable, Writer};
21-
use lightning_invoice::payment::payment_parameters_from_invoice;
22-
use lightning_invoice::payment::payment_parameters_from_zero_amount_invoice;
23-
use lightning_invoice::{utils, Bolt11Invoice, Currency};
24+
use lightning::util::ser::Writeable;
25+
use lightning_invoice::{Bolt11Invoice, Currency};
2426
use lightning_persister::fs_store::FilesystemStore;
2527
use std::env;
26-
use std::io;
2728
use std::io::Write;
2829
use std::net::{SocketAddr, ToSocketAddrs};
2930
use std::path::Path;
@@ -46,7 +47,7 @@ pub(crate) struct LdkUserInfo {
4647
pub(crate) fn poll_for_user_input(
4748
peer_manager: Arc<PeerManager>, channel_manager: Arc<ChannelManager>,
4849
keys_manager: Arc<KeysManager>, network_graph: Arc<NetworkGraph>,
49-
onion_messenger: Arc<OnionMessenger>, inbound_payments: Arc<Mutex<InboundPaymentInfoStorage>>,
50+
inbound_payments: Arc<Mutex<InboundPaymentInfoStorage>>,
5051
outbound_payments: Arc<Mutex<OutboundPaymentInfoStorage>>, ldk_data_dir: String,
5152
network: Network, logger: Arc<disk::FilesystemLogger>, fs_store: Arc<FilesystemStore>,
5253
) {
@@ -57,9 +58,9 @@ pub(crate) fn poll_for_user_input(
5758
println!("Local Node ID is {}.", channel_manager.get_our_node_id());
5859
'read_command: loop {
5960
print!("> ");
60-
io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print
61+
std::io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print
6162
let mut line = String::new();
62-
if let Err(e) = io::stdin().read_line(&mut line) {
63+
if let Err(e) = std::io::stdin().read_line(&mut line) {
6364
break println!("ERROR: {}", e);
6465
}
6566

@@ -159,7 +160,7 @@ pub(crate) fn poll_for_user_input(
159160
let payment_id = PaymentId(random_bytes);
160161

161162
let amt_msat = match (offer.amount(), user_provided_amt) {
162-
(Some(offer::Amount::Bitcoin { amount_msats }), _) => *amount_msats,
163+
(Some(offer::Amount::Bitcoin { amount_msats }), _) => amount_msats,
163164
(_, Some(amt)) => amt,
164165
(amt, _) => {
165166
println!("ERROR: Cannot process non-Bitcoin-denominated offer value {:?}", amt);
@@ -173,9 +174,9 @@ pub(crate) fn poll_for_user_input(
173174

174175
while user_provided_amt.is_none() {
175176
print!("Paying offer for {} msat. Continue (Y/N)? >", amt_msat);
176-
io::stdout().flush().unwrap();
177+
std::io::stdout().flush().unwrap();
177178

178-
if let Err(e) = io::stdin().read_line(&mut line) {
179+
if let Err(e) = std::io::stdin().read_line(&mut line) {
179180
println!("ERROR: {}", e);
180181
break 'read_command;
181182
}
@@ -266,7 +267,7 @@ pub(crate) fn poll_for_user_input(
266267
);
267268
},
268269
"getoffer" => {
269-
let offer_builder = channel_manager.create_offer_builder();
270+
let offer_builder = channel_manager.create_offer_builder(None);
270271
if let Err(e) = offer_builder {
271272
println!("ERROR: Failed to initiate offer building: {:?}", e);
272273
continue;
@@ -554,7 +555,7 @@ fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<Netw
554555
.get(&NodeId::from_pubkey(&chan_info.counterparty.node_id))
555556
{
556557
if let Some(announcement) = &node_info.announcement_info {
557-
println!("\t\tpeer_alias: {}", announcement.alias);
558+
println!("\t\tpeer_alias: {}", announcement.alias());
558559
}
559560
}
560561

@@ -569,7 +570,7 @@ fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<Netw
569570
println!("\t\tavailable_balance_for_recv_msat: {},", chan_info.inbound_capacity_msat);
570571
}
571572
println!("\t\tchannel_can_send_payments: {},", chan_info.is_usable);
572-
println!("\t\tpublic: {},", chan_info.is_public);
573+
println!("\t\tpublic: {},", chan_info.is_announced);
573574
println!("\t}},");
574575
}
575576
println!("]");
@@ -676,8 +677,8 @@ fn do_disconnect_peer(
676677
}
677678

678679
fn open_channel(
679-
peer_pubkey: PublicKey, channel_amt_sat: u64, announced_channel: bool, with_anchors: bool,
680-
channel_manager: Arc<ChannelManager>,
680+
peer_pubkey: PublicKey, channel_amt_sat: u64, announce_for_forwarding: bool,
681+
with_anchors: bool, channel_manager: Arc<ChannelManager>,
681682
) -> Result<(), ()> {
682683
let config = UserConfig {
683684
channel_handshake_limits: ChannelHandshakeLimits {
@@ -686,7 +687,7 @@ fn open_channel(
686687
..Default::default()
687688
},
688689
channel_handshake_config: ChannelHandshakeConfig {
689-
announced_channel,
690+
announce_for_forwarding,
690691
negotiate_anchors_zero_fee_htlc_tx: with_anchors,
691692
..Default::default()
692693
},
@@ -870,9 +871,11 @@ fn close_channel(
870871
fn force_close_channel(
871872
channel_id: [u8; 32], counterparty_node_id: PublicKey, channel_manager: Arc<ChannelManager>,
872873
) {
873-
match channel_manager
874-
.force_close_broadcasting_latest_txn(&ChannelId(channel_id), &counterparty_node_id)
875-
{
874+
match channel_manager.force_close_broadcasting_latest_txn(
875+
&ChannelId(channel_id),
876+
&counterparty_node_id,
877+
"Manually force-closed".to_string(),
878+
) {
876879
Ok(()) => println!("EVENT: initiating channel force-close"),
877880
Err(e) => println!("ERROR: failed to force-close channel: {:?}", e),
878881
}

src/disk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use bitcoin::Network;
44
use chrono::Utc;
55
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringDecayParameters};
66
use lightning::util::logger::{Logger, Record};
7-
use lightning::util::ser::{Readable, ReadableArgs, Writer};
7+
use lightning::util::ser::{Readable, ReadableArgs};
88
use std::collections::HashMap;
99
use std::fs;
1010
use std::fs::File;
11-
use std::io::{BufRead, BufReader};
11+
use std::io::{BufRead, BufReader, Write};
1212
use std::net::SocketAddr;
1313
use std::path::Path;
1414
use std::sync::Arc;

0 commit comments

Comments
 (0)