CLN's Plugin Architecture
C-Lightning (CLN) is a piece of software that allows your computer to communicate with bitcoin's lightning network... it's a lightning node. The team there has made a way for anyone to add custom functionality to their own node. This custom functionality is known as a plugin.
Running CLN
First, you will need to install the software. I recommend building from source, but all instructions can be found here.
Once installed, you can start your node with the lightningd
command.
RPC Methods
CLN comes with a nice CLI that is used by running the lightning-cli
command. From here, you are able to access all of the JSON RPC methods exposed by CLN.
This is where it starts to get fun. Many RPC methods that can be used with your node are plugins. You can view the list of plugins here. There are also a bunch of community plugins you can use for added functionality.
For example, keysend
is a method that can be used to send an unspecified amount of funds to another node using their node pubkey. Keysend is just a plugin and can be viewed here.
How Plugins Work
"A plugin may be written in any language, and communicates with lightningd
through the plugin's stdin
and stdout
." - CLN docs
Get Manifest
When a plugin is started, it gets registered with `lightningd` through the getmanifest
request. This request gets sent to your plugin's standard input (stdin) and a response is expected from the plugin's standard output (stdout).
The getmanifest
request looks something like this:
{
"jsonrpc": "2.0",
"id": 86,
"method": "getmanifest",
"params": {
"allow-deprecated-apis": false
}
}
And the expected response looks something like this:
{
"jsonrpc": "2.0",
"id": req_id,
"result": {
"dynamic": True,
"options": [{
"name": "foo_opt",
"type": "string",
"default": "bar",
"description": "description"
}],
"rpcmethods": [{
"name": "myplugin",
"usage": "",
"description": "description"
}]
}
}
Init
After getmanifest
, lightningd
will send the init request. This request provides important information about the node such as the lightning-dir
used for accessing RPC methods.
The expected response to the init
request looks like:
{
"jsonrpc": "2.0",
"id": req_id,
"result": {}
}
Input Output Communication
Once the plugin is registered by lightningd
, the input-output loop can start. Whenever a method defined in the plugin is called, lightningd
will send that request to the plugin's stdin and will receive and response through the plugin's stdout.
Conclusion
Plugins are subprocesses of the lightning daemon. Much of the out-of-box functionality in CLN is included as plugins, but any user is free to add plugins of their choosing.
This plugin architecture allows for a rich set of features to exist on CLN and is why we decided to implement BOLT 12 prisms as a CLN plugin.
Like this content? Tip its author: