diff --git a/.github/scripts/install-cln.sh b/.github/scripts/install-cln.sh index 1f96c26..e06af22 100755 --- a/.github/scripts/install-cln.sh +++ b/.github/scripts/install-cln.sh @@ -10,11 +10,10 @@ sudo apt-get install -y cargo rustfmt protobuf-compiler pip3 install mako -git clone https://github.com/niftynei/lightning.git +git clone https://github.com/elementsproject/lightning.git cd lightning -git checkout nifty/onchain_notif +git checkout v24.08.1 -pip3 install -r plugins/clnrest/requirements.txt pip3 install grpcio-tools ./configure diff --git a/README.md b/README.md index c43f114..756340f 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ This enables businesses to design a complete treasury using [Miniscript](https:/ ## Prerequsites - [`bitcoind`](https://github.com/bitcoin/bitcoin) with `scanblocks` RPC enabled (at least v24 and `blockfilterindex=1`) -- [`lightningd`](https://github.com/elementsproject/lightning) (aka Core Lightning aka CLN), built from [this branch](https://github.com/niftynei/lightning/tree/nifty/onchain_notif). (This branch adds the two new custom notification topics we use for Smaug: `utxo_deposit` and `utxo_spent`) +- [`lightningd`](https://github.com/elementsproject/lightning) (aka Core Lightning aka CLN), at least version v24.08 I recommend [`nix-bitcoin`](https://nixbitcoin.org) with a config [something like this](https://github.com/chrisguida/nix-dell) -- Obviously this is for mutinynet; if you want mainnet, edit your flake url to pull in the official nix-bitcoin repo) +- Obviously this is for mutinynet; if you want mainnet, edit your flake url to pull in the official nix-bitcoin repo. To get started quickly with nix-bitcoin, I recommend [this excellent tutorial](https://github.com/chrisguida/nixos-mutinynet-tutorial) ;). diff --git a/flake.lock b/flake.lock index 77c5c10..bd62ac7 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1698420672, - "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", "owner": "nix-community", "repo": "naersk", - "rev": "aeb58d5e8faead8980a807c840232697982d47b9", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", "type": "github" }, "original": { @@ -21,11 +21,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1702206697, - "narHash": "sha256-vE9oEx3Y8TO5MnWwFlmopjHd1JoEBno+EhsfUCq5iR8=", + "lastModified": 1727089097, + "narHash": "sha256-ZMHMThPsthhUREwDebXw7GX45bJnBCVbfnH1g5iuSPc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "29d6c96900b9b576c2fb89491452f283aa979819", + "rev": "568bfef547c14ca438c56a0bece08b8bb2b71a9c", "type": "github" }, "original": { @@ -35,11 +35,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1702206697, - "narHash": "sha256-vE9oEx3Y8TO5MnWwFlmopjHd1JoEBno+EhsfUCq5iR8=", + "lastModified": 1727089097, + "narHash": "sha256-ZMHMThPsthhUREwDebXw7GX45bJnBCVbfnH1g5iuSPc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "29d6c96900b9b576c2fb89491452f283aa979819", + "rev": "568bfef547c14ca438c56a0bece08b8bb2b71a9c", "type": "github" }, "original": { @@ -76,11 +76,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9c804c5..f0abd9d 100644 --- a/flake.nix +++ b/flake.nix @@ -13,23 +13,8 @@ ... }: utils.lib.eachDefaultSystem (system: let - cln-overlay = final: prev: { - clightning = prev.clightning.overrideAttrs { - version = "23.11"; - src = prev.fetchFromGitHub { - owner = "niftynei"; - repo = "lightning"; - #rev = "44c5b523683160e8c20bda200c6a5a59ea40bc5e"; - rev = "37ad798a02336a82460b865fd4e6a29d8880856c"; - sha256 = "sha256-pkXU4JB5Y2oN/2DfYNRgGJdH36Nz3gmVfC/Exv2E2Zk="; - fetchSubmodules = true; - }; - }; - }; - pkgs = import nixpkgs { inherit system; - overlays = [ cln-overlay ]; }; naersk-lib = pkgs.callPackage naersk {}; in rec { @@ -39,7 +24,7 @@ }; devShell = pkgs.mkShell { - buildInputs = with pkgs; [ bash cargo rustc rustfmt pre-commit rustPackages.clippy pkg-config openssl bitcoin clightning poetry ]; + buildInputs = with pkgs; [ bash bitcoin clightning cargo gawk libeatmydata openssl pkg-config poetry pre-commit rustc rustfmt rustPackages.clippy ]; RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; shellHook = '' echo "Entering devshell..." @@ -50,9 +35,13 @@ echo "mkdir -p ~/.bitcoin" echo "" + # Extract CLN zip file to a temporary directory + TMP_DIR=$(mktemp -d) + unzip -q ${pkgs.clightning.src} -d "$TMP_DIR" + echo "Then to set up two lightning nodes and a bitcoin node in regtest mode," echo "run the following two commands:" - echo "source ${pkgs.clightning.src}/contrib/startup_regtest.sh" + echo "source $TMP_DIR/clightning-v24.08.1/contrib/startup_regtest.sh" echo "start_ln" echo "" diff --git a/src/main.rs b/src/main.rs index 5e398eb..0beb218 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use tokio::sync::Mutex; -use smaug::wallet::{AddArgs, DescriptorWallet, SMAUG_DATADIR, UTXO_DEPOSIT_TAG, UTXO_SPENT_TAG}; +use smaug::wallet::{AddArgs, DescriptorWallet, SMAUG_DATADIR, UTXO_DEPOSIT_TAG, UTXO_SPEND_TAG}; use cln_plugin::{anyhow, messages, options, Builder, Error, Plugin}; use tokio; @@ -73,7 +73,7 @@ async fn main() -> Result<(), anyhow::Error> { "Bitcoind data directory (for cookie file access)", )) .notification(messages::NotificationTopic::new(UTXO_DEPOSIT_TAG)) - .notification(messages::NotificationTopic::new(UTXO_SPENT_TAG)) + .notification(messages::NotificationTopic::new(UTXO_SPEND_TAG)) .rpcmethod( "smaug", "Watch one or more external wallet descriptors and emit notifications when coins are moved", diff --git a/src/wallet.rs b/src/wallet.rs index ccd5f78..431c53d 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -26,7 +26,7 @@ use crate::state::State; pub const SMAUG_DATADIR: &str = ".smaug"; pub const UTXO_DEPOSIT_TAG: &str = "utxo_deposit"; -pub const UTXO_SPENT_TAG: &str = "utxo_spent"; +pub const UTXO_SPEND_TAG: &str = "utxo_spend"; /// Errors related to the `smaug` command. #[derive(Debug)] @@ -420,7 +420,7 @@ impl DescriptorWallet { let amount = po.value; let outpoint = format!("{}", input.previous_output.to_string()); log::trace!("outpoint = {}", format!("{}", outpoint)); - let onchain_spend = json!({UTXO_SPENT_TAG: { + let onchain_spend = json!({UTXO_SPEND_TAG: { "account": acct, "outpoint": outpoint, "spending_txid": tx.tx_node.txid, @@ -433,7 +433,7 @@ impl DescriptorWallet { let cloned_plugin = plugin.clone(); tokio::spawn(async move { if let Err(e) = cloned_plugin - .send_custom_notification(UTXO_SPENT_TAG.to_string(), onchain_spend) + .send_custom_notification(UTXO_SPEND_TAG.to_string(), onchain_spend) .await { log::error!("Error sending custom notification: {:?}", e); @@ -582,7 +582,7 @@ impl DescriptorWallet { let amount = po.value; let outpoint = format!("{}", input.previous_output.to_string()); log::trace!("outpoint = {}", format!("{}", outpoint)); - let onchain_spend = json!({UTXO_SPENT_TAG: { + let onchain_spend = json!({UTXO_SPEND_TAG: { "account": acct, "outpoint": outpoint, "spending_txid": tx.tx_node.txid.to_string(), @@ -595,7 +595,7 @@ impl DescriptorWallet { let cloned_plugin = plugin.clone(); tokio::spawn(async move { if let Err(e) = cloned_plugin - .send_custom_notification(UTXO_SPENT_TAG.to_string(), onchain_spend) + .send_custom_notification(UTXO_SPEND_TAG.to_string(), onchain_spend) .await { log::error!("Error sending custom notification: {:?}", e); diff --git a/tests/poetry.lock b/tests/poetry.lock index e4ead5e..765a8a2 100644 --- a/tests/poetry.lock +++ b/tests/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "asn1crypto" @@ -1297,6 +1297,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -1595,4 +1596,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "441760054c0c6c773f680298642e757fbe5b1a112a86d632925cd04a14b6c7a1" +content-hash = "f16e5c3928520e6144275c1fc668e11d7acae09e19d8fbd0d2a483c23b66359d" diff --git a/tests/test_bkpr_integration.py b/tests/test_bkpr_integration.py index 98946a5..3b79cff 100644 --- a/tests/test_bkpr_integration.py +++ b/tests/test_bkpr_integration.py @@ -70,7 +70,7 @@ def generate(): ) # ## simple spend ## # - # 1 input which is ours (send utxo_spent for 100M sats) + # 1 input which is ours (send utxo_spend for 100M sats) # 2 outputs: # 1 which is the 10M sat spend (to an external account) # (send utxo_deposit from our account to external) @@ -83,7 +83,7 @@ def generate(): # smaug wallet # this subtracts 1M sat (+141 sats for fee) from our bitcoind wallet # this will generate 3 more bkpr events for our smaug wallet: - # 1 utxo_spent for our input and 2 utxo_deposits for the outputs + # 1 utxo_spend for our input and 2 utxo_deposits for the outputs cln_addr = ln_node.rpc.newaddr()["bech32"] bitcoind.rpc.sendtoaddress(cln_addr, sats_to_btc(CLN_INITIAL_AMOUNT_SAT)) generate() @@ -102,8 +102,8 @@ def generate(): # ## simple shared tx ## # # payjoin where we pay 10M sats from smaug (ours) to CLN (theirs) # 2 inputs - # 1 which is ours (89_999_859 sats) (send utxo_spent) - # 1 which is theirs (10M sats) (send utxo_spent) + # 1 which is ours (89_999_859 sats) (send utxo_spend) + # 1 which is theirs (10M sats) (send utxo_spend) # 2 outputs # 1 which is ours (79_998_859 sats) # (utxo_deposit from our wallet to our wallet (basically change))