As of 14/03/2022 (chain tip hash : 00000000000000000000628002621832be9281faf72c394e66a8bc8446f80c75), this project is under implementation in separate process relying on the multiprocess framework. See https://github.com/chaincodelabs/libmultiprocess/issues/56 for more information on current state.
This PR proposes to introduce a new subsystem aiming towards providing a generic framework for integrating alternative transport communication channels inside Bitcoin Core. This PR is a functional proof-of-concept using LN transport protocol as a new link layer for header fetching. See #18989 for high-level discussion and proposal merits.
The Design
Previous work has been attempted to increase network security and robustness by increasing communication redundancy. While being optional and fault-tolerant, these attempt don’t scale well to integrate a wide-range of alternatives such as domain-fronting, orbital communications, amateur radio, Tor pluggable transports, unlicensed UHF, Bluetooth, I2P, Lightning Noise transport, … Each of these transports has its own availability, latency, don’t bind to the Berkeley sockets model, are unidirectional, require custom peer discovery, are not suited for block traffic, …
This proposal tries to overcome these issues by laying out a generic “driver” framework with its own new processing stack, thereby encapsulating per-transport oddities. It introduces:
- Per-transport capabilities (
TransportCapabilities
). Originally declared by each driver, they abstract driver specifities to general flags, like directionality, protocol messages scope. They could be extended with further attributes, like max bandwidth for adjusted packing or “privacy”/“trustness” niceness of the link. - Abstract driver model (
CDriver
). Basically, it dissociate driver warmup, message preprocessing, sending and reception. Ideally you would want to load them dynamically. - “Anycast” header-fetching (
AltLogicValidation::BlockHeaderAnomalie
). After notification from the watchdog module, it sends aGETHEADERS
message to any peers supporting bidirectionality and headers processing. - Alternative processing stack (
AltLogicValidation
). Relying on its own threads, it manages drivers and may take action based on static logical capabilites instead of peer state, reducing likelihood of bugs. In the future, one could implement a more robust headers-syncing strategy like reverse-header or compressed headers. It may also leverage a future asynchronous validation interface.
There are many advantages of this kind of design –, it is easy to integrate new drivers binding to an abstract class, it is easy to reason about due to logical capabilities and at the same time provides granular tuning due to the fine-integration with rpc. Peer discovery and policy or bandwidth/memory DoS-protection are all possible driver add-ons as well. One could envision an rpc like sendemergencytx
, broadcasting a transaction on any transport protocol available, like a LN’s justice transaction after detection of being eclipsed.
This module could be made entirely optional at compile-time with --enable-altnet
even if such integration with the build system hasn’t been made.
Obviously this is an exploratory PoC, I don’t expect code here to be merged. Beyond worthiness of doing this in Rust there are a lot of open questions, including the threading/memory model, interface with existing codebase, build system, resources consumption and fault-tolerance. As next steps, I would favor building on the multiprocess work and hosting this new network stack in its own to avoid any bug contamination from introducing complex driver. I encourage those with opinions on the higher level motivation and design discussion to leave their ideas on the linked issue.
High-level design:
___________ ______________________
| | | |
| CWatchdog |----------| AltLogicValidation |
|___________| |______________________|
|
______|______
| |
| CAltstack |
|_____________|
|
____|____
| |
| CDriver |
|_________|
|
________|__________
| |
| ClightningDriver |
|__________________|
The Demo
This PoC features a header-fetching round-trip, leveraging LN connection protocol. Each LN node connects to its peers through an encrypted and authenticated channel. Since your LN peer must have chain access, you could leverage this privileged link to create a redundant chain access.
Using C-lightning custom LN message support and plugin API, we could embed directly inside HEADERS
/GETHEADERS
and realize a round-trip between 2 disconnected bitcoin nodes through their respective C-lightning nodes.
For this to work, you need to compile and run 2 C-lightning nodes, each with its own data directory and launched with this custom bridge plugin. Once those LN nodes are running, activate bridges by lightning-cli alice_on
and lightning-cli bob_on
. The plugin doesn’t seem to accept CLI argument so I had to hardcode some node addresses.
Then compile 2 bitcoin nodes with this patchset. For one of them you must change the hardcoded port in C-lightning driver and deactivate the watchdog logic. Also, it would be best if you changed SCAN_INTERVAL
to something reasonable, for instance 1 min.
High-level setup:
-->
__________ LN_msg(`GETHEADERS`) ________
| | | |
| CL-Alice |-----------------------------------------------| CL-Bob |
|__________| |________|
| LN_msg(`HEADERS`) |
____|_____ ___|_____
| | <-- | |
| bridge | | bridge |
|__________| |_________|
| |
____|_____ ___|____
| | | |
| BC-Alice | | BC-Bob |
|__________| |________|
HEIGHT HEIGH + 1
Running both nodes, they should automatically connect to the bridge, and after anomaly detection realize a header exchange, if one of them is at least one block forward (run generatetoaddress 1 $ADDR
).
Otherwise you may observe past logs:
Alice:
0Ê0-05-16T00:55:11Z Boostrapping Altstack
12020-05-16T00:55:11Z init message: Done loading
22020-05-16T00:55:11Z msghand thread start
32020-05-16T00:55:11Z drivers-warmup thread start
42020-05-16T00:55:11Z addcon thread start
52020-05-16T00:55:11Z Registered driver with 0
62020-05-16T00:55:11Z net thread start
72020-05-16T00:55:11Z altstack-processing thread start
82020-05-16T00:55:11Z Clightning - Warmup
92020-05-16T00:55:11Z dnsseed thread start
102020-05-16T00:55:11Z altstack-handle thread start
112020-05-16T00:55:11Z 0 addresses found from DNS seeds
122020-05-16T00:55:11Z dnsseed thread exit
132020-05-16T00:55:11Z Clightning - Bridge connection
142020-05-16T00:55:11Z Registering node_id 0 with driver_id 0
152020-05-16T00:55:11Z drivers-warmup thread exit
162020-05-16T00:55:16Z Block header anomalie detected - notifying subscribers
172020-05-16T00:55:16Z Block header anomalie detected - Anycasting header fetching from 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
182020-05-16T00:55:16Z Clightning - Preprocessing getheader
192020-05-16T00:55:16Z Cligthning - Bridge send success 71
202020-05-16T00:55:19Z Cligtning - Bridge receive success
212020-05-16T00:55:19Z Receive HEADERS from 0
222020-05-16T00:55:19Z Receiver header 65084efeaffe9929de0a0bb747cf48ac7f9b4edb214b2d1ad2ea468977be8e1e vs tip 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
Bob:
02020-05-16T00:55:09Z Boostrapping Altstack
12020-05-16T00:55:09Z addcon thread start
22020-05-16T00:55:09Z opencon thread start
32020-05-16T00:55:09Z msghand thread start
42020-05-16T00:55:09Z drivers-warmup thread start
52020-05-16T00:55:09Z Registered driver with 0
62020-05-16T00:55:09Z Clightning - Warmup
72020-05-16T00:55:09Z init message: Done loading
82020-05-16T00:55:09Z dnsseed thread exit
92020-05-16T00:55:09Z altstack-processing thread start
102020-05-16T00:55:09Z altstack-handle thread start
112020-05-16T00:55:09Z Clightning - Bridge connection
122020-05-16T00:55:09Z Registering node_id 0 with driver_id 0
132020-05-16T00:55:09Z drivers-warmup thread exit
142020-05-16T00:55:10Z Leaving InitialBlockDownload (latching to false)
152020-05-16T00:55:17Z Cligtning - Bridge receive success
162020-05-16T00:55:17Z Receive GETHEADERS from 0
172020-05-16T00:55:17Z Fetch header starting from 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206, tip 65084efeaffe9929de0a0bb747cf48ac7f9b4edb214b2d1ad2ea468977be8e1e
182020-05-16T00:55:17Z Sending back 1 headers
192020-05-16T00:55:17Z Clightning - Preprocessing header
202020-05-16T00:55:17Z Cligthning - Bridge send success 84
212020-05-16T00:56:10Z Adding fixed seed nodes as DNS doesn't seem to be available.