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

upgrade ldk library version #187

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
794 changes: 447 additions & 347 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ default-members = [
"lampod-cli",
"lampo-cli",
"lampo-bitcoind",
"lampo-nakamoto",
"lampo-jsonrpc",
"lampo-client",
"lampo-c-ffi",
Expand Down
30 changes: 15 additions & 15 deletions lampo-bitcoind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ use std::thread::JoinHandle;
use std::time::Duration;

use bitcoincore_rpc::bitcoin::hashes::Hash;
use bitcoincore_rpc::bitcoin::ScriptBuf;
use bitcoincore_rpc::bitcoincore_rpc_json::GetTxOutResult;
use bitcoincore_rpc::Client;
use bitcoincore_rpc::RpcApi;

use lampo_common::backend::BlockHash;
use lampo_common::backend::{deserialize, serialize};
use lampo_common::backend::{Backend, TxResult};
use lampo_common::backend::{Block, BlockData};
use lampo_common::bitcoin::locktime::Height;
use lampo_common::bitcoin::{Script, Transaction, Txid};
use lampo_common::backend::{Block, BlockData, BlockHash};
use lampo_common::bitcoin::absolute::Height;
use lampo_common::bitcoin::{Transaction, Txid};
use lampo_common::error;
use lampo_common::event::onchain::OnChainEvent;
use lampo_common::event::Event;
use lampo_common::handler::Handler;
use lampo_common::json;
use lampo_common::secp256k1::hashes::hex::ToHex;

pub struct BitcoinCore {
inner: Client,
handler: RefCell<Option<Arc<dyn Handler>>>,
ours_txs: Mutex<RefCell<Vec<Txid>>>,
others_txs: Mutex<RefCell<Vec<(Txid, Script)>>>,
others_txs: Mutex<RefCell<Vec<(Txid, ScriptBuf)>>>,
// receive notification if the
// deamon was stop
stop: Arc<bool>,
Expand Down Expand Up @@ -86,7 +85,7 @@ impl BitcoinCore {
Ok(tx.script_pub_key.hex)
}

pub fn watch_tx(&self, txid: &Txid, script: &Script) -> error::Result<()> {
pub fn watch_tx(&self, txid: &Txid, script: &ScriptBuf) -> error::Result<()> {
log::debug!(target: "bitcoind", "Looking an external transaction `{}`", txid);
if self
.ours_txs
Expand Down Expand Up @@ -115,7 +114,7 @@ impl BitcoinCore {
log::debug!(target: "bitcoin", "looking the tx inside the new block");
let utxos = self.others_txs.lock().unwrap();
let mut utxos = utxos.borrow_mut();
let mut still_unconfirmed: Vec<(Txid, Script)> = vec![];
let mut still_unconfirmed: Vec<(Txid, ScriptBuf)> = vec![];
for (utxo, script) in utxos.iter() {
log::debug!(target: "bitcoind", "looking for UTXO {} inside the block at height: {}", utxo, self.best_height.borrow());
if let Some((idx, tx)) = block
Expand Down Expand Up @@ -154,9 +153,7 @@ impl Backend for BitcoinCore {
// FIXME: check the result.
let result: bitcoincore_rpc::Result<json::Value> = self.inner.call(
"sendrawtransaction",
&[lampo_common::bitcoin::consensus::serialize(&tx)
.to_hex()
.into()],
&[lampo_common::bitcoin::consensus::serialize(&tx).into()],
);
log::info!(target: "bitcoind", "broadcast transaction return {:?}", result);
if result.is_ok() {
Expand Down Expand Up @@ -244,7 +241,6 @@ impl Backend for BitcoinCore {
header_hash: &lampo_common::backend::BlockHash,
) -> error::Result<lampo_common::backend::BlockData> {
use bitcoincore_rpc::bitcoin::consensus::serialize as inner_serialize;
use bitcoincore_rpc::bitcoin::BlockHash;

// FIXME: change the version of rust bitcoin in nakamoto and in lampod_common.
let bytes = serialize(header_hash);
Expand Down Expand Up @@ -291,7 +287,7 @@ impl Backend for BitcoinCore {
txid: &lampo_common::backend::Txid,
script: &lampo_common::backend::Script,
) {
self.watch_tx(txid, script).unwrap();
self.watch_tx(txid, &script.to_owned()).unwrap();
let _ = self.process_transactions();
}

Expand All @@ -310,7 +306,7 @@ impl Backend for BitcoinCore {
let raw_tx: Transaction = deserialize(&tx.hex)?;
if tx.info.confirmations > 0 {
// SAFETY: if it is confirmed, the block hash is not null.
let block_hash = tx.info.blockhash.unwrap().to_hex();
let block_hash = tx.info.blockhash.unwrap().to_string();
let BlockData::FullBlock(block) = self.get_block(&BlockHash::from_str(&block_hash)?)?
else {
unreachable!()
Expand Down Expand Up @@ -350,7 +346,11 @@ impl Backend for BitcoinCore {
.vout
.iter()
.enumerate()
.find(|vout| vout.1.script_pub_key.hex.to_hex() == script.to_hex())
// FIXME: I am not sure that this magic with script is correct
.find(|vout| {
ScriptBuf::from_bytes(vout.1.script_pub_key.hex.clone()).to_hex_string()
== script.to_hex_string()
})
.unwrap();
return Ok(TxResult::Confirmed((
raw_tx,
Expand Down
1 change: 0 additions & 1 deletion lampo-c-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ log = "*"
lampod = { path = "../lampod" }
lampo-common = { path = "../lampo-common" }
lampo-jsonrpc = { path = "../lampo-jsonrpc" }
lampo-nakamoto = { path = "../lampo-nakamoto" }
lampo-bitcoind = { path = "../lampo-bitcoind" }
lampo-core-wallet = { path = "../lampo-core-wallet" }

Expand Down
6 changes: 0 additions & 6 deletions lampo-c-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@
pub extern "C" fn new_lampod(conf_path: *const libc::c_char) -> *mut LampoDeamon {
use lampo_common::conf::LampoConf;
use lampo_core_wallet::CoreWalletManager;
use lampo_nakamoto::{Config, Nakamoto, Network};
use lampod::chain::WalletManager;
use std::str::FromStr;

Check warning on line 107 in lampo-c-ffi/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (stable)

unused import: `std::str::FromStr`

init_logger();

Expand Down Expand Up @@ -185,11 +184,6 @@
)
.expect("impossible connect to core"),
),
"nakamoto" => {
let mut nakamtot_conf = Config::default();
nakamtot_conf.network = Network::from_str(&conf.network.to_string()).unwrap();
Arc::new(Nakamoto::new(nakamtot_conf).unwrap())
}
_ => {
LAST_ERR
.lock()
Expand Down
17 changes: 8 additions & 9 deletions lampo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lightning = { version = "0.0.118", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.118" }
lightning-persister = { version = "0.0.118" }
lightning-background-processor = { version = "0.0.118" }
lightning-net-tokio = { version = "0.0.118" }
lightning-rapid-gossip-sync = { version = "0.0.118" }
lightning-invoice = { version = "0.26.0" }

lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys", features = ["max_level_trace"] }
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys" }
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys" }
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys" }
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys" }
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys" }
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning.git", branch = "macros/allow-to-inject-channels-keys" }
bitcoin = { version = "0.30.2", features = ["serde"] }
clightningrpc-conf = { git = "https://github.com/laanwj/cln4rust.git", branch = "master" }
crossbeam-channel = "0.5.8"
bitcoin = { version = "0.29.0", features = ["serde"] }
anyhow = "1.0.70"
colored = "1.9"
log = { version = "0.4", features = ["std"] }
Expand Down
5 changes: 3 additions & 2 deletions lampo-common/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
use std::sync::Arc;
use std::thread::JoinHandle;

use bitcoin::absolute::Height;
use bitcoin::block::Header as BlockHeader;

pub use bitcoin::consensus::{deserialize, serialize};
use bitcoin::locktime::Height;
use bitcoin::BlockHeader;
pub use bitcoin::{Block, BlockHash, Script, Transaction, Txid};
pub use lightning::chain::WatchedOutput;
pub use lightning::routing::utxo::UtxoResult;
Expand Down
10 changes: 5 additions & 5 deletions lampo-common/src/event/onchain.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Event generated by onchain events.
use std::fmt::Debug;

use crate::bitcoin::BlockHeader;
use crate::bitcoin::{locktime::Height, Txid};
use crate::bitcoin::{Block, Transaction};
use crate::bitcoin::absolute::Height;
use crate::bitcoin::block::Header;
use crate::bitcoin::{Block, Transaction, Txid};

#[derive(Clone)]
pub enum OnChainEvent {
NewBlock(Block),
NewBestBlock((BlockHeader, Height)),
NewBestBlock((Header, Height)),
FeeEstimation(u32),
SendRawTransaction(Transaction),
ConfirmedTransaction((Transaction, u32, BlockHeader, Height)),
ConfirmedTransaction((Transaction, u32, Header, Height)),
DiscardedTransaction(Txid),
UnconfirmedTransaction(Txid),
}
Expand Down
Loading
Loading