Merge pull request #428 from lightninglabs/macaroon-stateless

Macaroon stateless
pull/431/head
Oliver Gugger 3 years ago committed by GitHub
commit 7c4d8f601e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,7 +131,7 @@ func (d *Daemon) Start() error {
// server client, the swap client RPC server instance and our main swap // server client, the swap client RPC server instance and our main swap
// and error handlers. If this fails, then nothing has been started yet // and error handlers. If this fails, then nothing has been started yet
// and we can just return the error. // and we can just return the error.
err = d.initialize() err = d.initialize(true)
if errors.Is(err, bbolt.ErrTimeout) { if errors.Is(err, bbolt.ErrTimeout) {
// We're trying to be started as a standalone Loop daemon, most // We're trying to be started as a standalone Loop daemon, most
// likely LiT is already running and blocking the DB // likely LiT is already running and blocking the DB
@ -163,7 +163,9 @@ func (d *Daemon) Start() error {
// create its own gRPC server but registers to an existing one. The same goes // create its own gRPC server but registers to an existing one. The same goes
// for REST (if enabled), instead of creating an own mux and HTTP server, we // for REST (if enabled), instead of creating an own mux and HTTP server, we
// register to an existing one. // register to an existing one.
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error { func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
createDefaultMacaroonFile bool) error {
// There should be no reason to start the daemon twice. Therefore return // There should be no reason to start the daemon twice. Therefore return
// an error if that's tried. This is mostly to guard against Start and // an error if that's tried. This is mostly to guard against Start and
// StartAsSubserver both being called. // StartAsSubserver both being called.
@ -179,7 +181,7 @@ func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error {
// the swap server client, the RPC server instance and our main swap // the swap server client, the RPC server instance and our main swap
// handlers. If this fails, then nothing has been started yet and we can // handlers. If this fails, then nothing has been started yet and we can
// just return the error. // just return the error.
err := d.initialize() err := d.initialize(createDefaultMacaroonFile)
if errors.Is(err, bbolt.ErrTimeout) { if errors.Is(err, bbolt.ErrTimeout) {
// We're trying to be started inside LiT so there most likely is // We're trying to be started inside LiT so there most likely is
// another standalone Loop process blocking the DB. // another standalone Loop process blocking the DB.
@ -339,7 +341,7 @@ func (d *Daemon) startWebServers() error {
// the swap client RPC server instance and our main swap and error handlers. If // the swap client RPC server instance and our main swap and error handlers. If
// this method fails with an error then no goroutine was started yet and no // this method fails with an error then no goroutine was started yet and no
// cleanup is necessary. If it succeeds, then goroutines have been spawned. // cleanup is necessary. If it succeeds, then goroutines have been spawned.
func (d *Daemon) initialize() error { func (d *Daemon) initialize(createDefaultMacaroonFile bool) error {
// If no swap server is specified, use the default addresses for mainnet // If no swap server is specified, use the default addresses for mainnet
// and testnet. // and testnet.
if d.cfg.Server.Host == "" { if d.cfg.Server.Host == "" {
@ -370,7 +372,7 @@ func (d *Daemon) initialize() error {
// Start the macaroon service and let it create its default macaroon in // Start the macaroon service and let it create its default macaroon in
// case it doesn't exist yet. // case it doesn't exist yet.
err = d.startMacaroonService() err = d.startMacaroonService(createDefaultMacaroonFile)
if err != nil { if err != nil {
// The client is the only thing we started yet, so if we clean // The client is the only thing we started yet, so if we clean
// up its connection now, nothing else needs to be shut down at // up its connection now, nothing else needs to be shut down at

@ -151,7 +151,7 @@ var (
// unlocks the macaroon database and creates the default macaroon if it doesn't // unlocks the macaroon database and creates the default macaroon if it doesn't
// exist yet. If macaroons are disabled in general in the configuration, none of // exist yet. If macaroons are disabled in general in the configuration, none of
// these actions are taken. // these actions are taken.
func (d *Daemon) startMacaroonService() error { func (d *Daemon) startMacaroonService(createDefaultMacaroonFile bool) error {
var err error var err error
d.macaroonDB, err = kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{ d.macaroonDB, err = kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{
DBPath: d.cfg.DataDir, DBPath: d.cfg.DataDir,
@ -184,8 +184,11 @@ func (d *Daemon) startMacaroonService() error {
return fmt.Errorf("unable to unlock macaroon DB: %v", err) return fmt.Errorf("unable to unlock macaroon DB: %v", err)
} }
// Create macaroon files for loop CLI to use if they don't exist. // There are situations in which we don't want a macaroon to be created
if !lnrpc.FileExists(d.cfg.MacaroonPath) { // on disk (for example when running inside LiT stateless integrated
// mode). For any other cases, we create macaroon files for the loop CLI
// in the default directory.
if createDefaultMacaroonFile && !lnrpc.FileExists(d.cfg.MacaroonPath) {
// We don't offer the ability to rotate macaroon root keys yet, // We don't offer the ability to rotate macaroon root keys yet,
// so just use the default one since the service expects some // so just use the default one since the service expects some
// value to be set. // value to be set.

Loading…
Cancel
Save