Documentation ¶
Index ¶
- Constants
- func CheckChannelPolicy(policy, expectedPolicy *lnrpc.RoutingPolicy) error
- type BackendConfig
- type BaseNodeConfig
- func (cfg *BaseNodeConfig) BaseConfig() *BaseNodeConfig
- func (cfg BaseNodeConfig) ChanBackupPath() string
- func (cfg BaseNodeConfig) DBDir() string
- func (cfg BaseNodeConfig) DBPath() string
- func (cfg *BaseNodeConfig) GenArgs() []string
- func (cfg *BaseNodeConfig) GenerateListeningPorts()
- func (cfg BaseNodeConfig) P2PAddr() string
- func (cfg BaseNodeConfig) RESTAddr() string
- func (cfg BaseNodeConfig) RPCAddr() string
- type HarnessNode
- func (hn *HarnessNode) AddToLogf(format string, a ...interface{})
- func (hn *HarnessNode) BackupDB() error
- func (hn *HarnessNode) CloseConn() error
- func (hn *HarnessNode) ConnectRPC() (*grpc.ClientConn, error)
- func (hn *HarnessNode) ConnectRPCWithMacaroon(mac *macaroon.Macaroon) (*grpc.ClientConn, error)
- func (hn *HarnessNode) InitNode(macBytes []byte) error
- func (hn *HarnessNode) InitRPCClients(c *grpc.ClientConn)
- func (hn *HarnessNode) Name() string
- func (hn *HarnessNode) ReadMacaroon(macPath string, timeout time.Duration) (*macaroon.Macaroon, error)
- func (hn *HarnessNode) RestoreDB() error
- func (hn *HarnessNode) SetExtraArgs(extraArgs []string)
- func (hn *HarnessNode) Shutdown() error
- func (hn *HarnessNode) Start(ctxt context.Context) error
- func (hn *HarnessNode) StartLndCmd(ctxb context.Context) error
- func (hn *HarnessNode) StartWithSeed(ctxt context.Context) error
- func (hn *HarnessNode) Stop() error
- func (hn *HarnessNode) String() string
- func (hn *HarnessNode) Unlock(unlockReq *lnrpc.UnlockWalletRequest) error
- func (hn *HarnessNode) UpdateState()
- func (hn *HarnessNode) WaitUntilServerActive() error
- func (hn *HarnessNode) WaitUntilStarted() error
- type OpenChannelUpdate
- type Option
- type PolicyUpdate
- type PolicyUpdateInfo
- type State
- type SyncMap
Constants ¶
const ( // TODO(yy): remove once temp tests is finished. DefaultTimeout = lntest.DefaultTimeout )
const ( // ListenerFormat is the format string that is used to generate local // listener addresses. ListenerFormat = "127.0.0.1:%d" )
Variables ¶
This section is empty.
Functions ¶
func CheckChannelPolicy ¶
func CheckChannelPolicy(policy, expectedPolicy *lnrpc.RoutingPolicy) error
CheckChannelPolicy checks that the policy matches the expected one.
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 HasSeed bool Password []byte P2PPort int RPCPort int RESTPort int ProfilePort int FeeURL string DbBackend lntest.DatabaseBackend PostgresDsn string // 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 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) 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) InitRPCClients ¶
func (hn *HarnessNode) InitRPCClients(c *grpc.ClientConn)
InitRPCClients initializes a list of RPC clients for the node.
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) StartWithSeed ¶
func (hn *HarnessNode) StartWithSeed(ctxt context.Context) error
StartWithSeed 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) UpdateState ¶
func (hn *HarnessNode) UpdateState()
UpdateState updates the node's internal state.
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.
type SyncMap ¶
type SyncMap[K comparable, V any] struct { sync.Map }
SyncMap wraps a sync.Map with type parameters such that it's easier to access the items stored in the map since no type assertion is needed. It also requires explicit type definition when declaring and initiating the variables, which helps us understanding what's stored in a given map.
func (*SyncMap[K, V]) Delete ¶
func (m *SyncMap[K, V]) Delete(key K)
Delete removes an item from the map specified by the key.
func (*SyncMap[K, V]) Load ¶
Load queries an item from the map using the specified key. If the item cannot be found, an empty value and false will be returned. If the stored item fails the type assertion, a nil value and false will be returned.
func (*SyncMap[K, V]) LoadAndDelete ¶
LoadAndDelete queries an item and deletes it from the map using the specified key.