5.7 KiB
Code Generation
The CLN project has a multitude of interfaces, most of which are generated from an abstract schema:
-
Wire format for peer-to-peer communication: this is the binary format that is specific by the LN spec. It uses the generate-wire.py script to parse the (faux) CSV files that are automatically extrated from the specification and writes C source code files that are then used internally to encode and decode messages, as well as provide print functions for the messages.
-
Wire format for inter-daemon communication: CLN follows a multi-daemon architecture, making communication explicit across daemons. For this inter-daemon communication we use a slightly altered message format from the LN spec. The changes are 1) addition of FD passing semantics to allow establishing a new connection between daemons (communication uses socketpairs, so no
connect
), and 2) change the message length prefix fromu16
tou32
, allowing for messages larger than 65Kb. The CSV files are with the respective sub-daemon and also use generate-wire.py to generate encoding, decoding and printing functions. -
We describe the JSON-RPC using JSON Schema in the
doc/schemas
directory. Each method has a.request.json
for the request message, and a.schema.json
for the response (the mismatch is historical and will eventually be addressed). During tests thepytest
target will verify responses, however the JSON-RPC methods are not generated (yet?). We do generate various client stubs for languages, using themsggen
tool. More on the generated stubs and utilities below.
Man pages
The manpages are partially generated from the JSON schemas
using the fromschema
tool. It reads the request schema
and fills in the manpage between two markers:
[comment]: # (GENERATE-FROM-SCHEMA-START)
...
[comment]: # (GENERATE-FROM-SCHEMA-END)
!!! note
Some of this functionality overlaps with [`msggen`][msggen] (parsing the Schemas)
and [blockreplace.py][blockreplace.py] (filling in the template). It
is likely that this will eventually be merged.
msggen
msggen
is used to generate JSON-RPC client stubs, and converters
between in-memory formats and the JSON format. In addition, by
chaining some of these we can expose a grpc interface that
matches the JSON-RPC interface. This conversion chain is implemented
in the grpc-plugin