Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: upgrade dependencies #297

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 235 additions & 37 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lampo-bitcoind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
35 changes: 23 additions & 12 deletions lampo-bitcoind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ 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;
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -179,16 +186,19 @@ 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
// the estimation fee for regtest, in this way we start
// or conditional code skipping.
//
// What next LND? :)
if network_str == "regtest" {
return Ok(253);
match &network_str {
Network::Regtest => {
return Ok(253);
}
_ => {}
}

error::bail!(
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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 => {
Expand Down
16 changes: 8 additions & 8 deletions lampo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lampo-common/src/event/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down
42 changes: 23 additions & 19 deletions lampo-common/src/keys.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<bitcoin::secp256k1::ecdh::SharedSecret, ()> {
other_key: &lightning::bitcoin::secp256k1::PublicKey,
tweak: Option<&lightning::bitcoin::secp256k1::Scalar>,
) -> Result<lightning::bitcoin::secp256k1::ecdh::SharedSecret, ()> {
Comment on lines +118 to +120
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here we do not referer in this crate with lightning, it is wrong.

Please see how we use it in other part of the code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

self.inner.ecdh(recipient, other_key, tweak)
}

Expand All @@ -126,51 +128,50 @@ impl NodeSigner for LampoKeysManager {
fn get_node_id(
&self,
recipient: lightning::sign::Recipient,
) -> Result<bitcoin::secp256k1::PublicKey, ()> {
) -> Result<lightning::bitcoin::secp256k1::PublicKey, ()> {
self.inner.get_node_id(recipient)
}

fn sign_bolt12_invoice(
&self,
invoice: &lightning::offers::invoice::UnsignedBolt12Invoice,
) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
) -> Result<lightning::bitcoin::secp256k1::schnorr::Signature, ()> {
self.inner.sign_bolt12_invoice(invoice)
}

fn sign_bolt12_invoice_request(
&self,
invoice_request: &lightning::offers::invoice_request::UnsignedInvoiceRequest,
) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
) -> Result<lightning::bitcoin::secp256k1::schnorr::Signature, ()> {
self.inner.sign_bolt12_invoice_request(invoice_request)
}

fn sign_gossip_message(
&self,
msg: lightning::ln::msgs::UnsignedGossipMessage,
) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
) -> Result<lightning::bitcoin::secp256k1::ecdsa::Signature, ()> {
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<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
self.inner.sign_invoice(hrp_bytes, invoice_data, recipient)
) -> Result<lightning::bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
self.inner.sign_invoice(invoice_data, recipient)
}
}

impl OutputSpender for LampoKeysManager {
fn spend_spendable_outputs<C: bitcoin::secp256k1::Signing>(
fn spend_spendable_outputs<C: lightning::bitcoin::secp256k1::Signing>(
&self,
descriptors: &[&lightning::sign::SpendableOutputDescriptor],
outputs: Vec<bitcoin::TxOut>,
change_destination_script: bitcoin::ScriptBuf,
outputs: Vec<lightning::bitcoin::TxOut>,
change_destination_script: lightning::bitcoin::ScriptBuf,
feerate_sat_per_1000_weight: u32,
locktime: Option<bitcoin::absolute::LockTime>,
secp_ctx: &bitcoin::secp256k1::Secp256k1<C>,
) -> Result<bitcoin::Transaction, ()> {
locktime: Option<lightning::bitcoin::absolute::LockTime>,
secp_ctx: &lightning::bitcoin::secp256k1::Secp256k1<C>,
) -> Result<lightning::bitcoin::Transaction, ()> {
self.inner.spend_spendable_outputs(
descriptors,
outputs,
Expand Down Expand Up @@ -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<bitcoin::ScriptBuf, ()> {
fn get_destination_script(
&self,
channel_keys_id: [u8; 32],
) -> Result<lightning::bitcoin::ScriptBuf, ()> {
self.inner.get_destination_script(channel_keys_id)
}

Expand Down
1 change: 1 addition & 0 deletions lampo-common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong, why we are using it? you are suppressing warning and we should not do without a good reason

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The network request has nothing in it.

We could probably remove this, but then the request and response pattern would be non-uniform.

pub use crate::model::network::request::*;
pub use crate::model::new_addr::request::*;
#[allow(unused_imports)]
Expand Down
5 changes: 2 additions & 3 deletions lampo-common/src/model/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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<String>,
pub metadata_pubkey: Option<PublicKey>,
pub metadata_pubkey: Option<lightning::bitcoin::secp256k1::PublicKey>,
}

impl From<ldk::offers::offer::Offer> for Offer {
Expand Down
2 changes: 1 addition & 1 deletion lampo-common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lampo-core-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
21 changes: 10 additions & 11 deletions lampo-core-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,18 +73,17 @@ impl CoreWalletManager {
channel_keys: Option<String>,
) -> 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);
Expand Down Expand Up @@ -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::<Transaction>(&hex)?;
Ok(tx)
}

fn get_onchain_address(&self) -> error::Result<NewAddress> {
Expand Down
8 changes: 5 additions & 3 deletions lampod/src/actions/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
}
Expand Down Expand Up @@ -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)
Expand All @@ -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))?;
Expand Down
Loading
Loading