Core Lightning plugins in 2023

LIVE #8July 06, 2023

The idea of this live is (1) to highlight the work that has already been done in CLN plugins space and (2) to inspire new CLN users/programmers to either maintain existing plugins or to write their own.

Note that in this document we try to list "all" that have been done in Core Lightning Plugin space till 2023. Some libraries/plugins may no longer be maintained. Although the live took place in June, we will be adding new material up to December of 2023.

/img/2023-07-06-live-0008-christian-decker-there-is-a-plugin-that-does-that.png

Plugin system

The smallblock Conspiracy

If I understand correctly, the plugin system has been introduced in release [0.6.3] - 2019-01-09: "The Smallblock Conspiracy".

The most important plugin

And the most import plugin ever written (cowsay.sh) has been introduced with the following pull request: The most important contrib/ addition, ever. #2985.

/img/2023-07-06-live-0008-cowsay-pull-request.png

Contribution to lightningd/plugin.c file

◉ tony@tony:~/clnlive/lightning:[git»(HEAD detached at v23.05.2)]
$ git log --oneline --reverse --pretty=format:"%an" lightningd/plugin.c | sort | uniq
arowser
Christian Decker
Conor Scott
darosior
lisa neigut
Michael Schmoock
Richard Bondi
Rusty Russell
Simon Vrouwe
trueptolemy
Vasil Dimov
Vincenzo Palazzo
ZmnSCPxj
ZmnSCPxj jxPCSnmZ

How does it work?

Plugins can be written in any languages.

They are started by lightningd and live as subprocesses of lightningd master process. They read incoming requests from lightningd in their stdin stream and send responses/notifications to lightningd by writing to their stdout stream.

When started, plugins reply to a getmanifest request telling lightningd what they want to register, declare and subscribe to (startup options, JSON-RPC commands, notification topics and hooks).

Then they receive an init request from lightningd. At that moment, plugins have complete information about the node, therefore they can initialize themselves if necessary (starting a webserver for instance). When they are done they reply to that init request which tell lightningd that it can proceed.

Finally, plugins start an IO loop waiting for incoming request from lightningd.

Note that lightningd and plugins use JSON-RPC 2.0 to understand each other.

See lightning:doc/PLUGINS.md.

Most simple plugin in Bash

The following Bash script foo-plugin.bash implements a CLN plugin that registers foo-method JSON-RPC method to lightningd. When we call that method from any client with no argument, it returns the json {"foo":"bar"}. Note that this uses no specific CLN library and only depends only on jq command for convenience:

#!/usr/bin/bash

set -e

# getmanifest
read -r JSON
read -r _
id=$(echo "$JSON" | jq .id)
echo '{"jsonrpc": "2.0", "id": '"$id"', "result": {"dynamic": true, "options": [], "rpcmethods": [{"name": "foo-method", "usage": "", "description": "description"}]}}'

# init
read -r JSON
read -r _
id=$(echo "$JSON" | jq .id)
echo '{"jsonrpc": "2.0", "id": '"$id"', "result": {}}'

# i/o loop
while read -r JSON; do
    read -r _
    id=$(echo "$JSON" | jq .id)
    echo '{"jsonrpc": "2.0", "id": '"$id"', "result": {"foo": "bar"}}'
done

The plugin can be started like this

◉ tony@tony:~/clnlive:
$ lightning-cli plugin start $(pwd)/foo-plugin.bash

and foo-method command can be called using lightning-cli RPC client like this:

◉ tony@tony:~/clnlive:
$ lightning-cli foo-method
{
   "foo": "bar"
}

Most simple plugin in Python using pyln-client plugin library

Now, if we use a plugin library to write plugins, all the plumbing goes away and we can focus on our use case. For instance the previous foo-plugin.bash plugin would be written in Python using pyln-client library like this:

#!/usr/bin/env python3
from pyln.client import Plugin

plugin = Plugin()

@plugin.method("foo-method")
def foo_method_func(plugin):
    return {"foo": "bar"}

plugin.run()

Installing plugin

  • Manually,

  • lightning:doc/reckless.7.md: Reckless is a plugin manager for Core-Lightning. Typical plugin installation involves: finding the source plugin, copying, installing dependencies, testing, activating, and updating the lightningd config file,

  • coffee-tools/coffee: Reference implementation for a flexible core lightning plugin manager.

See also:

pyln-testing / pyln-client

The Python library pyln-client is a plugin library and also a JSON-RCP client that let you talk to lightningd.

It is maintained by Core Lightning team.

Many plugins are written with that library and part of CLN tests uses it along with pyln-testing.

See:

Libraries to write plugins

Template

Builtin plugins

Current builtin plugins:

In release 23.08 the plugins renepay and clrest have been added:

In the source code we can also find the two following plugins:

Plugins (not builtin)

Backup

  • plugins:backup/README.md: This plugin will maintain clean database backups to another location. It uses the `db_write` hook to make sure to always have a backup that is not missing any state updates and is not potentially harmful.

Bitcoin backends

  • clightning4j/esplora_clnd_plugin: Using @Blockstream Esplora web explorer to fetch bitcoin data for clightning.

  • coffee-tools/folgore: Universal Bitcoin backend for core lightning with BIP 157 support full based on the btcli4j Kotlin plugin! Ah, yes it is written in Rust.

  • clightning4j/btcli4j: It is a core lightning plugin to override Bitcoin backend plugin with esplora by Blockstream and give the possibility to make the running process with bitcoind in pruning mode more solid.

  • plugins:sauron/README.md: A Bitcoin backend plugin relying on Esplora.

  • nbd-wtf/trustedcoin: A lightningd plugin that replaces bitcoind with trusted public explorers.

  • andrewtoth/rust-bcli: A CoreLightning bitcoin backend plugin written in rust to replace the built-in bcli.

  • Start9Labs/c-lightning-pruning-plugin: This plugin manages pruning of bitcoind such that it can always sync.

Channels

Bookkeeper

  • chrisguida/watchdescriptor: watchdescriptor is a Rust-based CLN plugin that allows CLN's bookkeeper plugin to track coin movements in external descriptor wallets, enabling businesses to obtain a complete picture of all bitcoin inflows and outflows.

Events / notifications

HTTP APIs / access to CLN

Invoices

Lightning network

  • endothermicdev/impscan: CLN plugin to scan for active implementations on the lightning network.

  • plugins:probe/README.md: This plugin regularly performs a random probe of the network by sending a payment to a random node in the network, with a random `payment_hash`, and observing how the network reacts.

  • niftynei/sitzprobe: sitzprobe is a c-lightning plugin that actively sends test payments through the lightning network.

  • plugins:historian/README.org: The historian plugin aims to provide tools to archive the Lightning Network gossip messages and to work with the archived messages.

  • AutonomousOrganization/fgln: Plugin and library that uses graph Library fgl to load lightning network into functional data structure and create some convenience functions (in progress).

  • litch/spaz: This is a CLN plugin to make a fairly randomly spazzy node in a network.

LNURL

LSP

  • breez/lspd: lspd is a simple deamon that provides LSP services to Breez clients. This is a simple example of an lspd that works with an LND node or a CLN node. The CLN plugin is defined in the subdirectory cln_plugin.

Messages

Metrics / summaries

Monitoring

  • daywalker90/vitality: Core lightning (CLN) plugin to watch channel health, gossip health and ping amboss for online status.

Nostr

Pay / Payments

  • daGoodenough/bolt12-prism: CLN plugin for lightning prisms using BOLT 12.

  • andrewtoth/paythrough: CoreLightning plugin to pay through a specific channel.

  • plugins:paytest/README.org: A plugin to benchmark the performance of the pay plugin. It can generate mock invoices for remote nodes, and it can hold on to incoming test multi-part payments as if they were real payments.

  • ZmnSCPxj/payz: Plugin for an alternative to the normal C-Lightning pay algorithm.

  • fiatjaf/trampoline: Trampoline payments plugin for c-lightning.

  • dart-lightning/kraken: Kraken is a plugin for Core Lightning that helps you analyze payment failure and try to procude a suggestion.

UI

  • darosior/lightning-qt: lightning-qt is a Python plugin for C-lightning, a Lightning Network daemon. It enables the use of a bitcoin-qt-like Graphical User Interface (actually, part of the icons and forms have been taken from bitcoin-qt and modified) via the RPC interface.

Watchtower

Others

Resources

  • conscott/c-lightning-plugins: A collection of plugins for c-lightning.

  • jb55/awesome-core-lightning: A list of awesome CLN projects and plugins.

  • lightningd/plugins: Community curated plugins for core-lightning.

  • renepickhardt/c-lightning-plugin-collection: A collection of c-lightning plugins which are ready to use for your lightning network node.

  • rsbondi/clightning-go-plugin: A collection of plugins for use with clightning written in go using glightning:

    • remoteRPC: This plugin allows you to access all RPC commands using HTTP instead of the default of unix socket,

    • stats: Shows some additional stats, currently shows forwarding info by channel, amount earned, percent gain etc..

    • dumpkeys: Export xpriv/xpub,

    • setban: ban peers for specified time.

Videos

Rusty Russell

Christian Decker

Lisa Neigut

Lisa Neigut and Aditya Sharma

Antoine Poinsot

Rene Pickhardt

Kody Low

Sergi Delgado and Conor Okus

  • Deploying an Eye of Satoshi Lightning Watchtower:

    • the deployement of a test network with two CLN nodes and a watchtower using Polar,

    • the installation of The Eye of Satoshi watchtower,

    • the installation of watchtower-client plugin for CLN and

    • some basic interactions between a node and the watchtower.

402 Payment Required

Satoshi N

Vincenzo Palazzo

Shahana Farooqi

  • clnrest Latest Features with Shahana: Become better at controlling your CLN node by using clnrest to its fullest potential. Join Blockstream Front-End Engineer Shahana Farooqi to find out more about recent improvements as well as:

    • clnrest usage in applications

    • rune validation

    • certificate generation

    • configuration options

    • automated tests

Damian

LNROOM

Biweekly live coding sessions - CLN on BOL2

  • Understand CLN Plugin mechanism with a Python example: In this live, we add the method myplugin to Core Lightning by writing a dynamic Python plugin called myplugin.py. Doing this, we try to understand: (1) how startup options are passed to the plugin, (2) how cli parameters are passed to the plugin and (3) how to communicate to the lightning node via JSON-RPC over unix sockets.

  • Register a JSON-RPC method to Core Lightning using pyln-client Python package: In this live, we register a JSON-RPC method in Core Lightning using pyln-client Python package. As pyln-client uses Python decorators to declare JSON-RPC methods, in the second part we try to understand how they work by playing with 2 examples, the second one being very close to the way pyln-client uses them.

  • How to write tests for CLN plugins: In this live, we use pyln-testing Python package to write a test for a simple Core Lightning plugin written with pyln-client Python package. We do it in a TDD style.

  • Learn how to subscribe to lightningd event notifications with CLN plugins: In the first part of this live we write a Python plugin without pyln-client package which subscribes to the notification topics connect and disconnect. A benefit of doing it like this is that it allows us to understand how the system works. Another benefit is that the way we write the plugin can be applied to any other languages. In the second part we do it again with Python but this time using pyln-client package.

  • How Core Lightning plugins can communicate with each other?: In this live we implement a plugin that emits custom notifications foo to lightningd and another plugin which subscribes to those custom notifications foo. We do it with Python only and also with pyln-client package.

  • Core lightning rpc_command hook, pay command and BOLT11 invoice: In this live we write a plugin that limits the amount a node can send (using the builtin pay command) to a BOLT11 invoice. This is possible thanks to Core Lightning hook system and specifically the hook rpc_command.

  • How does Core Lightning communicate with the Bitcoin network?: In this live we install trustedcoin plugin that replaces bitcoind with trusted public explorers. Then we look at lightningd/bitcoind.c file which defines a standardized interface for talking and gathering Bitcoin data using any Bitcoin backend plugin. Finally, we see how trustedcoin uses public Esplora instances to implement the JSON-RPC method getrawblockbyheight.

LNROOM

  • Start writing Core Lightning plugins with pyln-client TODAY!: In this episode, we register a JSON-RPC method in Core Lightning using pyln-client Python package.

  • Overview of pyln-client implementation - Plugin.run() - Part 1: In this episode, we look a pyln-client Python package implementation focusing specifically on the method run of the class Plugin.

  • Overview of pyln-client implementation - @plugin.method() - Part 2: In this episode, we look a pyln-client Python package implementation focusing specifically on the method method of the class Plugin. We write a very simplified version of Method and Plugin classes to understand plugin.method().

  • Overview of pyln-client implementation - LightningRpc - Part 3: In this episode, we look a pyln-client Python package implementation focusing specifically on LightningRpc class. This class implements a RPC client for the lightningd daemon. This RPC client connects to the lightningd daemon through a unix domain socket and passes calls through.

  • Understand CLN Plugin mechanism with a Bash example: In this live, we add the method mymethod to Core Lightning by writing a dynamic Bash plugin called myplugin.bash. Doing this, we try to understand: (1) how startup options are passed to the plugin, (2) how cli parameters are passed to the plugin and (3) how to communicate to the lightning node via JSON-RPC over unix sockets.

  • Subscribe to lightningd notification topics with a Python plugin: In this episode we write a Python plugin without pyln-client package which subscribes to the notification topics connect and disconnect. A benefit of doing it like this is that it allows us to understand how the system works.

  • Subscribe to connect notifications with pyln-client: In this episode we write a Python plugin with pyln-client package which subscribes to the notification topics connect and invoice_creation.

  • Write a Core Lightning plugin in Javascript: In this episode, we write a Core Lightning plugin in Javascript that registers a JSON-RPC method. To do so we use clightningjs Javascript package.

  • Write a Core Lightning plugin in Go: In this episode, we write a Core Lightning plugin in go that registers a JSON-RPC method. To do so we use lightningd-gjson-rpc Go module.

  • Write a Core Lightning plugin in Rust: In this episode, we write a Core Lightning plugin in Rust that registers a JSON-RPC method. To do so we use cln-plugin and cln-rpc Rust crates.

  • Getting started with CLNRest plugin: In this live we see how to start and use the new builtin plugin CLNRest that transforms RPC calls into a REST service. We learn how to use the Swagger interface to generate/send http requests. Then we connect to the websocket offered by CLNRest that sends lightningd notification. Finally, we take a look at CLNRest implementation to show how plugin developers can take advantage of the new JSON RPC method checkrune.

  • Get started with cln-grpc plugin: In this live we continue our tour about Core Lightning remote control with the builtin plugin cln-grpc. We write a Python application which generates invoices on our CLN node using the gRPC protocol.

Short clips

Learning

  • Lightning: BOLTs in a flash by Base58: Want to really understand how lightning works? Join us for an in-depth and hands on, project based investigation of building lightning channels, making payments, finding routes, and making onions. By the end of this class you'll have implemented a hodl-invoice plugin, bolt11 invoice decoder, an onion packager, and a routing algorithm that can parse through gossip to find a route. [...] We'll use Core Lightning Plugins to manually HODL invoices, build onions for routes, and understand gossip messages.

Articles

  • Five plugins every node runner should know: CLN is awesome because out of the box it's a minimal yet high-performance LN node implementation that is customizable with its plugin architecture. Plugins allow you to easily add features to your CLN node such as a watchtower, autopilot, and various other quality of life improvements that make your life as a node op easier. Here are five plugins every node operator should know

  • Plugging into c-lightning: the future of lightning plugins is bright: [...]_In contrast, c-lightning offers a third way. It maintains a robust and secure core that is designed to not be tweaked or replaced by the developer. Flexibility and additional functionality is available through the use of plugins that can be written by the developer in various languages such as Python or Go. The aim is for the c-lightning ecosystem to emerge as a testbed for experimenting with new cutting edge features, previously the terrain of other implementations such as lnd and eclair, without sacrificing the performance and robustness of the core.

  • Run c-lightning in a light and resilient way: If you are here, means that you are searching for a light method to run a lightning node with c-lightning, and possibly in a reliant way.