node

package
v0.18.3-beta.rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ListenerFormat is the format string that is used to generate local
	// listener addresses.
	ListenerFormat = "127.0.0.1:%d"

	// DefaultCSV is the CSV delay (remotedelay) we will start our test
	// nodes with.
	DefaultCSV = 4
)

Variables

This section is empty.

Functions

func CheckChannelPolicy

func CheckChannelPolicy(policy, expectedPolicy *lnrpc.RoutingPolicy) error

CheckChannelPolicy checks that the policy matches the expected one.

func CopyFile

func CopyFile(dest, src string) error

CopyFile copies the file src to dest.

func ExtraArgsEtcd

func ExtraArgsEtcd(etcdCfg *etcd.Config, name string, cluster bool,
	leaderSessionTTL int) []string

ExtraArgsEtcd returns extra args for configuring LND to use an external etcd database (for remote channel DB and wallet DB).

func GetBtcdBinary

func GetBtcdBinary() string

GetBtcdBinary returns the full path to the binary of the custom built btcd executable or an empty string if none is set.

func GetLogDir

func GetLogDir() string

GetLogDir returns the passed --logdir flag or the default value if it wasn't set.

Types

type BackendConfig

type BackendConfig interface {
	// GenArgs returns the arguments needed to be passed to LND at startup
	// for using this node as a chain backend.
	GenArgs() []string

	// ConnectMiner is called to establish a connection to the test miner.
	ConnectMiner() error

	// DisconnectMiner is called to disconnect the miner.
	DisconnectMiner() error

	// Name returns the name of the backend type.
	Name() string

	// Credentials returns the rpc username, password and host for the
	// backend.
	Credentials() (string, string, string, error)
}

BackendConfig is an interface that abstracts away the specific chain backend node implementation.

type BaseNodeConfig

type BaseNodeConfig struct {
	Name string

	// LogFilenamePrefix is used to prefix node log files. Can be used to
	// store the current test case for simpler postmortem debugging.
	LogFilenamePrefix string

	NetParams         *chaincfg.Params
	BackendCfg        BackendConfig
	BaseDir           string
	ExtraArgs         []string
	OriginalExtraArgs []string

	DataDir        string
	LogDir         string
	TLSCertPath    string
	TLSKeyPath     string
	AdminMacPath   string
	ReadMacPath    string
	InvoiceMacPath string

	SkipUnlock bool
	Password   []byte

	P2PPort     int
	RPCPort     int
	RESTPort    int
	ProfilePort int

	FeeURL string

	DBBackend   DatabaseBackend
	PostgresDsn string
	NativeSQL   bool

	// NodeID is a unique ID used to identify the node.
	NodeID uint32

	// LndBinary is the full path to the lnd binary that was specifically
	// compiled with all required itest flags.
	LndBinary string
	// contains filtered or unexported fields
}

BaseNodeConfig is the base node configuration.

func (*BaseNodeConfig) BaseConfig

func (cfg *BaseNodeConfig) BaseConfig() *BaseNodeConfig

BaseConfig returns the base node configuration struct.

func (BaseNodeConfig) ChanBackupPath

func (cfg BaseNodeConfig) ChanBackupPath() string

func (BaseNodeConfig) DBDir

func (cfg BaseNodeConfig) DBDir() string

DBDir returns the holding directory path of the graph database.

func (BaseNodeConfig) DBPath

func (cfg BaseNodeConfig) DBPath() string

func (*BaseNodeConfig) GenArgs

func (cfg *BaseNodeConfig) GenArgs() []string

GenArgs generates a slice of command line arguments from the lightning node config struct.

func (*BaseNodeConfig) GenerateListeningPorts

func (cfg *BaseNodeConfig) GenerateListeningPorts()

GenerateListeningPorts generates the ports to listen on designated for the current lightning network test.

func (BaseNodeConfig) P2PAddr

func (cfg BaseNodeConfig) P2PAddr() string

func (BaseNodeConfig) RESTAddr

func (cfg BaseNodeConfig) RESTAddr() string

func (BaseNodeConfig) RPCAddr

func (cfg BaseNodeConfig) RPCAddr() string

type DatabaseBackend

type DatabaseBackend int
const (
	BackendBbolt DatabaseBackend = iota
	BackendEtcd
	BackendPostgres
	BackendSqlite
)

type HarnessNode

type HarnessNode struct {
	*testing.T

	// Cfg holds the config values for the node.
	Cfg *BaseNodeConfig

	// RPC holds a list of RPC clients.
	RPC *rpc.HarnessRPC

	// State records the current state of the node.
	State *State

	// Watcher watches the node's topology updates.
	Watcher *nodeWatcher

	// PubKey is the serialized compressed identity public key of the node.
	// This field will only be populated once the node itself has been
	// started via the start() method.
	PubKey    [33]byte
	PubKeyStr string
	// contains filtered or unexported fields
}

HarnessNode represents an instance of lnd running within our test network harness. It's responsible for managing the lnd process, grpc connection, and wallet auth. A HarnessNode is built upon its rpc clients, represented in `HarnessRPC`. It also has a `State` which holds its internal state, and a `Watcher` that keeps track of its topology updates.

func NewHarnessNode

func NewHarnessNode(t *testing.T, cfg *BaseNodeConfig) (*HarnessNode, error)

NewHarnessNode creates a new test lightning node instance from the passed config.

func (*HarnessNode) AddToLogf

func (hn *HarnessNode) AddToLogf(format string, a ...interface{})

AddToLogf adds a line of choice to the node's logfile. This is useful to interleave test output with output from the node.

func (*HarnessNode) BackupDB

func (hn *HarnessNode) BackupDB() error

BackupDB creates a backup of the current database.

func (*HarnessNode) ChangePasswordAndInit

func (hn *HarnessNode) ChangePasswordAndInit(
	req *lnrpc.ChangePasswordRequest) (
	*lnrpc.ChangePasswordResponse, error)

InitChangePassword initializes a harness node by passing the change password request via RPC. After the request is submitted, this method will block until a macaroon-authenticated RPC connection can be established to the harness node. Once established, the new connection is used to initialize the RPC clients and subscribes the HarnessNode to topology changes.

func (*HarnessNode) CloseConn

func (hn *HarnessNode) CloseConn() error

CloseConn closes the grpc connection.

func (*HarnessNode) ConnectRPC

func (hn *HarnessNode) ConnectRPC() (*grpc.ClientConn, error)

ConnectRPC uses the TLS certificate and admin macaroon files written by the lnd node to create a gRPC client connection.

func (*HarnessNode) ConnectRPCWithMacaroon

func (hn *HarnessNode) ConnectRPCWithMacaroon(mac *macaroon.Macaroon) (
	*grpc.ClientConn, error)

ConnectRPCWithMacaroon uses the TLS certificate and given macaroon to create a gRPC client connection.

func (*HarnessNode) InitNode

func (hn *HarnessNode) InitNode(macBytes []byte) error

InitNode waits until the main gRPC server is detected as active, then complete the normal HarnessNode gRPC connection creation. A non-nil `macBytes` indicates the node is initialized stateless, otherwise it will use the admin macaroon.

func (*HarnessNode) Initialize

func (hn *HarnessNode) Initialize(c *grpc.ClientConn)

Initialize creates a list of new RPC clients using the passed connection, initializes the node's internal state and creates a topology watcher.

func (*HarnessNode) Kill

func (hn *HarnessNode) Kill() error

Kill kills the lnd process.

func (*HarnessNode) Name

func (hn *HarnessNode) Name() string

Name returns the name of this node set during initialization.

func (*HarnessNode) ReadMacaroon

func (hn *HarnessNode) ReadMacaroon(macPath string, timeout time.Duration) (
	*macaroon.Macaroon, error)

ReadMacaroon waits a given duration for the macaroon file to be created. If the file is readable within the timeout, its content is de-serialized as a macaroon and returned.

func (*HarnessNode) RestoreDB

func (hn *HarnessNode) RestoreDB() error

RestoreDB restores a database backup.

func (*HarnessNode) SetExtraArgs

func (hn *HarnessNode) SetExtraArgs(extraArgs []string)

SetExtraArgs assigns the ExtraArgs field for the node's configuration. The changes will take effect on restart.

func (*HarnessNode) Shutdown

func (hn *HarnessNode) Shutdown() error

Shutdown stops the active lnd process and cleans up any temporary directories created along the way.

func (*HarnessNode) Start

func (hn *HarnessNode) Start(ctxt context.Context) error

Start will start the lnd process, creates the grpc connection, and waits until the server is fully started.

func (*HarnessNode) StartLndCmd

func (hn *HarnessNode) StartLndCmd(ctxb context.Context) error

StartLndCmd handles the startup of lnd, creating log files, and possibly kills the process when needed.

func (*HarnessNode) StartWithNoAuth

func (hn *HarnessNode) StartWithNoAuth(ctxt context.Context) error

StartWithNoAuth will start the lnd process, creates the grpc connection without macaroon auth, and waits until the server is reported as waiting to start.

NOTE: caller needs to take extra step to create and unlock the wallet.

func (*HarnessNode) Stop

func (hn *HarnessNode) Stop() error

Stop attempts to stop the active lnd process.

func (*HarnessNode) String

func (hn *HarnessNode) String() string

String gives the internal state of the node which is useful for debugging.

func (*HarnessNode) Unlock

func (hn *HarnessNode) Unlock(unlockReq *lnrpc.UnlockWalletRequest) error

Unlock attempts to unlock the wallet of the target HarnessNode. This method should be called after the restart of a HarnessNode that was created with a seed+password. Once this method returns, the HarnessNode will be ready to accept normal gRPC requests and harness command.

func (*HarnessNode) UpdateGlobalPolicy

func (hn *HarnessNode) UpdateGlobalPolicy(policy *lnrpc.RoutingPolicy)

UpdateGlobalPolicy updates a node's global channel policy.

func (*HarnessNode) UpdateState

func (hn *HarnessNode) UpdateState()

UpdateState updates the node's internal state.

func (*HarnessNode) WaitForProcessExit

func (hn *HarnessNode) WaitForProcessExit() error

waitForProcessExit Launch a new goroutine which that bubbles up any potential fatal process errors to the goroutine running the tests.

func (*HarnessNode) WaitUntilLeader

func (hn *HarnessNode) WaitUntilLeader(timeout time.Duration) error

WaitUntilLeader attempts to finish the start procedure by initiating an RPC connection and setting up the wallet unlocker client. This is needed when a node that has recently been started was waiting to become the leader and we're at the point when we expect that it is the leader now (awaiting unlock).

func (*HarnessNode) WaitUntilServerActive

func (hn *HarnessNode) WaitUntilServerActive() error

WaitUntilServerActive waits until the lnd daemon is fully started.

func (*HarnessNode) WaitUntilStarted

func (hn *HarnessNode) WaitUntilStarted() error

WaitUntilStarted waits until the wallet state flips from "WAITING_TO_START".

type OpenChannelUpdate

type OpenChannelUpdate struct {
	// AdvertisingNode specifies the node that advertised this update.
	AdvertisingNode string `json:"advertising_node"`

	// ConnectingNode specifies the node that is connected with the
	// advertising node.
	ConnectingNode string `json:"connecting_node"`

	// Timestamp records the time the policy update is made.
	Timestamp time.Time `json:"timestamp"`
}

OpenChannelUpdate stores the open channel updates.

type Option

type Option func(*BaseNodeConfig)

Option is a function for updating a node's configuration.

type PolicyUpdate

type PolicyUpdate map[string][]*PolicyUpdateInfo

PolicyUpdate defines a type to store channel policy updates for a given advertisingNode. It has the format, {"advertisingNode": [policy1, policy2, ...]}.

type PolicyUpdateInfo

type PolicyUpdateInfo struct {
	*lnrpc.RoutingPolicy

	// ConnectingNode specifies the node that is connected with the
	// advertising node.
	ConnectingNode string `json:"connecting_node"`

	// Timestamp records the time the policy update is made.
	Timestamp time.Time `json:"timestamp"`
}

PolicyUpdateInfo stores the RoutingPolicy plus the connecting node info.

type State

type State struct {

	// OpenChannel gives the summary of open channel related counts.
	OpenChannel openChannelCount

	// CloseChannel gives the summary of close channel related counts.
	CloseChannel closedChannelCount

	// Wallet gives the summary of the wallet balance.
	Wallet walletBalance

	// HTLC counts the total active HTLCs.
	HTLC int

	// Edge counts the total private/public edges.
	Edge edgeCount

	// ChannelUpdate counts the total channel updates seen from the graph
	// subscription.
	ChannelUpdate int

	// NodeUpdate counts the total node announcements seen from the graph
	// subscription.
	NodeUpdate int

	// UTXO counts the total active UTXOs.
	UTXO utxoCount

	// Payment counts the total payment of the node.
	Payment paymentCount

	// Invoice counts the total invoices made by the node.
	Invoice invoiceCount
	// contains filtered or unexported fields
}

State records the current state for a given node. It provides a simple count over the node so that the test can track its state. For a channel-specific state check, use dedicated function to query the channel as each channel is meant to be unique.

func (*State) String

func (s *State) String() string

String encodes the node's state for debugging.

Jump to

Keyboard shortcuts

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