Skip to content

Commit

Permalink
update to new upstream CLN
Browse files Browse the repository at this point in the history
ElementsProject/lightning#7258 finally merged,
so we need to switch to the new more consistent tag names and
use the elementsproject fork instead of niftynei

There are also some changes required for the new startup_regtest script.
  • Loading branch information
chrisguida committed Sep 26, 2024
1 parent a10b4e0 commit 3a607a4
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 47 deletions.
5 changes: 2 additions & 3 deletions .github/scripts/install-cln.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/

scratch

result
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;).

Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 6 additions & 17 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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..."
Expand All @@ -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 ""
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/test_bkpr_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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))
Expand Down

0 comments on commit 3a607a4

Please sign in to comment.