loopd

package
v0.28.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 61 Imported by: 2

Documentation

Index

Constants

View Source
const Subsystem = "LOOPD"

Variables

View Source
var (
	// LoopDirBase is the default main directory where loop stores its data.
	LoopDirBase = btcutil.AppDataDir("loop", false)

	// DefaultNetwork is the default bitcoin network loop runs on.
	DefaultNetwork = "mainnet"

	// DefaultTLSCertFilename is the default file name for the autogenerated
	// TLS certificate.
	DefaultTLSCertFilename = "tls.cert"

	// DefaultTLSKeyFilename is the default file name for the autogenerated
	// TLS key.
	DefaultTLSKeyFilename = "tls.key"

	// DatabaseBackendSqlite is the name of the SQLite database backend.
	DatabaseBackendSqlite = "sqlite"

	// DatabaseBackendPostgres is the name of the Postgres database backend.
	DatabaseBackendPostgres = "postgres"

	// DefaultLndMacaroonPath is the default mainnet admin macaroon path of
	// LND.
	DefaultLndMacaroonPath = filepath.Join(
		btcutil.AppDataDir("lnd", false),
		"data", "chain", "bitcoin", DefaultNetwork,
		defaultLndMacaroon,
	)

	// DefaultTLSCertPath is the default full path of the autogenerated TLS
	// certificate.
	DefaultTLSCertPath = filepath.Join(
		LoopDirBase, DefaultNetwork, DefaultTLSCertFilename,
	)

	// DefaultTLSKeyPath is the default full path of the autogenerated TLS
	// key.
	DefaultTLSKeyPath = filepath.Join(
		LoopDirBase, DefaultNetwork, DefaultTLSKeyFilename,
	)

	// DefaultMacaroonFilename is the default file name for the
	// autogenerated loop macaroon.
	DefaultMacaroonFilename = "loop.macaroon"

	// DefaultMacaroonPath is the default full path of the base loop
	// macaroon.
	DefaultMacaroonPath = filepath.Join(
		LoopDirBase, DefaultNetwork, DefaultMacaroonFilename,
	)

	// DefaultAutogenValidity is the default validity of a self-signed
	// certificate in number of days.
	DefaultAutogenValidity = 365 * 24 * time.Hour
)
View Source
var (
	// LoopMinRequiredLndVersion is the minimum required version of lnd that
	// is compatible with the current version of the loop client. Also all
	// listed build tags/subservers need to be enabled.
	LoopMinRequiredLndVersion = &verrpc.Version{
		AppMajor: 0,
		AppMinor: 17,
		AppPatch: 0,
		BuildTags: []string{
			"signrpc", "walletrpc", "chainrpc", "invoicesrpc",
		},
	}
)

Functions

func Run

func Run(rpcCfg RPCConfig) error

Run starts the loop daemon and blocks until it's shut down again.

func SetupLoggers

func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor)

SetupLoggers initializes all package-global logger variables.

func ToClientReservations

func ToClientReservations(
	res []*reservation.Reservation) []*clientrpc.ClientReservation

ToClientReservations converts a slice of server reservations to a slice of client reservations.

func Validate

func Validate(cfg *Config) error

Validate cleans up paths in the config provided and validates it.

Types

type Config

type Config struct {
	ShowVersion bool   `long:"version" description:"Display version information and exit"`
	Network     string `long:"network" description:"network to run on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"`
	RPCListen   string `long:"rpclisten" description:"Address to listen on for gRPC clients"`
	RESTListen  string `long:"restlisten" description:"Address to listen on for REST clients"`
	CORSOrigin  string `long:"corsorigin" description:"The value to send in the Access-Control-Allow-Origin header. Header will be omitted if empty."`

	LoopDir    string `` /* 166-byte string literal not displayed */
	ConfigFile string `long:"configfile" description:"Path to configuration file."`
	DataDir    string `long:"datadir" description:"Directory for loopdb."`

	DatabaseBackend string                 `` /* 134-byte string literal not displayed */
	Sqlite          *loopdb.SqliteConfig   `group:"sqlite" namespace:"sqlite"`
	Postgres        *loopdb.PostgresConfig `group:"postgres" namespace:"postgres"`

	TLSCertPath        string        `long:"tlscertpath" description:"Path to write the TLS certificate for loop's RPC and REST services."`
	TLSKeyPath         string        `long:"tlskeypath" description:"Path to write the TLS private key for loop's RPC and REST services."`
	TLSExtraIPs        []string      `long:"tlsextraip" description:"Adds an extra IP to the generated certificate."`
	TLSExtraDomains    []string      `long:"tlsextradomain" description:"Adds an extra domain to the generated certificate."`
	TLSAutoRefresh     bool          `long:"tlsautorefresh" description:"Re-generate TLS certificate and key if the IPs or domains are changed."`
	TLSDisableAutofill bool          `` /* 174-byte string literal not displayed */
	TLSValidity        time.Duration `long:"tlsvalidity" description:"Loop's TLS certificate validity period in days. Defaults to 8760h (1 year)"`

	MacaroonPath string `long:"macaroonpath" description:"Path to write the macaroon for loop's RPC and REST services if it doesn't exist."`

	LogDir         string `long:"logdir" description:"Directory to log output."`
	MaxLogFiles    int    `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)."`
	MaxLogFileSize int    `long:"maxlogfilesize" description:"Maximum logfile size in MB."`

	DebugLevel  string `` /* 265-byte string literal not displayed */
	MaxLSATCost uint32 `` /* 148-byte string literal not displayed */
	MaxLSATFee  uint32 `long:"maxlsatfee" description:"Maximum routing fee in satoshis that we are willing to pay while paying for an LSAT token."`

	LoopOutMaxParts uint32 `long:"loopoutmaxparts" description:"The maximum number of payment parts that may be used for a loop out swap."`

	TotalPaymentTimeout time.Duration `long:"totalpaymenttimeout" description:"The timeout to use for off-chain payments."`
	MaxPaymentRetries   int           `long:"maxpaymentretries" description:"The maximum number of times an off-chain payment may be retried."`

	EnableExperimental bool `long:"experimental" description:"Enable experimental features: reservations"`

	Lnd *lndConfig `group:"lnd" namespace:"lnd"`

	Server *loopServerConfig `group:"server" namespace:"server"`

	View viewParameters `` /* 131-byte string literal not displayed */
}

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns all default values for the Config struct.

type Daemon

type Daemon struct {

	// ErrChan is an error channel that users of the Daemon struct must use
	// to detect runtime errors and also whether a shutdown is fully
	// completed.
	ErrChan chan error
	// contains filtered or unexported fields
}

Daemon is the struct that holds one instance of the loop client daemon.

func New

func New(config *Config, lisCfg *ListenerCfg) *Daemon

New creates a new instance of the loop client daemon.

func (*Daemon) AbandonSwap

func (s *Daemon) AbandonSwap(ctx context.Context,
	req *clientrpc.AbandonSwapRequest) (*clientrpc.AbandonSwapResponse,
	error)

AbandonSwap requests the server to abandon a swap with the given hash.

func (*Daemon) GetInfo

func (s *Daemon) GetInfo(ctx context.Context,
	_ *clientrpc.GetInfoRequest) (*clientrpc.GetInfoResponse, error)

GetInfo returns basic information about the loop daemon and details to swaps from the swap store.

func (*Daemon) GetLiquidityParams

func (s *Daemon) GetLiquidityParams(_ context.Context,
	_ *clientrpc.GetLiquidityParamsRequest) (*clientrpc.LiquidityParameters,
	error)

GetLiquidityParams gets our current liquidity manager's parameters.

func (*Daemon) GetLoopInQuote

func (s *Daemon) GetLoopInQuote(ctx context.Context,
	req *clientrpc.QuoteRequest) (*clientrpc.InQuoteResponse, error)

GetLoopInQuote returns a quote for a swap with the provided parameters.

func (*Daemon) GetLoopInTerms

func (s *Daemon) GetLoopInTerms(ctx context.Context,
	_ *clientrpc.TermsRequest) (*clientrpc.InTermsResponse, error)

GetLoopInTerms returns the terms that the server enforces for swaps.

func (*Daemon) GetLsatTokens

func (s *Daemon) GetLsatTokens(ctx context.Context,
	_ *clientrpc.TokensRequest) (*clientrpc.TokensResponse, error)

GetLsatTokens returns all tokens that are contained in the LSAT token store.

func (*Daemon) InstantOut

func (s *Daemon) InstantOut(ctx context.Context,
	req *clientrpc.InstantOutRequest) (*clientrpc.InstantOutResponse,
	error)

InstantOut initiates an instant out swap.

func (*Daemon) InstantOutQuote

func (s *Daemon) InstantOutQuote(ctx context.Context,
	req *clientrpc.InstantOutQuoteRequest) (
	*clientrpc.InstantOutQuoteResponse, error)

InstantOutQuote returns a quote for an instant out swap with the provided parameters.

func (*Daemon) ListInstantOuts

func (s *Daemon) ListInstantOuts(ctx context.Context,
	_ *clientrpc.ListInstantOutsRequest) (
	*clientrpc.ListInstantOutsResponse, error)

ListInstantOuts returns a list of all currently known instant out swaps and their current status.

func (*Daemon) ListReservations

func (s *Daemon) ListReservations(ctx context.Context,
	_ *clientrpc.ListReservationsRequest) (
	*clientrpc.ListReservationsResponse, error)

ListReservations lists all existing reservations the client has ever made.

func (*Daemon) ListSwaps

func (s *Daemon) ListSwaps(_ context.Context,
	req *clientrpc.ListSwapsRequest) (*clientrpc.ListSwapsResponse, error)

ListSwaps returns a list of all currently known swaps and their current status.

func (*Daemon) LoopIn

func (s *Daemon) LoopIn(ctx context.Context,
	in *clientrpc.LoopInRequest) (*clientrpc.SwapResponse, error)

func (*Daemon) LoopOut

func (s *Daemon) LoopOut(ctx context.Context,
	in *clientrpc.LoopOutRequest) (
	*clientrpc.SwapResponse, error)

LoopOut initiates a loop out swap with the given parameters. The call returns after the swap has been set up with the swap server. From that point onwards, progress can be tracked via the LoopOutStatus stream that is returned from Monitor().

func (*Daemon) LoopOutQuote

func (s *Daemon) LoopOutQuote(ctx context.Context,
	req *clientrpc.QuoteRequest) (*clientrpc.OutQuoteResponse, error)

LoopOutQuote returns a quote for a loop out swap with the provided parameters.

func (*Daemon) LoopOutTerms

func (s *Daemon) LoopOutTerms(ctx context.Context,
	_ *clientrpc.TermsRequest) (*clientrpc.OutTermsResponse, error)

LoopOutTerms returns the terms that the server enforces for loop out swaps.

func (*Daemon) Monitor

func (s *Daemon) Monitor(in *clientrpc.MonitorRequest,
	server clientrpc.SwapClient_MonitorServer) error

Monitor will return a stream of swap updates for currently active swaps.

func (*Daemon) Probe

func (s *Daemon) Probe(ctx context.Context,
	req *clientrpc.ProbeRequest) (*clientrpc.ProbeResponse, error)

Probe requests the server to probe the client's node to test inbound liquidity.

func (*Daemon) SetLiquidityParams

SetLiquidityParams attempts to set our current liquidity manager's parameters.

func (*Daemon) Start

func (d *Daemon) Start() error

Start starts loopd in daemon mode. It will listen for grpc connections, execute commands and pass back swap status information.

func (*Daemon) StartAsSubserver

func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
	withMacaroonService bool) error

StartAsSubserver is an alternative to Start where the RPC server does not 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 register to an existing one.

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop tries to gracefully shut down the daemon. A caller needs to wait for a message on the main error channel indicating that the shutdown is completed.

func (*Daemon) SuggestSwaps

func (s *Daemon) SuggestSwaps(ctx context.Context,
	_ *clientrpc.SuggestSwapsRequest) (*clientrpc.SuggestSwapsResponse, error)

SuggestSwaps provides a list of suggested swaps based on lnd's current channel balances and rules set by the liquidity manager.

func (*Daemon) SwapInfo

func (s *Daemon) SwapInfo(_ context.Context,
	req *clientrpc.SwapInfoRequest) (*clientrpc.SwapStatus, error)

SwapInfo returns all known details about a single swap.

func (*Daemon) ValidateMacaroon

func (d *Daemon) ValidateMacaroon(ctx context.Context,
	requiredPermissions []bakery.Op, fullMethod string) error

ValidateMacaroon extracts the macaroon from the context's gRPC metadata, checks its signature, makes sure all specified permissions for the called method are contained within and finally ensures all caveat conditions are met. A non-nil error is returned if any of the checks fail. This method is needed to enable loopd running as an external subserver in the same process as lnd but still validate its own macaroons.

type ListenerCfg

type ListenerCfg struct {
	// contains filtered or unexported fields
}

ListenerCfg holds closures used to retrieve listeners for the gRPC services.

func NewListenerConfig

func NewListenerConfig(config *Config, rpcCfg RPCConfig) *ListenerCfg

NewListenerConfig creates and returns a new listenerCfg from the passed config and RPCConfig.

type RPCConfig

type RPCConfig struct {
	// RPCListener is an optional listener that if set will override the
	// daemon's gRPC settings, and make the gRPC server listen on this
	// listener.
	// Note that setting this will also disable REST.
	RPCListener net.Listener

	// LndConn is an optional connection to an lnd instance. If set it will
	// override the TCP connection created from daemon's config.
	LndConn net.Conn
}

RPCConfig holds optional options that can be used to make the loop daemon communicate on custom connections.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL