all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#47187] [PATCH] gnu: Add c-lightning.
@ 2021-03-16  8:40 ZmnSCPxj via Guix-patches via
  2021-03-16  9:13 ` Léo Le Bouter via Guix-patches via
  0 siblings, 1 reply; 12+ messages in thread
From: ZmnSCPxj via Guix-patches via @ 2021-03-16  8:40 UTC (permalink / raw)
  To: 47187

Good morning Guix developers,

C-Lightning is one of the earliest living implementations of the Lightning
Network protocol.
I am one of the developers of this implementation.

I tested this as follows:

* Extracted the package `c-lightning` into a `c-lightning.scm` file.
* Ran `guix build --rounds=4 -f c-lightning.scm` on an X86-64 server to
  check for reproducability issues.
* Ran the compiled `lightningd` with `lightningd --version`,
  `lightningd --help`, and the developer-secret undocumented
  `lightningd --test-daemons-only` and checked they work correctly.
* Ran the compiled `lightningd` with `lightningd --proxy=127.0.0.1:9050
  --bind-addr=127.0.0.1:9735 --addr=statictor:127.0.0.1:9051
  --always-use-proxy=true` on a server with Bitcoin and Tor installed,
  and checked that it indeed created an LN wallet and started operating
  the node.
  * This also tests the SQLITE database backend and that the sub-daemons
    are accessible and runnable.
* From an existing Lightning Network node, did a `lightning-cli connect`
  to the new node running on the above command, and confirmed that the
  above new node was connected to, and that it started downloading the
  gossip map (the first thing every new node does when it initially gets
  connected to the network).
* On a separate X86-64 machine with the same Guix commit version, copied
  the `c-lightning.scm` file and reran `guix build --rounds=4 -f
  c-lightning.scm` as well.
* Checked that the same `/gnu/store` path was produced on the separate
  machine as on the first test server.
* Checked that this command produced the exact same text on both computers:
  `find ${GNU_STORE_PATH} -type f | sort | xargs -n1 sha256sum`.
* Extracted the package `c-lightning-postgresql` into a
  `c-lightning-postgresql.scm` file.
* Ran `guix build --rounds=4 -f c-lightning-postgresql.scm` on a X86-64
  server to check for reproducibility issues.
* Chekced that `strings ${GNU_STORE_PATH}/bin/lightningd` for the
  `c-lightning-postgresql` had references to `PQ*` functions, and that
  the `c-lightning` version had none, meaning that `c-lightning-postgresql`
  indeed included PostgreSQL support.

Thus, PostgreSQL support is not fully tested yet, but I believe the
produced binaries will work correctly as a C-Lightning instance.
Therefore I would like to submit this patch for inclusion into Guix.

Some notes:

* C-Lightning includes an extensive suite of tests, but these require
  several additional python packages, some of which (e.g.
  `python-bitcoinlib`) are not yet in Guix.
  The tests are extensive and *very long*, running the entire test
  suite can take an hour or more depending on exact settings.
* I took advantage of the functional nature of Guix and disabled the
  relative-path `BINTOPKGLIBEXECDIR`, making it an absolute path, as
  it also incidentally solves the issue of "upgrading C-lightning may
  cause strange problems in a running instance".
  See patch for more details.
* Our `configure` and `Makefile` are weird and I should probably go
  fix those upstream.

Regards,
ZmnSCPxj

From 490aa608765228fbb6bb64b9fa679bb4c8145001 Mon Sep 17 00:00:00 2001
From: ZmnSCPxj jxPCSnmZ <ZmnSCPxj@protonmail.com>
Date: Mon, 15 Mar 2021 11:53:35 +0000
Subject: [PATCH] gnu: Add c-lightning.

* gnu/packages/finance.scm (c-lightning, c-lightning-postgresql): New variables.
---
 gnu/packages/finance.scm | 153 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 153 insertions(+)

diff --git a/gnu/packages/finance.scm b/gnu/packages/finance.scm
index e6df40c168..4b565ddfeb 100644
--- a/gnu/packages/finance.scm
+++ b/gnu/packages/finance.scm
@@ -22,6 +22,7 @@
 ;;; Copyright © 2020 Vinicius Monego <monego@posteo.net>
 ;;; Copyright © 2020 Carlo Holl <carloholl@gmail.com>
 ;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
+;;; Copyright © 2021 ZmnSCPxj jxPCSnmZ <ZmnSCPxj@protonmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -57,6 +58,7 @@
   #:use-module (gnu packages aidc)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages base)
+  #:use-module (gnu packages bash)
   #:use-module (gnu packages boost)
   #:use-module (gnu packages check)
   #:use-module (gnu packages compression)
@@ -99,6 +101,7 @@
   #:use-module (gnu packages qt)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages sphinx)
+  #:use-module (gnu packages sqlite)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages textutils)
   #:use-module (gnu packages time)
@@ -1676,3 +1679,152 @@ Interface (UI) for the hledger accounting system.  It can be used as a
 local, single-user UI, or as a multi-user UI for viewing, adding, and
 editing on the Web.")
     (license license:gpl3)))
+
+(define-public c-lightning
+  (package
+    (name "c-lightning")
+    (version "0.9.3")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (string-append
+               "https://github.com/ElementsProject/lightning/releases/download/"
+               "v" version "/clightning-v" version ".zip"))
+        (sha256
+          (base32 "1chqzxcqpr49vbayrw4213lznmyw4lcghcdh6afxbk4bxlhkjmml"))))
+    (build-system gnu-build-system)
+    (native-inputs
+      `(("autoconf" ,autoconf)
+        ("automake" ,automake)
+        ("bash" ,bash)
+        ("libtool" ,libtool)
+        ("pkg-config" ,pkg-config)
+        ("python" ,python)
+        ("python-mako" ,python-mako)
+        ("sed" ,sed)
+        ("unzip" ,unzip)
+        ("which" ,which)))
+    (inputs
+      `(("gmp" ,gmp)
+        ("sqlite" ,sqlite)
+        ("zlib" ,zlib)))
+    (arguments
+      ;; Tests exist, but need a lot of Python packages (some not available
+      ;; on Guix) and they are incompatible with our BINTOPKGLIBEXECDIR hack.
+      `(#:tests? #f
+        #:phases
+        (modify-phases %standard-phases
+          (add-before 'configure 'patch-makefile
+            (lambda _
+              (substitute* "Makefile"
+                ;; The C-lightning Makefile uses the PYTHONPATH
+                ;; variable, which causes Guix builds to fail
+                ;; since the environment variable is masked by
+                ;; the Makefile variable.
+                ;; Insert the contents of the variable into the
+                ;; Makefile.
+                (("^PYTHONPATH=")
+                 (string-append
+                   "PYTHONPATH="
+                   (getenv "PYTHONPATH")
+                   ":"))
+                ;; C-lightning will spawn a number of other
+                ;; processes from binaries installed in its
+                ;; libexecdir.
+                ;; It normally uses relative paths so that
+                ;; users can move around the installation
+                ;; location.
+                ;; However, it does have the drawback that if
+                ;; the installation location is overwritten
+                ;; with a newer version while an existing
+                ;; instance is still running, any new
+                ;; sub-processes launched will be the new
+                ;; version, which is likely incompatible with
+                ;; the running instance.
+                ;; Since Guix would not allow the store
+                ;; directory to be moved anyway, we use an
+                ;; absolute path instead in the below
+                ;; substitution.
+                ;; With Guix and an absolute path, even if a
+                ;; running instance was launched from a
+                ;; profile and that profile is upgraded to a
+                ;; newer version, the running instance will
+                ;; refer to the absolute store directory
+                ;; containing binaries of the running version.
+                (("BINTOPKGLIBEXECDIR=.*$")
+                 "BINTOPKGLIBEXECDIR='\"'\"$(pkglibexecdir)\"'\"'\n"))))
+          ;; C-lightning configure is unusual, it does not understand
+          ;; the standard parameters Guix passes in, so, provide those
+          ;; by env variables.
+          (replace 'configure
+            (lambda* (#:key outputs inputs (configure-flags '())
+                      #:allow-other-keys)
+              (let* ((bash    (string-append (assoc-ref inputs "bash") "/bin/bash"))
+                     (python  (assoc-ref inputs "python"))
+                     (prefix  (assoc-ref outputs "out"))
+                     (flags   (cons*
+                                "CC=gcc"
+                                (string-append "--prefix=" prefix)
+                                configure-flags)))
+                (setenv "PYTHON" (string-append python "/bin/python3"))
+                (setenv "CONFIG_SHELL" bash)
+                (setenv "SHELL" bash)
+                (format #t "build directory: ~s~%" (getcwd))
+                (format #t "configure flags: ~s~%" flags)
+                (apply invoke bash
+                       "./configure"
+                       flags))))
+          ;; Rather than call the configure script of its external
+          ;; libraries from its own configure script, the external
+          ;; configure are created and called at build time.
+          ;; Unfortunately, it is a single Makefile stanza which
+          ;; does the autoreconf, configure, and make.
+          ;; This means we cannot "cut" through here by creating
+          ;; the external configure before this step (the Makefile
+          ;; stanza will recreate and overwrite the external
+          ;; configure), we have to modify the autogen.sh scripts
+          ;; of the external libraries instead so that they
+          ;; patch the shebangs after autoreconf.
+          (add-before 'build 'fix-autoreconf
+            (lambda _
+              (substitute* "external/libsodium/autogen.sh"
+                (("exec autoreconf(.*)$" exec-autoreconf flags)
+                 (string-append
+                   "autoreconf" flags
+                   "sed 's:/bin/sh:" (getenv "SHELL") ":g' < configure > configure.tmp\n"
+                   "mv configure.tmp configure\n"
+                   "chmod +x configure\n"
+                   "exit 0\n")))
+              (substitute* "external/libwally-core/tools/autogen.sh"
+                (("autoreconf(.*)$" autoreconf)
+                 (string-append
+                   autoreconf
+                   "sed 's:/bin/sh:" (getenv "SHELL") ":g' < configure > configure.tmp\n"
+                   "mv configure.tmp configure\n"
+                   "chmod +x configure\n"))))))))
+    (home-page "https://github.com/ElementsProject/lightning")
+    (synopsis "Lightweight Lightning Network protocol implementation in C")
+    (description
+      "c-lightning is a lightweight, highly customizable, and standard
+compliant implementation of the Lightning Network protocol.")
+    (license license:expat)))
+
+(define-public c-lightning-postgresql
+  (package
+    (inherit c-lightning)
+    (name "c-lightning-postgresql")
+    (inputs
+      `(("postgresql" ,postgresql)
+        ;; C-Lightning requires SQLITE3 as of 0.9.3, and will
+        ;; fail to build if it is not found.
+        ;; (The configure script will allow PostgreSQL without
+        ;; SQLITE3 but some build tool of C-Lightning fails if
+        ;; SQLITE3 is not found.)
+        ,@(package-inputs c-lightning)))
+    (description
+      "c-lightning is a lightweight, highly customizable, and standard
+compliant implementation of the Lightning Network protocol.
+
+This package includes support for using a PostgreSQL database to back
+your node; you will need to set up the PostgreSQL separately and pass
+in its details using an appropriate flag setting.")))
--
2.30.1





^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-03-26 18:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-16  8:40 [bug#47187] [PATCH] gnu: Add c-lightning ZmnSCPxj via Guix-patches via
2021-03-16  9:13 ` Léo Le Bouter via Guix-patches via
2021-03-16  9:17   ` Léo Le Bouter via Guix-patches via
2021-03-16 11:27     ` ZmnSCPxj via Guix-patches via
2021-03-16 12:46       ` Léo Le Bouter via Guix-patches via
2021-03-17  3:42         ` ZmnSCPxj via Guix-patches via
2021-03-18  6:33           ` Léo Le Bouter via Guix-patches via
2021-03-18 16:54             ` ZmnSCPxj via Guix-patches via
2021-03-19  9:09               ` Léo Le Bouter via Guix-patches via
2021-03-19 19:31                 ` ZmnSCPxj via Guix-patches via
2021-03-21 21:42                   ` Léo Le Bouter via Guix-patches via
2021-03-26 18:13                     ` Léo Le Bouter via Guix-patches via

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.