Skip to content

Commit afb1547

Browse files
committed
Upgrade to a customized version of LDK v120
We upgrade to LDK v120 because we need the new blinded route features within. On top of that we add the changes in a small PR we submitted, which we need in order to send an onion message across along a specified path for LNDK's integration tests: lightningdevkit/rust-lightning#2868
1 parent 1624431 commit afb1547

File tree

10 files changed

+298
-164
lines changed

10 files changed

+298
-164
lines changed

Cargo.lock

Lines changed: 199 additions & 88 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,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 = { git = "https://github.com/orbitalturtle/rust-lightning", branch = "v0.0.118-custom", features = ["max_level_trace"] }
12-
lightning-block-sync = { git = "https://github.com/orbitalturtle/rust-lightning", branch = "v0.0.118-custom", features = [ "rpc-client", "tokio" ] }
11+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "06f9dd7", features = ["max_level_trace", "_test_utils"] }
12+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "06f9dd7", features = [ "rpc-client", "tokio" ] }
1313
lightning-invoice = { version = "0.25.0" }
14-
lightning-net-tokio = { git = "https://github.com/orbitalturtle/rust-lightning", branch = "v0.0.118-custom" }
15-
lightning-persister = { git = "https://github.com/orbitalturtle/rust-lightning", branch = "v0.0.118-custom" }
16-
lightning-background-processor = { git = "https://github.com/orbitalturtle/rust-lightning", branch = "v0.0.118-custom", features = [ "futures" ] }
17-
lightning-rapid-gossip-sync = { git = "https://github.com/orbitalturtle/rust-lightning", branch = "v0.0.118-custom" }
14+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "06f9dd7" }
15+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "06f9dd7" }
16+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "06f9dd7", features = [ "futures" ] }
17+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "06f9dd7" }
1818

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

src/bitcoind_client.rs

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ use crate::convert::{
55
use crate::disk::FilesystemLogger;
66
use crate::hex_utils;
77
use base64;
8+
use bitcoin::address::{Address, Payload, WitnessVersion};
89
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
10+
use bitcoin::blockdata::script::ScriptBuf;
911
use bitcoin::blockdata::transaction::Transaction;
1012
use bitcoin::consensus::{encode, Decodable, Encodable};
1113
use bitcoin::hash_types::{BlockHash, Txid};
1214
use bitcoin::hashes::Hash;
13-
use bitcoin::util::address::{Address, Payload, WitnessVersion};
14-
use bitcoin::{OutPoint, Script, TxOut, WPubkeyHash, XOnlyPublicKey};
15+
use bitcoin::key::XOnlyPublicKey;
16+
use bitcoin::psbt::PartiallySignedTransaction;
17+
use bitcoin::{Network, OutPoint, TxOut, WPubkeyHash};
1518
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
1619
use lightning::events::bump_transaction::{Utxo, WalletSource};
1720
use lightning::log_error;
@@ -28,6 +31,7 @@ use std::time::Duration;
2831

2932
pub struct BitcoindClient {
3033
pub(crate) bitcoind_rpc_client: Arc<RpcClient>,
34+
network: Network,
3135
host: String,
3236
port: u16,
3337
rpc_user: String,
@@ -60,7 +64,7 @@ const MIN_FEERATE: u32 = 253;
6064

6165
impl BitcoindClient {
6266
pub(crate) async fn new(
63-
host: String, port: u16, rpc_user: String, rpc_password: String,
67+
host: String, port: u16, rpc_user: String, rpc_password: String, network: Network,
6468
handle: tokio::runtime::Handle, logger: Arc<FilesystemLogger>,
6569
) -> std::io::Result<Self> {
6670
let http_endpoint = HttpEndpoint::for_host(host.clone()).with_port(port);
@@ -76,10 +80,6 @@ impl BitcoindClient {
7680
})?;
7781
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::new();
7882
fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
79-
fees.insert(
80-
ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
81-
AtomicU32::new(25 * 250),
82-
);
8383
fees.insert(
8484
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
8585
AtomicU32::new(MIN_FEERATE),
@@ -98,6 +98,7 @@ impl BitcoindClient {
9898
port,
9999
rpc_user,
100100
rpc_password,
101+
network,
101102
fees: Arc::new(fees),
102103
handle: handle.clone(),
103104
logger,
@@ -178,9 +179,6 @@ impl BitcoindClient {
178179
fees.get(&ConfirmationTarget::OnChainSweep)
179180
.unwrap()
180181
.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);
184182
fees.get(&ConfirmationTarget::MinAllowedAnchorChannelRemoteFee)
185183
.unwrap()
186184
.store(mempoolmin_estimate, Ordering::Release);
@@ -264,7 +262,7 @@ impl BitcoindClient {
264262
.call_method::<NewAddress>("getnewaddress", &addr_args)
265263
.await
266264
.unwrap();
267-
Address::from_str(addr.0.as_str()).unwrap()
265+
Address::from_str(addr.0.as_str()).unwrap().require_network(self.network).unwrap()
268266
}
269267

270268
pub async fn get_blockchain_info(&self) -> BlockchainInfo {
@@ -328,23 +326,38 @@ impl WalletSource for BitcoindClient {
328326
.into_iter()
329327
.filter_map(|utxo| {
330328
let outpoint = OutPoint { txid: utxo.txid, vout: utxo.vout };
331-
match utxo.address.payload {
332-
Payload::WitnessProgram { version, ref program } => match version {
333-
WitnessVersion::V0 => WPubkeyHash::from_slice(program)
334-
.map(|wpkh| Utxo::new_v0_p2wpkh(outpoint, utxo.amount, &wpkh))
335-
.ok(),
329+
match utxo.address.payload.clone() {
330+
Payload::WitnessProgram(wp) => match wp.version() {
331+
WitnessVersion::V0 => {
332+
bitcoin::hashes::hash160::Hash::from_slice(wp.program().as_bytes())
333+
.map(|hash| {
334+
Utxo::new_v0_p2wpkh(
335+
outpoint,
336+
utxo.amount,
337+
&WPubkeyHash::from_raw_hash(hash),
338+
)
339+
})
340+
.ok()
341+
}
336342
// TODO: Add `Utxo::new_v1_p2tr` upstream.
337-
WitnessVersion::V1 => XOnlyPublicKey::from_slice(program)
338-
.map(|_| Utxo {
339-
outpoint,
340-
output: TxOut {
341-
value: utxo.amount,
342-
script_pubkey: Script::new_witness_program(version, program),
343-
},
344-
satisfaction_weight: 1 /* empty script_sig */ * WITNESS_SCALE_FACTOR as u64 +
345-
1 /* witness items */ + 1 /* schnorr sig len */ + 64, /* schnorr sig */
346-
})
347-
.ok(),
343+
WitnessVersion::V1 => {
344+
bitcoin::hashes::hash160::Hash::from_slice(wp.program().as_bytes())
345+
.map(|wp_hash| {
346+
let _pubkey =
347+
XOnlyPublicKey::from_slice(wp_hash.as_byte_array())
348+
.expect("Invalid pubkey length");
349+
Utxo {
350+
outpoint,
351+
output: TxOut {
352+
value: utxo.amount,
353+
script_pubkey: ScriptBuf::new_witness_program(&wp),
354+
},
355+
satisfaction_weight: 1 /* empty script_sig */ * WITNESS_SCALE_FACTOR as u64 +
356+
1 /* witness items */ + 1 /* schnorr sig len */ + 64, /* schnorr sig */
357+
}
358+
})
359+
.ok()
360+
}
348361
_ => None,
349362
},
350363
_ => None,
@@ -353,15 +366,15 @@ impl WalletSource for BitcoindClient {
353366
.collect())
354367
}
355368

356-
fn get_change_script(&self) -> Result<Script, ()> {
369+
fn get_change_script(&self) -> Result<ScriptBuf, ()> {
357370
tokio::task::block_in_place(move || {
358371
Ok(self.handle.block_on(async move { self.get_new_address().await.script_pubkey() }))
359372
})
360373
}
361374

362-
fn sign_tx(&self, tx: Transaction) -> Result<Transaction, ()> {
375+
fn sign_psbt(&self, tx: PartiallySignedTransaction) -> Result<Transaction, ()> {
363376
let mut tx_bytes = Vec::new();
364-
let _ = tx.consensus_encode(&mut tx_bytes).map_err(|_| ());
377+
let _ = tx.unsigned_tx.consensus_encode(&mut tx_bytes).map_err(|_| ());
365378
let tx_hex = hex_utils::hex_str(&tx_bytes);
366379
let signed_tx = tokio::task::block_in_place(move || {
367380
self.handle.block_on(async move { self.sign_raw_transaction_with_wallet(tx_hex).await })

src/cli.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use lightning::sign::{EntropySource, KeysManager};
1919
use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
2020
use lightning::util::persist::KVStore;
2121
use lightning::util::ser::{Writeable, Writer};
22-
use lightning_invoice::payment::pay_invoice;
2322
use lightning_invoice::{utils, Bolt11Invoice, Currency};
2423
use lightning_persister::fs_store::FilesystemStore;
2524
use std::env;
@@ -43,6 +42,7 @@ pub(crate) struct LdkUserInfo {
4342
pub(crate) network: Network,
4443
}
4544

45+
#[derive(Debug)]
4646
struct UserOnionMessageContents {
4747
tlv_type: u64,
4848
data: Vec<u8>,
@@ -672,7 +672,7 @@ fn open_channel(
672672
..Default::default()
673673
};
674674

675-
match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, Some(config)) {
675+
match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, None, Some(config)) {
676676
Ok(_) => {
677677
println!("EVENT: initiated channel with peer {}. ", peer_pubkey);
678678
return Ok(());
@@ -688,7 +688,8 @@ fn send_payment(
688688
channel_manager: &ChannelManager, invoice: &Bolt11Invoice,
689689
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
690690
) {
691-
let payment_id = PaymentId((*invoice.payment_hash()).into_inner());
691+
let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array());
692+
let payment_hash = PaymentHash((*invoice.payment_hash()).to_byte_array());
692693
let payment_secret = Some(*invoice.payment_secret());
693694
outbound_payments.payments.insert(
694695
payment_id,
@@ -700,8 +701,20 @@ fn send_payment(
700701
},
701702
);
702703
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
703-
match pay_invoice(invoice, Retry::Timeout(Duration::from_secs(10)), channel_manager) {
704-
Ok(_payment_id) => {
704+
705+
let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());
706+
recipient_onion.payment_metadata = invoice.payment_metadata().map(|v| v.clone());
707+
let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
708+
invoice.min_final_cltv_expiry_delta() as u32)
709+
.with_expiry_time(invoice.duration_since_epoch().as_secs() + invoice.expiry_time().as_secs())
710+
.with_route_hints(invoice.route_hints()).unwrap();
711+
if let Some(features) = invoice.features() {
712+
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
713+
}
714+
let route_params = RouteParameters::from_payment_params_and_value(payment_params, invoice.amount_milli_satoshis().unwrap_or_default());
715+
716+
match channel_manager.send_payment(payment_hash, recipient_onion, payment_id, route_params, Retry::Timeout(Duration::from_secs(10))) {
717+
Ok(_) => {
705718
let payee_pubkey = invoice.recover_payee_pub_key();
706719
let amt_msat = invoice.amount_milli_satoshis().unwrap();
707720
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
@@ -721,7 +734,7 @@ fn keysend<E: EntropySource>(
721734
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
722735
) {
723736
let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
724-
let payment_id = PaymentId(Sha256::hash(&payment_preimage.0[..]).into_inner());
737+
let payment_id = PaymentId(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
725738

726739
let route_params = RouteParameters::from_payment_params_and_value(
727740
PaymentParameters::for_keysend(payee_pubkey, 40, false),
@@ -764,9 +777,9 @@ fn get_invoice(
764777
) {
765778
let currency = match network {
766779
Network::Bitcoin => Currency::Bitcoin,
767-
Network::Testnet => Currency::BitcoinTestnet,
768780
Network::Regtest => Currency::Regtest,
769781
Network::Signet => Currency::Signet,
782+
Network::Testnet | _ => Currency::BitcoinTestnet,
770783
};
771784
let invoice = match utils::create_invoice_from_channelmanager(
772785
channel_manager,
@@ -788,7 +801,7 @@ fn get_invoice(
788801
}
789802
};
790803

791-
let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
804+
let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());
792805
inbound_payments.payments.insert(
793806
payment_hash,
794807
PaymentInfo {

src/convert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitcoin::hashes::hex::FromHex;
1+
use bitcoin::address::NetworkUnchecked;
22
use bitcoin::{Address, BlockHash, Txid};
33
use lightning_block_sync::http::JsonResponse;
44
use std::convert::TryInto;
@@ -111,7 +111,7 @@ impl TryInto<BlockchainInfo> for JsonResponse {
111111
fn try_into(self) -> std::io::Result<BlockchainInfo> {
112112
Ok(BlockchainInfo {
113113
latest_height: self.0["blocks"].as_u64().unwrap() as usize,
114-
latest_blockhash: BlockHash::from_hex(self.0["bestblockhash"].as_str().unwrap())
114+
latest_blockhash: BlockHash::from_str(self.0["bestblockhash"].as_str().unwrap())
115115
.unwrap(),
116116
chain: self.0["chain"].as_str().unwrap().to_string(),
117117
})
@@ -122,7 +122,7 @@ pub struct ListUnspentUtxo {
122122
pub txid: Txid,
123123
pub vout: u32,
124124
pub amount: u64,
125-
pub address: Address,
125+
pub address: Address<NetworkUnchecked>,
126126
}
127127

128128
pub struct ListUnspentResponse(pub Vec<ListUnspentUtxo>);

src/disk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl FilesystemLogger {
2929
}
3030
}
3131
impl Logger for FilesystemLogger {
32-
fn log(&self, record: &Record) {
32+
fn log(&self, record: Record) {
3333
if record.level < self.level {
3434
return;
3535
}

0 commit comments

Comments
 (0)