From 128c22e3c0e793d73cffb2000bac98732877d19f Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Thu, 28 Nov 2024 22:32:32 +0530 Subject: [PATCH 1/4] deps(lampo-common): Upgrade lightning and bitcoin lightning 0.0.123 -> 0.0.125 bitcoin 0.30 -> 0.32 --- lampo-common/Cargo.toml | 16 ++++++------ lampo-common/src/event/onchain.rs | 4 +-- lampo-common/src/keys.rs | 42 +++++++++++++++++-------------- lampo-common/src/model.rs | 1 + lampo-common/src/model/invoice.rs | 5 ++-- lampo-common/src/types.rs | 2 +- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/lampo-common/Cargo.toml b/lampo-common/Cargo.toml index b0735bcd..2f6d9f56 100644 --- a/lampo-common/Cargo.toml +++ b/lampo-common/Cargo.toml @@ -6,14 +6,14 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -lightning = { version = "0.0.123", features = ["max_level_trace"] } -lightning-block-sync = { version = "0.0.123" } -lightning-persister = { version = "0.0.123" } -lightning-background-processor = { version = "0.0.123" } -lightning-net-tokio = { version = "0.0.123" } -lightning-rapid-gossip-sync = { version = "0.0.123" } -lightning-invoice = { version = "0.31" } -bitcoin = { version = "0.30.2", features = ["serde"] } +lightning = { version = "0.0.125", features = ["max_level_trace"] } +lightning-block-sync = { version = "0.0.125" } +lightning-persister = { version = "0.0.125" } +lightning-background-processor = { version = "0.0.125" } +lightning-net-tokio = { version = "0.0.125" } +lightning-rapid-gossip-sync = { version = "0.0.125" } +lightning-invoice = { version = "0.32" } +bitcoin = { version = "0.32.0", features = ["serde"] } clightningrpc-conf = { git = "https://github.com/laanwj/cln4rust.git", branch = "master" } crossbeam-channel = "0.5.8" anyhow = "1.0.70" diff --git a/lampo-common/src/event/onchain.rs b/lampo-common/src/event/onchain.rs index e5ced5e3..48bd16cb 100644 --- a/lampo-common/src/event/onchain.rs +++ b/lampo-common/src/event/onchain.rs @@ -22,14 +22,14 @@ impl Debug for OnChainEvent { Self::ConfirmedTransaction((tx, idx, header, height)) => write!( f, "ConfirmedTransaction(txid: {}, idx {idx}, block: {:?}, height: {height})", - tx.txid(), + tx.compute_txid(), header ), Self::NewBestBlock((header, height)) => { write!(f, "NewBestBlock({}, {height})", header.block_hash()) } Self::NewBlock(block) => write!(f, "NewBlock({})", block.block_hash()), - Self::SendRawTransaction(tx) => write!(f, "SendRawTransaction({})", tx.txid()), + Self::SendRawTransaction(tx) => write!(f, "SendRawTransaction({})", tx.compute_txid()), Self::UnconfirmedTransaction(tx) => write!(f, "UnconfirmedTransaction({})", tx), _ => write!(f, "Debug fmt not unsupported"), } diff --git a/lampo-common/src/keys.rs b/lampo-common/src/keys.rs index 8f220f39..f5acf085 100644 --- a/lampo-common/src/keys.rs +++ b/lampo-common/src/keys.rs @@ -1,8 +1,10 @@ use std::{sync::Arc, time::SystemTime}; -use bitcoin::secp256k1::{Secp256k1, SecretKey}; use lightning::sign::{InMemorySigner, NodeSigner, OutputSpender, SignerProvider}; +use lightning_invoice::RawBolt11Invoice; +use crate::ldk::bitcoin::secp256k1::Secp256k1; +use crate::ldk::bitcoin::secp256k1::SecretKey; use crate::ldk::sign::{EntropySource, KeysManager}; /// Lampo keys implementations @@ -113,9 +115,9 @@ impl NodeSigner for LampoKeysManager { fn ecdh( &self, recipient: lightning::sign::Recipient, - other_key: &bitcoin::secp256k1::PublicKey, - tweak: Option<&bitcoin::secp256k1::Scalar>, - ) -> Result { + other_key: &lightning::bitcoin::secp256k1::PublicKey, + tweak: Option<&lightning::bitcoin::secp256k1::Scalar>, + ) -> Result { self.inner.ecdh(recipient, other_key, tweak) } @@ -126,51 +128,50 @@ impl NodeSigner for LampoKeysManager { fn get_node_id( &self, recipient: lightning::sign::Recipient, - ) -> Result { + ) -> Result { self.inner.get_node_id(recipient) } fn sign_bolt12_invoice( &self, invoice: &lightning::offers::invoice::UnsignedBolt12Invoice, - ) -> Result { + ) -> Result { self.inner.sign_bolt12_invoice(invoice) } fn sign_bolt12_invoice_request( &self, invoice_request: &lightning::offers::invoice_request::UnsignedInvoiceRequest, - ) -> Result { + ) -> Result { self.inner.sign_bolt12_invoice_request(invoice_request) } fn sign_gossip_message( &self, msg: lightning::ln::msgs::UnsignedGossipMessage, - ) -> Result { + ) -> Result { self.inner.sign_gossip_message(msg) } fn sign_invoice( &self, - hrp_bytes: &[u8], - invoice_data: &[bitcoin::bech32::u5], + invoice_data: &RawBolt11Invoice, recipient: lightning::sign::Recipient, - ) -> Result { - self.inner.sign_invoice(hrp_bytes, invoice_data, recipient) + ) -> Result { + self.inner.sign_invoice(invoice_data, recipient) } } impl OutputSpender for LampoKeysManager { - fn spend_spendable_outputs( + fn spend_spendable_outputs( &self, descriptors: &[&lightning::sign::SpendableOutputDescriptor], - outputs: Vec, - change_destination_script: bitcoin::ScriptBuf, + outputs: Vec, + change_destination_script: lightning::bitcoin::ScriptBuf, feerate_sat_per_1000_weight: u32, - locktime: Option, - secp_ctx: &bitcoin::secp256k1::Secp256k1, - ) -> Result { + locktime: Option, + secp_ctx: &lightning::bitcoin::secp256k1::Secp256k1, + ) -> Result { self.inner.spend_spendable_outputs( descriptors, outputs, @@ -224,7 +225,10 @@ impl SignerProvider for LampoKeysManager { .generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id) } - fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result { + fn get_destination_script( + &self, + channel_keys_id: [u8; 32], + ) -> Result { self.inner.get_destination_script(channel_keys_id) } diff --git a/lampo-common/src/model.rs b/lampo-common/src/model.rs index af5a4e63..7ec073ed 100644 --- a/lampo-common/src/model.rs +++ b/lampo-common/src/model.rs @@ -17,6 +17,7 @@ pub mod request { pub use crate::model::getinfo::*; pub use crate::model::invoice::request::*; pub use crate::model::keysend::request::*; + #[allow(unused_imports)] pub use crate::model::network::request::*; pub use crate::model::new_addr::request::*; #[allow(unused_imports)] diff --git a/lampo-common/src/model/invoice.rs b/lampo-common/src/model/invoice.rs index 7c9c2f03..40798a88 100644 --- a/lampo-common/src/model/invoice.rs +++ b/lampo-common/src/model/invoice.rs @@ -31,7 +31,6 @@ pub mod request { pub mod response { use std::vec::Vec; - use bitcoin::secp256k1::PublicKey; use lightning::routing::router::RouteHop; use serde::{Deserialize, Serialize}; @@ -42,11 +41,11 @@ pub mod response { pub bolt11: String, } - #[derive(Serialize, Deserialize, Debug)] + #[derive(Debug, Serialize, Deserialize)] pub struct Offer { pub bolt12: String, pub metadata: Option, - pub metadata_pubkey: Option, + pub metadata_pubkey: Option, } impl From for Offer { diff --git a/lampo-common/src/types.rs b/lampo-common/src/types.rs index e9d79f3d..425dbd7f 100644 --- a/lampo-common/src/types.rs +++ b/lampo-common/src/types.rs @@ -3,7 +3,7 @@ use crate::bitcoin::secp256k1::PublicKey; use crate::ldk; pub type NodeId = PublicKey; -pub type ChannelId = ldk::ln::ChannelId; +pub type ChannelId = ldk::ln::types::ChannelId; #[derive(Debug, Clone)] pub enum ChannelState { From 7171f555c49b7c69cae68cb02f8327b749041cfe Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Thu, 28 Nov 2024 22:34:29 +0530 Subject: [PATCH 2/4] deps(lampo-bitcoind): Upgrade bitcoincore-rpc bitcoincore-rpc 0.17 -> 0.19 --- lampo-bitcoind/Cargo.toml | 2 +- lampo-bitcoind/src/lib.rs | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lampo-bitcoind/Cargo.toml b/lampo-bitcoind/Cargo.toml index 7a735bfa..ef3dfe42 100644 --- a/lampo-bitcoind/Cargo.toml +++ b/lampo-bitcoind/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" [dependencies] lampo-common = { path = "../lampo-common" } -bitcoincore-rpc = { version = "0.17.0", features = [] } +bitcoincore-rpc = { version = "0.19.0", features = [] } log = "0.4.17" diff --git a/lampo-bitcoind/src/lib.rs b/lampo-bitcoind/src/lib.rs index 25cc7fda..c7d9288a 100644 --- a/lampo-bitcoind/src/lib.rs +++ b/lampo-bitcoind/src/lib.rs @@ -6,7 +6,9 @@ use std::sync::{Arc, Mutex}; use std::thread::JoinHandle; use std::time::Duration; +// BitcoinCore-RPC uses 0.30.0 use bitcoincore_rpc::bitcoin::hashes::Hash; +use bitcoincore_rpc::bitcoin::Block; use bitcoincore_rpc::bitcoin::ScriptBuf; use bitcoincore_rpc::bitcoincore_rpc_json::GetTxOutResult; use bitcoincore_rpc::Client; @@ -14,9 +16,10 @@ use bitcoincore_rpc::RpcApi; use lampo_common::backend::{deserialize, serialize}; use lampo_common::backend::{Backend, TxResult}; -use lampo_common::backend::{Block, BlockData, BlockHash}; +use lampo_common::backend::{BlockData, BlockHash}; use lampo_common::bitcoin::absolute::Height; use lampo_common::bitcoin::{Transaction, Txid}; +use lampo_common::conf::Network; use lampo_common::error; use lampo_common::event::onchain::OnChainEvent; use lampo_common::event::Event; @@ -121,7 +124,7 @@ impl BitcoinCore { .txdata .iter() .enumerate() - .find(|(_, tx)| tx.txid() == *utxo) + .find(|(_, tx)| tx.compute_txid() == *utxo) { // Confirmed! let handler = self.handler.borrow(); @@ -157,12 +160,16 @@ impl Backend for BitcoinCore { ); log::info!(target: "bitcoind", "broadcast transaction return {:?}", result); if result.is_ok() { - self.ours_txs.lock().unwrap().borrow_mut().push(tx.txid()); + self.ours_txs + .lock() + .unwrap() + .borrow_mut() + .push(tx.compute_txid()); self.others_txs .lock() .unwrap() .borrow_mut() - .retain(|(txid, _)| txid.to_string() == tx.txid().to_string()); + .retain(|(txid, _)| txid.to_string() == tx.compute_txid().to_string()); let handler = self.handler.borrow(); let Some(handler) = handler.as_ref() else { return; @@ -179,7 +186,7 @@ impl Backend for BitcoinCore { // FIXME: store the network inside the self let chain_info = self.inner.get_blockchain_info()?; - let network_str = chain_info.chain.as_str(); + let network_str = chain_info.chain.as_ref().network; if let Some(errors) = &result.errors { // Thanks to bitcoin core that will not process in time @@ -187,8 +194,11 @@ impl Backend for BitcoinCore { // or conditional code skipping. // // What next LND? :) - if network_str == "regtest" { - return Ok(253); + match &network_str { + Network::Regtest => { + return Ok(253); + } + _ => {} } error::bail!( @@ -202,7 +212,7 @@ impl Backend for BitcoinCore { let result: u32 = result.fee_rate.unwrap_or_default().to_sat() as u32; let result = match network_str { // in the regtest case that it is useful for integration testing - "regtest" => { + Network::Regtest => { if result == 0 { 253 } else { @@ -248,8 +258,9 @@ impl Backend for BitcoinCore { let bytes = serialize(header_hash); let hash = BlockHash::from_slice(bytes.as_slice())?; let result = self.inner.get_block(&hash)?; - let block: Block = deserialize(&inner_serialize(&result))?; + let block: lampo_common::bitcoin::Block = deserialize(&inner_serialize(&result))?; log::debug!(target: "bitcoind", "decode blocks {}", header_hash.to_string()); + // Lightning 0.0.125 uses bitcoin 0.32.4 Ok(BlockData::FullBlock(block)) } @@ -382,15 +393,15 @@ impl Backend for BitcoinCore { for txid in txs.iter() { match self.get_transaction(txid)? { TxResult::Confirmed((tx, idx, header, height)) => { - confirmed_txs.push(tx.txid()); + confirmed_txs.push(tx.compute_txid()); handler.emit(Event::OnChain(OnChainEvent::ConfirmedTransaction(( tx, idx, header, height, )))) } TxResult::Unconfirmed(tx) => { - unconfirmed_txs.push(tx.txid()); + unconfirmed_txs.push(tx.compute_txid()); handler.emit(Event::OnChain(OnChainEvent::UnconfirmedTransaction( - tx.txid(), + tx.compute_txid(), ))); } TxResult::Discarded => { From a2f0869009dfc12ff2f4b56673c6d597a23ce94b Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Thu, 28 Nov 2024 22:35:47 +0530 Subject: [PATCH 3/4] deps(lampo-core-wallet): Upgrade bitcoincore_rpc and bitcoin_hashes bitcoincore-rpc 0.17 -> 0.19 bitcoin-hashes 0.12 -> 0.15 --- lampo-core-wallet/Cargo.toml | 4 ++-- lampo-core-wallet/src/lib.rs | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lampo-core-wallet/Cargo.toml b/lampo-core-wallet/Cargo.toml index 370ca041..1cbd9033 100644 --- a/lampo-core-wallet/Cargo.toml +++ b/lampo-core-wallet/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" [dependencies] log = "0.4.17" lampo-common = { path = "../lampo-common" } -bitcoincore-rpc = { version = "0.17.0", features = [] } +bitcoincore-rpc = { version = "0.19.0", features = [] } bitcoin-bech32 = "0.12" -bitcoin_hashes = "0.12.0" +bitcoin_hashes = {version = "0.15", features = ["bitcoin-io"]} serde = "1" bdk = { version = "1.0.0-alpha.11", features = ["keys-bip39"] } \ No newline at end of file diff --git a/lampo-core-wallet/src/lib.rs b/lampo-core-wallet/src/lib.rs index 09cff55b..2f2b8351 100644 --- a/lampo-core-wallet/src/lib.rs +++ b/lampo-core-wallet/src/lib.rs @@ -12,14 +12,14 @@ use bdk::keys::GeneratableKey; use bdk::keys::GeneratedKey; use bdk::template::Bip84; use bdk::KeychainKind; -use bitcoin_hashes::hex::HexIterator; use bitcoincore_rpc::{Auth, Client, RpcApi}; #[cfg(debug_assertions)] use crate::bitcoin::PrivateKey; use lampo_common::bitcoin; -use lampo_common::bitcoin::consensus::Decodable; +use lampo_common::bitcoin::consensus::encode; +use lampo_common::bitcoin::Transaction; use lampo_common::conf::{LampoConf, Network}; use lampo_common::error; use lampo_common::json; @@ -73,18 +73,17 @@ impl CoreWalletManager { channel_keys: Option, ) -> error::Result<(bdk::Wallet, LampoKeys)> { use bdk::bitcoin::bip32::Xpriv; + use lampo_common::bitcoin::NetworkKind; let ldk_keys = if let Some(channel_keys) = channel_keys { LampoKeys::with_channel_keys(xprv.inner.secret_bytes(), channel_keys) } else { LampoKeys::new(xprv.inner.secret_bytes()) }; - let network = match xprv.network.to_string().as_str() { - "bitcoin" => bdk::bitcoin::Network::Bitcoin, - "testnet" => bdk::bitcoin::Network::Testnet, - "signet" => bdk::bitcoin::Network::Signet, - "regtest" => bdk::bitcoin::Network::Regtest, - _ => unreachable!(), + let network = match &xprv.network { + NetworkKind::Main => bdk::bitcoin::Network::Bitcoin, + // All other networks are handled inside test network only + NetworkKind::Test => bdk::bitcoin::Network::Testnet, }; let key = Xpriv::new_master(network, &xprv.inner.secret_bytes())?; let key = ExtendedKey::from(key); @@ -272,9 +271,9 @@ impl WalletManager for CoreWalletManager { .rpc .call("signrawtransactionwithwallet", &[json::json!(tx.hex)])?; let hex = hex.hex.unwrap(); - let mut reader = HexIterator::new(&hex)?; - let object = Decodable::consensus_decode(&mut reader)?; - Ok(object) + + let tx = encode::deserialize_hex::(&hex)?; + Ok(tx) } fn get_onchain_address(&self) -> error::Result { From ac3b44851d17e7ef806450c2d6b032329a928265 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Thu, 28 Nov 2024 22:37:06 +0530 Subject: [PATCH 4/4] deps: Upgrade lampod --- Cargo.lock | 272 ++++++++++++++++++++++++++---- lampod/src/actions/handler.rs | 8 +- lampod/src/chain/blockchain.rs | 12 +- lampod/src/jsonrpc/offchain.rs | 3 +- lampod/src/lib.rs | 4 + lampod/src/ln/channel_manager.rs | 8 +- lampod/src/ln/offchain_manager.rs | 10 +- lampod/src/ln/peer_manager.rs | 15 +- 8 files changed, 278 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d3e5ed5..30ae736c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,12 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-trait" version = "0.1.80" @@ -97,6 +103,16 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.13.1" @@ -167,6 +183,12 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bip39" version = "2.0.0" @@ -200,14 +222,32 @@ checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" dependencies = [ "base64 0.21.7", "bech32 0.10.0-beta", - "bitcoin-internals", + "bitcoin-internals 0.2.0", "bitcoin_hashes 0.13.0", - "hex-conservative", + "hex-conservative 0.1.2", "hex_lit", "secp256k1 0.28.2", "serde", ] +[[package]] +name = "bitcoin" +version = "0.32.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "788902099d47c8682efe6a7afb01c8d58b9794ba66c06affd81c3d6b560743eb" +dependencies = [ + "base58ck", + "bech32 0.11.0", + "bitcoin-internals 0.3.0", + "bitcoin-io 0.1.3", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", + "hex_lit", + "secp256k1 0.29.1", + "serde", +] + [[package]] name = "bitcoin-bech32" version = "0.12.1" @@ -226,12 +266,52 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-internals" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b854212e29b96c8f0fe04cab11d57586c8f3257de0d146c76cb3b42b3eb9118" + +[[package]] +name = "bitcoin-io" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf" + +[[package]] +name = "bitcoin-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26792cd2bf245069a1c5acb06aa7ad7abe1de69b507c90b490bca81e0665d0ee" +dependencies = [ + "bitcoin-internals 0.4.0", +] + [[package]] name = "bitcoin-private" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +[[package]] +name = "bitcoin-units" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +dependencies = [ + "bitcoin-internals 0.3.0", + "serde", +] + [[package]] name = "bitcoin_hashes" version = "0.11.0" @@ -254,11 +334,32 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.2", "serde", ] +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io 0.1.3", + "hex-conservative 0.2.1", + "serde", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0982261c82a50d89d1a411602afee0498b3e0debe3d36693f0c661352809639" +dependencies = [ + "bitcoin-io 0.2.0", + "hex-conservative 0.3.0", +] + [[package]] name = "bitcoincore-rpc" version = "0.17.0" @@ -266,8 +367,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d6c0ee9354e3dac217db4cb1dd31941073a87fe53c86bcf3eb2b8bc97f00a08" dependencies = [ "bitcoin-private", - "bitcoincore-rpc-json", - "jsonrpc", + "bitcoincore-rpc-json 0.17.0", + "jsonrpc 0.14.1", + "log", + "serde", + "serde_json", +] + +[[package]] +name = "bitcoincore-rpc" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedd23ae0fd321affb4bbbc36126c6f49a32818dc6b979395d24da8c9d4e80ee" +dependencies = [ + "bitcoincore-rpc-json 0.19.0", + "jsonrpc 0.18.0", "log", "serde", "serde_json", @@ -285,6 +399,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "bitcoincore-rpc-json" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8909583c5fab98508e80ef73e5592a651c954993dc6b7739963257d19f0e71a" +dependencies = [ + "bitcoin 0.32.4", + "serde", + "serde_json", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -353,7 +478,7 @@ version = "0.1.0" source = "git+https://github.com/laanwj/cln4rust.git#c0744fa90dd5fc711198e55e80e06d549e9f94b5" dependencies = [ "anyhow", - "bitcoincore-rpc", + "bitcoincore-rpc 0.17.0", "clightningrpc", "log", "port-selector", @@ -649,6 +774,24 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "hex-conservative" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afe881d0527571892c4034822e59bb10c6c991cce6abe8199b6f5cf10766f55" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex_lit" version = "0.1.1" @@ -748,11 +891,23 @@ dependencies = [ "serde_json", ] +[[package]] +name = "jsonrpc" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf" +dependencies = [ + "base64 0.13.1", + "minreq", + "serde", + "serde_json", +] + [[package]] name = "lampo-bitcoind" version = "0.1.0" dependencies = [ - "bitcoincore-rpc", + "bitcoincore-rpc 0.19.0", "lampo-common", "log", ] @@ -798,7 +953,7 @@ name = "lampo-common" version = "0.1.0" dependencies = [ "anyhow", - "bitcoin 0.30.2", + "bitcoin 0.32.4", "chrono", "clightningrpc-conf", "colored", @@ -822,8 +977,8 @@ version = "0.1.0" dependencies = [ "bdk", "bitcoin-bech32", - "bitcoin_hashes 0.12.0", - "bitcoincore-rpc", + "bitcoin_hashes 0.15.0", + "bitcoincore-rpc 0.19.0", "lampo-common", "log", "serde", @@ -947,80 +1102,91 @@ dependencies = [ [[package]] name = "lightning" -version = "0.0.123" +version = "0.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd92d4aa159374be430c7590e169b4a6c0fb79018f5bc4ea1bffde536384db3" +checksum = "767f388e50251da71f95a3737d6db32c9729f9de6427a54fa92bb994d04d793f" dependencies = [ - "bitcoin 0.30.2", - "hex-conservative", + "bech32 0.9.1", + "bitcoin 0.32.4", + "lightning-invoice", + "lightning-types", ] [[package]] name = "lightning-background-processor" -version = "0.0.123" +version = "0.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb1c2c64050e37cee7c3b6b022106523784055ac3ee572d360780a1d6fe8062c" +checksum = "4734caab73611a2c725f15392565150e4f5a531dd1f239365d01311f7de65d2d" dependencies = [ - "bitcoin 0.30.2", + "bitcoin 0.32.4", "lightning", "lightning-rapid-gossip-sync", ] [[package]] name = "lightning-block-sync" -version = "0.0.123" +version = "0.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e1e70fa351daccede0c366cf16320b16a3e42b05ae3c7ec9c0df6b5d3a3e18" +checksum = "ea041135bad736b075ad1123ef0a4793e78da8041386aa7887779fc5c540b94b" dependencies = [ - "bitcoin 0.30.2", - "hex-conservative", + "bitcoin 0.32.4", "lightning", ] [[package]] name = "lightning-invoice" -version = "0.31.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d07d01cf197bf2184b929b7dc94aa70d935aac6df896c256a3a9475b7e9d40" +checksum = "90ab9f6ea77e20e3129235e62a2e6bd64ed932363df104e864ee65ccffb54a8f" dependencies = [ "bech32 0.9.1", - "bitcoin 0.30.2", - "lightning", - "secp256k1 0.27.0", + "bitcoin 0.32.4", + "lightning-types", ] [[package]] name = "lightning-net-tokio" -version = "0.0.123" +version = "0.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9e6a4d49c50a1344916d080dc8c012ce3a778cdd45de8def75350b2b40fe018" +checksum = "af2847a19f892f32b9ab5075af25c70370b4cc5842b4f5b53c57092e52a49498" dependencies = [ - "bitcoin 0.30.2", + "bitcoin 0.32.4", "lightning", "tokio", ] [[package]] name = "lightning-persister" -version = "0.0.123" +version = "0.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a8dd33971815fa074b05678e09a6d4b15c78225ea34d66ed4f17c35a53467a9" +checksum = "8d06283d41eb8e6d4af883cd602d91ab0c5f9e0c9a6be1c944b10e6f47176f20" dependencies = [ - "bitcoin 0.30.2", + "bitcoin 0.32.4", "lightning", "windows-sys 0.48.0", ] [[package]] name = "lightning-rapid-gossip-sync" -version = "0.0.123" +version = "0.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d861b0f0cd5f8fe8c63760023c4fd4fd32c384881b41780b62ced2a8a619f91" +checksum = "92185313db1075495e5efa3dd6a3b5d4dee63e1496059f58cf65074994718f05" dependencies = [ - "bitcoin 0.30.2", + "bitcoin 0.32.4", "lightning", ] +[[package]] +name = "lightning-types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1083b8d9137000edf3bfcb1ff011c0d25e0cdd2feb98cc21d6765e64a494148f" +dependencies = [ + "bech32 0.9.1", + "bitcoin 0.32.4", + "hex-conservative 0.2.1", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1057,7 +1223,7 @@ checksum = "86a23dd3ad145a980e231185d114399f25a0a307d2cd918010ddda6334323df9" dependencies = [ "bech32 0.10.0-beta", "bitcoin 0.31.2", - "bitcoin-internals", + "bitcoin-internals 0.2.0", "serde", ] @@ -1070,6 +1236,17 @@ dependencies = [ "adler", ] +[[package]] +name = "minreq" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763d142cdff44aaadd9268bebddb156ef6c65a0e13486bb81673cf2d8739f9b0" +dependencies = [ + "log", + "serde", + "serde_json", +] + [[package]] name = "mio" version = "0.8.11" @@ -1441,6 +1618,18 @@ dependencies = [ "serde", ] +[[package]] +name = "secp256k1" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" +dependencies = [ + "bitcoin_hashes 0.14.0", + "rand", + "secp256k1-sys 0.10.1", + "serde", +] + [[package]] name = "secp256k1-sys" version = "0.8.1" @@ -1459,6 +1648,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +dependencies = [ + "cc", +] + [[package]] name = "serde" version = "1.0.203" diff --git a/lampod/src/actions/handler.rs b/lampod/src/actions/handler.rs index 1dfb221f..6e86e867 100644 --- a/lampod/src/actions/handler.rs +++ b/lampod/src/actions/handler.rs @@ -130,6 +130,8 @@ impl Handler for LampoHandler { funding_satoshis, push_msat, channel_type, + is_announced, + params, } => { Err(error::anyhow!("Request for open a channel received, unfortunatly we do not support this feature yet.")) } @@ -190,7 +192,7 @@ impl Handler for LampoHandler { channel_value_satoshis, fee, )?; - log::info!("funding transaction created `{}`", transaction.txid()); + log::info!("funding transaction created `{}`", transaction.compute_txid()); log::info!( "transaction hex `{}`", lampo_common::bitcoin::consensus::encode::serialize_hex(&transaction) @@ -204,8 +206,8 @@ impl Handler for LampoHandler { self.channel_manager .manager() .funding_transaction_generated( - &temporary_channel_id, - &counterparty_node_id, + temporary_channel_id, + counterparty_node_id, transaction, ) .map_err(|err| error::anyhow!("{:?}", err))?; diff --git a/lampod/src/chain/blockchain.rs b/lampod/src/chain/blockchain.rs index 081a8904..49648ed2 100644 --- a/lampod/src/chain/blockchain.rs +++ b/lampod/src/chain/blockchain.rs @@ -36,7 +36,6 @@ impl LampoChainManager { fn print_ldk_target_to_string(&self, target: ConfirmationTarget) -> String { match target { - ConfirmationTarget::OnChainSweep => String::from("on_chain_sweep"), ConfirmationTarget::AnchorChannelFee => String::from("anchor_channel"), ConfirmationTarget::NonAnchorChannelFee => String::from("non_anchor_channel"), ConfirmationTarget::ChannelCloseMinimum => String::from("channel_close_minimum"), @@ -47,18 +46,21 @@ impl LampoChainManager { String::from("min_allowed_non_anchor_channel_remote") } ConfirmationTarget::OutputSpendingFee => String::from("output_spending"), + ConfirmationTarget::MaximumFeeEstimate => String::from("max_fee_estimate"), + ConfirmationTarget::UrgentOnChainSweep => String::from("urgent_on_chain_sweep"), } } pub fn estimated_fees(&self) -> HashMap> { let fees_targets = vec![ - ConfirmationTarget::OnChainSweep, ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee, ConfirmationTarget::NonAnchorChannelFee, ConfirmationTarget::MinAllowedAnchorChannelRemoteFee, ConfirmationTarget::AnchorChannelFee, ConfirmationTarget::ChannelCloseMinimum, ConfirmationTarget::OutputSpendingFee, + ConfirmationTarget::MaximumFeeEstimate, + ConfirmationTarget::UrgentOnChainSweep, ]; let mut map: HashMap> = HashMap::new(); for target in fees_targets { @@ -75,7 +77,7 @@ impl FeeEstimator for LampoChainManager { fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 { //FIXME: use cache to avoid return default value (that is 0) on u32 match confirmation_target { - ConfirmationTarget::OnChainSweep => { + ConfirmationTarget::UrgentOnChainSweep => { self.backend.fee_rate_estimation(1).unwrap_or_default() } ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee @@ -92,6 +94,10 @@ impl FeeEstimator for LampoChainManager { ConfirmationTarget::OutputSpendingFee => { self.backend.fee_rate_estimation(12).unwrap_or_default() } + // FIXME: How much blocks needs to be taken care of in MaximumFeeEstimate? + ConfirmationTarget::MaximumFeeEstimate => { + self.backend.fee_rate_estimation(12).unwrap_or_default() + } } } } diff --git a/lampod/src/jsonrpc/offchain.rs b/lampod/src/jsonrpc/offchain.rs index 15cae5f8..b9b7d3c2 100644 --- a/lampod/src/jsonrpc/offchain.rs +++ b/lampod/src/jsonrpc/offchain.rs @@ -39,8 +39,9 @@ pub fn json_offer(ctx: &LampoDaemon, request: &json::Value) -> Result { - log::info!(target: "channel_manager", "confirmed transaction with txid `{}` at height `{height}`", tx.txid()); + log::info!(target: "channel_manager", "confirmed transaction with txid `{}` at height `{height}`", tx.compute_txid()); self.chain_monitor().transactions_confirmed( &header, &[(idx as usize, &tx)], @@ -205,7 +205,7 @@ impl LampoChannelManager { ready: channel.is_channel_ready, amount: channel.channel_value_satoshis, amount_msat: channel.next_outbound_htlc_limit_msat, - public: channel.is_public, + public: channel.is_announced, available_balance_for_send_msat: channel.outbound_capacity_msat, available_balance_for_recv_msat: channel.inbound_capacity_msat, }) @@ -432,7 +432,7 @@ impl ChannelEvents for LampoChannelManager { } }; - let txid = tx.as_ref().map(|tx| tx.txid()); + let txid = tx.as_ref().map(|tx| tx.compute_txid()); Ok(response::OpenChannel { node_id: open_channel.node_id, diff --git a/lampod/src/ln/offchain_manager.rs b/lampod/src/ln/offchain_manager.rs index 9f45ca16..b5252ecd 100644 --- a/lampod/src/ln/offchain_manager.rs +++ b/lampod/src/ln/offchain_manager.rs @@ -68,7 +68,7 @@ impl OffchainManager { expiring_in: u32, ) -> error::Result { let currency = ldk::invoice::Currency::try_from(self.lampo_conf.network)?; - let invoice = ldk::invoice::utils::create_invoice_from_channelmanager( + let invoice = ldk::ln::invoice_utils::create_invoice_from_channelmanager( &self.channel_manager.manager(), self.keys_manager.clone(), self.logger.clone(), @@ -83,7 +83,9 @@ impl OffchainManager { } pub fn decode_invoice(&self, invoice_str: &str) -> error::Result { - let invoice = invoice_str.parse::()?; + let invoice = invoice_str + .parse::() + .map_err(|err| error::anyhow!("Error occured while decoding invoice {err}"))?; Ok(invoice) } @@ -129,7 +131,7 @@ impl OffchainManager { let invoice = self.decode_invoice(invoice_str)?; let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array()); let (payment_hash, onion, route) = if invoice.amount_milli_satoshis().is_none() { - ldk::invoice::payment::payment_parameters_from_zero_amount_invoice( + ldk::ln::bolt11_payment::payment_parameters_from_zero_amount_invoice( &invoice, amount_msat.ok_or(error::anyhow!( "invoice with no amount, and amount must be specified" @@ -137,7 +139,7 @@ impl OffchainManager { ) .map_err(|err| error::anyhow!("{:?}", err))? } else { - ldk::invoice::payment::payment_parameters_from_invoice(&invoice) + ldk::ln::bolt11_payment::payment_parameters_from_invoice(&invoice) .map_err(|err| error::anyhow!("{:?}", err))? }; self.channel_manager diff --git a/lampod/src/ln/peer_manager.rs b/lampod/src/ln/peer_manager.rs index bb4dad54..8e24545a 100644 --- a/lampod/src/ln/peer_manager.rs +++ b/lampod/src/ln/peer_manager.rs @@ -36,6 +36,7 @@ pub type LampoArcOnionMessenger = OnionMessenger< Arc, Arc, Arc>>, IgnoringMessageHandler, IgnoringMessageHandler, + IgnoringMessageHandler, >; pub type SimpleArcPeerManager = PeerManager< @@ -51,11 +52,14 @@ pub type SimpleArcPeerManager = PeerManager< type InnerLampoPeerManager = SimpleArcPeerManager; +type LampoOnionMessenger = LampoArcOnionMessenger; + pub struct LampoPeerManager { peer_manager: Option>, channel_manager: Option>, conf: LampoConf, logger: Arc, + onion_messenger: Option>, } impl LampoPeerManager { @@ -65,6 +69,7 @@ impl LampoPeerManager { conf: conf.to_owned(), logger, channel_manager: None, + onion_messenger: None, } } @@ -72,6 +77,10 @@ impl LampoPeerManager { self.peer_manager.clone().unwrap() } + pub fn onion_messenger(&self) -> Arc { + self.onion_messenger.clone().unwrap() + } + pub fn init( &mut self, _onchain_manager: Arc, @@ -94,6 +103,7 @@ impl LampoPeerManager { Arc::new(DefaultMessageRouter::new(graph.clone(), keys.clone())), IgnoringMessageHandler {}, IgnoringMessageHandler {}, + IgnoringMessageHandler {}, )); let gossip_sync = Arc::new(P2PGossipSync::new( @@ -104,7 +114,7 @@ impl LampoPeerManager { let lightning_msg_handler = MessageHandler { chan_handler: channel_manager.channeld.clone().unwrap(), - onion_message_handler: onion_messenger, + onion_message_handler: onion_messenger.clone(), route_handler: gossip_sync, custom_message_handler: IgnoringMessageHandler {}, }; @@ -118,6 +128,7 @@ impl LampoPeerManager { ); self.peer_manager = Some(Arc::new(peer_manager)); self.channel_manager = Some(channel_manager.clone()); + self.onion_messenger = Some(onion_messenger); Ok(()) } @@ -181,7 +192,7 @@ impl LampoPeerManager { .manager() .list_channels() .iter() - .any(|chan| chan.is_public) + .any(|chan| chan.is_announced) { peer_manager.broadcast_node_announcement( [0; 3],