We add regular channel event pruning, as otherwise the database may get
filled quickly. We add two mechanisms, a retention time and a max events
number. Both can be turned on individually.
Threads the chanevents.Store the daemon already constructs into the
frdrpcserver.Config so the upcoming GetChannelEvents handler has a
read path. Both standalone and subserver startup wire the same store
instance.
Refine the Faraday struct's lifecycle management:
- Use atomic.Bool for cleaner start/stop guards with CompareAndSwap
instead of the old atomic.AddInt32 pattern.
- Extract initialize() to consolidate macaroon and bitcoin client setup
shared between Start() and StartAsSubserver().
- Extract startRPCServer()/stopRPCServer() from the monolithic
Start()/Stop() methods for better separation of concerns.
- Use the lndOwned flag so Stop() only closes the lnd connection in
standalone mode, leaving it open for the parent in subserver mode.
- Move lnd connection and bitcoin client creation from Main() into the
Faraday struct so callers only need New() and Start().
- Mark the struct as permanently stopped on Start failure to prevent
retry with stale internal state. Guard startRPCServer against a nil
macaroon service.
- Reorder Stop() to wait for in-flight RPC goroutines before tearing
down the macaroon service.
Move the gRPC/REST server lifecycle, macaroon service management, and
TLS setup from frdrpcserver.RPCServer to a new Faraday struct in the
faraday package. This leaves RPCServer as a pure RPC request handler
with only business logic methods.
The Faraday struct embeds *frdrpcserver.RPCServer and takes ownership
of all infrastructure concerns: gRPC/REST server creation, macaroon
service setup, TLS configuration, and start/stop lifecycle. The
frdrpcserver.Config is slimmed down to just Lnd and BitcoinClient.
The macaroons.go file is also moved from frdrpcserver to the faraday
package, as the macaroon constants are now used by the Faraday struct
directly.
To avoid the frdrpc package having dependencies to other libraries and
making using the JSON/WASM stubs hard, we extract all the business logic
and RPC server code into its own package called frdrpcserver.
We need to move the call that sets all log levels out of the config
validation. Otherwise this will overwrite all subsystem log levels in
LiT where we call the faraday.ValidateConfig() function but have already
set up our loggers.
At the same time we remove the unnecessary global logWriter variable.
Fixes#84.
Allows faraday to only use the readonly.macaroon (or a custom baked one)
to connect to lnd instead of needing to copy all macaroons (including
the subserver ones).
To make it easier to use faraday as an external subserver, it is
necessary to extract the config validation into its own function that is
separate from loading the config.
We update to the newest verion of lnd so we can use the updated macaroon
service.
NOTE: This is a compile time dependency update only, no RPC level update
is required.
As a preparation to start the gRPC server using TLS, we make sure the
certificate is created and loaded correctly before starting the server
itself.
We also need to silence the linter that complains about the struct
alignment because we didn't put all boolean variables to the beginning.
But since this struct will only be loaded once per process we care more
about similar options being grouped than memory efficiency.
To make the command line interface a bit more similar to other tools
like loop, we switch from using single flags like --testnet or --regtest
to just one --network flag.
As a preparation to add TLS to faraday itself, we need to move the
parameters that are meant for lnd into its own sub struct to avoid name
collisions and user confusion.
Previously, if we generated a report while a channel was pending open
or close, it would not have been picked up as a channel. This change
adds pending channels and simplifies our on chain sorting to just have
opened and closed channels (independent of the source where we got the
channel information).
We are going to need the walletkit and chainnotifier subservers in
future changes, so we make the switch now. Note that this commit does
not build, and is split up for the sake of easy review.