lntest

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 61 Imported by: 0

Documentation

Overview

Package lntest provides testing utilities for the dcrlnd repository.

This package contains infrastructure for integration tests that launch full dcrlnd nodes in a controlled environment and interact with them via RPC. Using a NetworkHarness, a test can launch multiple dcrlnd nodes, open channels between them, create defined network topologies, and anything else that is possible with RPC commands.

Index

Constants

View Source
const (

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

	// NeutrinoBackendName is the name of the neutrino backend.
	NeutrinoBackendName = "neutrino"
)
View Source
const (
	// MinerMempoolTimeout is the max time we will wait for a transaction
	// to propagate to the mining node's mempool.
	MinerMempoolTimeout = time.Minute

	// ChannelOpenTimeout is the max time we will wait before a channel to
	// be considered opened.
	ChannelOpenTimeout = time.Second * 30

	// ChannelCloseTimeout is the max time we will wait before a channel is
	// considered closed.
	ChannelCloseTimeout = time.Second * 30

	// DefaultTimeout is a timeout that will be used for various wait
	// scenarios where no custom timeout value is defined.
	DefaultTimeout = time.Second * 30

	// AsyncBenchmarkTimeout is the timeout used when running the async
	// payments benchmark.
	AsyncBenchmarkTimeout = 2 * time.Minute

	// NodeStartTimeout is the timeout value when waiting for a node to
	// become fully started.
	NodeStartTimeout = time.Second * 60
)
View Source
const DefaultCSV = 4

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

Variables

This section is empty.

Functions

func ApplyPortOffset added in v0.5.0

func ApplyPortOffset(offset uint32)

ApplyPortOffset adds the given offset to the lastPort variable, making it possible to run the tests in parallel without colliding on the same ports.

func CheckChannelPolicy added in v0.6.0

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 GetLogDir added in v0.5.0

func GetLogDir() string

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

func MakeOutpoint added in v0.6.0

func MakeOutpoint(chanPoint *lnrpc.ChannelPoint) (wire.OutPoint, error)

MakeOutpoint returns the outpoint of the channel's funding transaction.

func NextAvailablePort added in v0.5.0

func NextAvailablePort() int

NextAvailablePort returns the first port that is available for listening by a new node. It panics if no port is found and the maximum available TCP port is reached.

Types

type BackendConfig added in v0.2.0

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

	// StartWalletSync starts the sync process of a remote wallet using the
	// given backend implementation.
	StartWalletSync(loader pb.WalletLoaderServiceClient, password []byte) error

	// 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
}

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

type BaseNodeConfig added in v0.6.0

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

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

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

	HasSeed      bool
	Password     []byte
	RemoteWallet bool
	DcrwNode     bool

	P2PPort     int
	RPCPort     int
	RESTPort    int
	ProfilePort int
	WalletPort  int

	AcceptKeySend bool
	AcceptAMP     bool

	FeeURL string

	DbBackend   DatabaseBackend
	PostgresDsn string
}

BaseNodeConfig is the base node configuration.

func (*BaseNodeConfig) BaseConfig added in v0.6.0

func (cfg *BaseNodeConfig) BaseConfig() *BaseNodeConfig

BaseConfig returns the base node configuration struct.

func (BaseNodeConfig) ChanBackupPath added in v0.6.0

func (cfg BaseNodeConfig) ChanBackupPath() string

func (BaseNodeConfig) DBDir added in v0.6.0

func (cfg BaseNodeConfig) DBDir() string

DBDir returns the holding directory path of the graph database.

func (BaseNodeConfig) DBPath added in v0.6.0

func (cfg BaseNodeConfig) DBPath() string

func (*BaseNodeConfig) GenArgs added in v0.6.0

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

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

func (*BaseNodeConfig) GenerateListeningPorts added in v0.6.0

func (cfg *BaseNodeConfig) GenerateListeningPorts()

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

func (BaseNodeConfig) P2PAddr added in v0.6.0

func (cfg BaseNodeConfig) P2PAddr() string

func (BaseNodeConfig) RESTAddr added in v0.6.0

func (cfg BaseNodeConfig) RESTAddr() string

func (BaseNodeConfig) RPCAddr added in v0.6.0

func (cfg BaseNodeConfig) RPCAddr() string

type DatabaseBackend added in v0.6.0

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

type DcrdBackendConfig added in v0.5.0

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

DcrdBackendConfig is an implementation of the BackendConfig interface backed by a btcd node.

func NewBackend added in v0.5.0

func NewBackend(t *testing.T, miner *rpctest.Harness) (*DcrdBackendConfig, func() error, error)

NewBackend starts a new rpctest.Harness and returns a DcrdBackendConfig for that node.

func (DcrdBackendConfig) ConnectMiner added in v0.5.0

func (b DcrdBackendConfig) ConnectMiner() error

ConnectMiner connects the backend to the underlying miner.

func (DcrdBackendConfig) DisconnectMiner added in v0.5.0

func (b DcrdBackendConfig) DisconnectMiner() error

DisconnectMiner disconnects the backend to the underlying miner.

func (DcrdBackendConfig) GenArgs added in v0.5.0

func (b DcrdBackendConfig) GenArgs() []string

GenArgs returns the arguments needed to be passed to LND at startup for using this node as a chain backend.

func (DcrdBackendConfig) Name added in v0.5.0

func (b DcrdBackendConfig) Name() string

Name returns the name of the backend type.

func (DcrdBackendConfig) StartWalletSync added in v0.5.0

func (b DcrdBackendConfig) StartWalletSync(loader pb.WalletLoaderServiceClient, password []byte) error

type HarnessMiner added in v0.6.0

type HarnessMiner struct {
	*rpctest.Harness

	// Client adapts decred's dcrdtest.Harness interface to lnd's.
	Client *rpcclient.Client
	// contains filtered or unexported fields
}

func NewMiner added in v0.5.0

func NewMiner() (*HarnessMiner, error)

NewMiner creates a new miner using dcrd backend with the default log file dir and name.

func NewTempMiner added in v0.6.0

func NewTempMiner(tempDir, tempLogFilename string) (*HarnessMiner, error)

NewTempMiner creates a new miner using dcrd backend with the specified log file dir and name.

func (*HarnessMiner) GenerateAndSubmitBlock added in v0.6.0

func (h *HarnessMiner) GenerateAndSubmitBlock(txs []*dcrutil.Tx, _ int32, _ time.Time) (*dcrutil.Block, error)

GenerateAndSubmitBlock publishes the transactions and generates a new blck.

This function's signature is similar to the one in btcd's rpctest package.

func (*HarnessMiner) SetUpChain added in v0.6.0

func (h *HarnessMiner) SetUpChain() error

SetUpChain performs the initial chain setup for integration tests. This should be done only once.

func (*HarnessMiner) Stop added in v0.6.0

func (h *HarnessMiner) Stop() error

Stop shuts down the miner and saves its logs.

type HarnessNode

type HarnessNode struct {
	Cfg *BaseNodeConfig

	// NodeID is a unique identifier for the node within a NetworkHarness.
	NodeID int

	// 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

	// TODO(yy): remove
	lnrpc.LightningClient
	lnrpc.WalletUnlockerClient
	invoicesrpc.InvoicesClient
	SignerClient     signrpc.SignerClient
	RouterClient     routerrpc.RouterClient
	WalletKitClient  walletrpc.WalletKitClient
	Watchtower       watchtowerrpc.WatchtowerClient
	WatchtowerClient wtclientrpc.WatchtowerClientClient
	StateClient      lnrpc.StateClient
	// contains filtered or unexported fields
}

HarnessNode represents an instance of lnd running within our test network harness. Each HarnessNode instance also fully embeds an RPC client in order to pragmatically drive the node.

func (*HarnessNode) AddToLog

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

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

func (*HarnessNode) AdminMacPath added in v0.3.0

func (hn *HarnessNode) AdminMacPath() string

AdminMacPath returns the filepath to the admin.macaroon file for this node.

func (*HarnessNode) ChanBackupPath added in v0.2.0

func (hn *HarnessNode) ChanBackupPath() string

ChanBackupPath returns the fielpath to the on-disk channel.backup file for this node.

func (*HarnessNode) ConnectRPC

func (hn *HarnessNode) ConnectRPC(useMacs bool) (*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 added in v0.3.0

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) DBDir added in v0.5.0

func (hn *HarnessNode) DBDir() string

DBDir returns the path for the directory holding channeldb file(s).

func (*HarnessNode) DBPath

func (hn *HarnessNode) DBPath() string

DBPath returns the filepath to the channeldb database file for this node.

func (*HarnessNode) FetchNodeInfo

func (hn *HarnessNode) FetchNodeInfo() error

FetchNodeInfo queries an unlocked node to retrieve its public key.

func (*HarnessNode) Init

Init initializes a harness node by passing the init 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 LightningClient and subscribes the HarnessNode to topology changes.

func (*HarnessNode) InitChangePassword added in v0.5.0

func (hn *HarnessNode) InitChangePassword(
	chngPwReq *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 LightningClient and subscribes the HarnessNode to topology changes.

func (*HarnessNode) InitRPCClients added in v0.6.0

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

InitRPCClients initializes a list of RPC clients for the node.

func (*HarnessNode) InvoiceMacPath added in v0.3.0

func (hn *HarnessNode) InvoiceMacPath() string

InvoiceMacPath returns the filepath to the invoice.macaroon file for this node.

func (*HarnessNode) LogPrintf added in v0.3.0

func (hn *HarnessNode) LogPrintf(format string, args ...interface{}) error

func (*HarnessNode) Name

func (hn *HarnessNode) Name() string

Name returns the name of this node set during initialization.

func (*HarnessNode) P2PAddr

func (hn *HarnessNode) P2PAddr() string

P2PAddr returns the configured P2P address for the node.

func (*HarnessNode) PrintErr added in v0.6.0

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

PrintErr prints an error to the console.

func (*HarnessNode) ReadMacPath added in v0.3.0

func (hn *HarnessNode) ReadMacPath() string

ReadMacPath returns the filepath to the readonly.macaroon file for this node.

func (*HarnessNode) ReadMacaroon added in v0.3.0

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) 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) String added in v0.6.0

func (hn *HarnessNode) String() string

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

func (*HarnessNode) TLSCertStr added in v0.2.0

func (hn *HarnessNode) TLSCertStr() string

TLSCertStr returns the path where the TLS certificate is stored.

func (*HarnessNode) TLSKeyStr added in v0.2.0

func (hn *HarnessNode) TLSKeyStr() string

TLSKeyStr returns the path where the TLS key is stored.

func (*HarnessNode) Unlock added in v0.2.0

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) WaitForBalance

func (hn *HarnessNode) WaitForBalance(expectedBalance dcrutil.Amount,
	confirmed bool) error

WaitForBalance waits until the node sees the expected confirmed/unconfirmed balance within their wallet.

func (*HarnessNode) WaitForBlockHeight added in v0.2.0

func (hn *HarnessNode) WaitForBlockHeight(ctx context.Context, height uint32) error

WaitForBlockHeight will block until the target node syncs to the given block height or the context expires.

func (*HarnessNode) WaitForBlockchainSync

func (hn *HarnessNode) WaitForBlockchainSync() error

WaitForBlockchainSync waits for the target node to be fully synchronized with the blockchain. If the passed context object has a set timeout, it will continually poll until the timeout has elapsed. In the case that the chain isn't synced before the timeout is up, this function will return an error.

func (*HarnessNode) WaitForChannelPolicyUpdate added in v0.6.0

func (hn *HarnessNode) WaitForChannelPolicyUpdate(
	advertisingNode string, policy *lnrpc.RoutingPolicy,
	chanPoint *lnrpc.ChannelPoint, includeUnannounced bool) error

WaitForChannelPolicyUpdate will block until a channel policy with the target outpoint and advertisingNode is seen within the network.

func (*HarnessNode) WaitForNetworkChannelClose

func (hn *HarnessNode) WaitForNetworkChannelClose(
	chanPoint *lnrpc.ChannelPoint) error

WaitForNetworkChannelClose will block until a channel with the target outpoint is seen as closed within the network. A channel is considered closed once a transaction spending the funding outpoint is seen within a confirmed block.

func (*HarnessNode) WaitForNetworkChannelOpen

func (hn *HarnessNode) WaitForNetworkChannelOpen(
	chanPoint *lnrpc.ChannelPoint) error

WaitForNetworkChannelOpen will block until a channel with the target outpoint is seen as being fully advertised within the network. A channel is considered "fully advertised" once both of its directional edges has been advertised within the test Lightning Network.

func (*HarnessNode) WaitUntilLeader added in v0.5.0

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 added in v0.6.0

func (hn *HarnessNode) WaitUntilServerActive() error

WaitUntilServerActive waits until the lnd daemon is fully started.

func (*HarnessNode) WaitUntilStarted added in v0.6.0

func (hn *HarnessNode) WaitUntilStarted() error

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

func (*HarnessNode) WaitUntilStateReached added in v0.6.0

func (hn *HarnessNode) WaitUntilStateReached(
	desiredState lnrpc.WalletState) error

WaitUntilStateReached waits until the given wallet state (or one of the states following it) has been reached.

type NetworkHarness

type NetworkHarness struct {

	// Miner is a reference to a running full node that can be used to
	// create new blocks on the network.
	Miner *HarnessMiner

	// BackendCfg houses the information necessary to use a node as LND
	// chain backend, such as rpc configuration, P2P information etc.
	BackendCfg BackendConfig

	// Alice and Bob are the initial seeder nodes that are automatically
	// created to be the initial participants of the test network.
	Alice *HarnessNode
	Bob   *HarnessNode
	// contains filtered or unexported fields
}

NetworkHarness is an integration testing harness for the lightning network. Building on top of HarnessNode, it is responsible for handling interactions among different nodes. The harness by default is created with two active nodes on the network: Alice and Bob.

func NewNetworkHarness

func NewNetworkHarness(m *HarnessMiner, b BackendConfig, lndBinary string,
	dbBackend DatabaseBackend) (*NetworkHarness, error)

NewNetworkHarness creates a new network test harness. TODO(roasbeef): add option to use golang's build library to a binary of the current repo. This will save developers from having to manually `go install` within the repo each time before changes

func (*NetworkHarness) AssertChannelExists

func (n *NetworkHarness) AssertChannelExists(node *HarnessNode,
	chanPoint *wire.OutPoint, checks ...func(*lnrpc.Channel)) error

AssertChannelExists asserts that an active channel identified by the specified channel point exists from the point-of-view of the node. It takes an optional set of check functions which can be used to make further assertions using channel's values. These functions are responsible for failing the test themselves if they do not pass. nolint: interfacer

func (*NetworkHarness) BackupDb added in v0.6.0

func (n *NetworkHarness) BackupDb(hn *HarnessNode) error

BackupDb creates a backup of the current database.

func (*NetworkHarness) CloseChannel

CloseChannel attempts to close the channel indicated by the passed channel point, initiated by the passed lnNode. If the passed context has a timeout, an error is returned if that timeout is reached before the channel close is pending.

func (*NetworkHarness) ConnectNodes

func (n *NetworkHarness) ConnectNodes(t *testing.T, a, b *HarnessNode)

ConnectNodes attempts to create a connection between nodes a and b.

func (*NetworkHarness) ConnectNodesPerm added in v0.6.0

func (n *NetworkHarness) ConnectNodesPerm(t *testing.T,
	a, b *HarnessNode)

ConnectNodesPerm attempts to connect nodes a and b and sets node b as a peer that node a should persistently attempt to reconnect to if they become disconnected.

func (*NetworkHarness) DisconnectNodes

func (n *NetworkHarness) DisconnectNodes(a, b *HarnessNode) error

DisconnectNodes disconnects node a from node b by sending RPC message from a node to b node

func (*NetworkHarness) DumpLogs

func (n *NetworkHarness) DumpLogs(node *HarnessNode) (string, error)

DumpLogs reads the current logs generated by the passed node, and returns the logs as a single string. This function is useful for examining the logs of a particular node in the case of a test failure. Logs from lightning node being generated with delay - you should add time.Sleep() in order to get all logs.

func (*NetworkHarness) EnsureConnected

func (n *NetworkHarness) EnsureConnected(t *testing.T, a, b *HarnessNode)

EnsureConnected will try to connect to two nodes, returning no error if they are already connected. If the nodes were not connected previously, this will behave the same as ConnectNodes. If a pending connection request has already been made, the method will block until the two nodes appear in each other's peers list, or until the 15s timeout expires.

func (*NetworkHarness) Generate

func (n *NetworkHarness) Generate(nb uint32) ([]*chainhash.Hash, error)

Generate generates the given number of blocks while waiting for enough time that the new block can propagate to the voting node and votes for the new block can be generated and published.

func (*NetworkHarness) KillNode added in v0.5.0

func (n *NetworkHarness) KillNode(node *HarnessNode) error

KillNode kills the node (but won't wait for the node process to stop).

func (*NetworkHarness) LookUpNodeByPub

func (n *NetworkHarness) LookUpNodeByPub(pubStr string) (*HarnessNode, error)

LookUpNodeByPub queries the set of active nodes to locate a node according to its public key. The second value will be true if the node was found, and false otherwise.

func (*NetworkHarness) ModifyTestCaseName added in v0.5.0

func (n *NetworkHarness) ModifyTestCaseName(testCase string)

ModifyTestCaseName modifies the current test case name.

func (*NetworkHarness) NewNode

func (n *NetworkHarness) NewNode(t *testing.T,
	name string, extraArgs []string, opts ...NodeOption) *HarnessNode

NewNode fully initializes a returns a new HarnessNode bound to the current instance of the network harness. The created node is running, but not yet connected to other nodes within the network.

func (*NetworkHarness) NewNodeEtcd added in v0.5.0

func (n *NetworkHarness) NewNodeEtcd(name string, etcdCfg *etcd.Config,
	password []byte, cluster, wait bool, leaderSessionTTL int) (
	*HarnessNode, error)

NewNodeWithSeedEtcd starts a new node with seed that'll use an external etcd database as its (remote) channel and wallet DB. The passsed cluster flag indicates that we'd like the node to join the cluster leader election. If the wait flag is false then we won't wait until RPC is available (this is useful when the node is not expected to become the leader right away).

func (*NetworkHarness) NewNodeRemoteSigner added in v0.6.0

func (n *NetworkHarness) NewNodeRemoteSigner(name string, extraArgs []string,
	password []byte, watchOnly *lnrpc.WatchOnly) (*HarnessNode, error)

func (*NetworkHarness) NewNodeWithSeed

func (n *NetworkHarness) NewNodeWithSeed(name string, extraArgs []string,
	password []byte, statelessInit bool) (*HarnessNode, []string, []byte,
	error)

NewNodeWithSeed fully initializes a new HarnessNode after creating a fresh aezeed. The provided password is used as both the aezeed password and the wallet password. The generated mnemonic is returned along with the initialized harness node.

func (*NetworkHarness) NewNodeWithSeedEtcd added in v0.5.0

func (n *NetworkHarness) NewNodeWithSeedEtcd(name string, etcdCfg *etcd.Config,
	password []byte, entropy []byte, statelessInit, cluster bool,
	leaderSessionTTL int) (*HarnessNode, []string, []byte, error)

NewNodeWithSeedEtcd starts a new node with seed that'll use an external etcd database as its (remote) channel and wallet DB. The passsed cluster flag indicates that we'd like the node to join the cluster leader election.

func (*NetworkHarness) OpenChannel

func (n *NetworkHarness) OpenChannel(srcNode, destNode *HarnessNode,
	p OpenChannelParams) (lnrpc.Lightning_OpenChannelClient, error)

OpenChannel attempts to open a channel between srcNode and destNode with the passed channel funding parameters. If the passed context has a timeout, then if the timeout is reached before the channel pending notification is received, an error is returned. The confirmed boolean determines whether we should fund the channel with confirmed outputs or not.

func (*NetworkHarness) OpenPendingChannel

func (n *NetworkHarness) OpenPendingChannel(srcNode, destNode *HarnessNode,
	amt dcrutil.Amount,
	pushAmt dcrutil.Amount) (*lnrpc.PendingUpdate, error)

OpenPendingChannel attempts to open a channel between srcNode and destNode with the passed channel funding parameters. If the passed context has a timeout, then if the timeout is reached before the channel pending notification is received, an error is returned.

func (*NetworkHarness) ProcessErrors

func (n *NetworkHarness) ProcessErrors() <-chan error

ProcessErrors returns a channel used for reporting any fatal process errors. If any of the active nodes within the harness' test network incur a fatal error, that error is sent over this channel.

func (*NetworkHarness) RegisterNode

func (n *NetworkHarness) RegisterNode(node *HarnessNode)

RegisterNode records a new HarnessNode in the NetworkHarnesses map of known nodes. This method should only be called with nodes that have successfully retrieved their public keys via FetchNodeInfo.

func (*NetworkHarness) RestartNode

func (n *NetworkHarness) RestartNode(node *HarnessNode, callback func() error,
	chanBackups ...*lnrpc.ChanBackupSnapshot) error

RestartNode attempts to restart a lightning node by shutting it down cleanly, then restarting the process. This function is fully blocking. Upon restart, the RPC connection to the node will be re-attempted, continuing iff the connection attempt is successful. If the callback parameter is non-nil, then the function will be executed after the node shuts down, but *before* the process has been started up again.

This method can be useful when testing edge cases such as a node broadcast and invalidated prior state, or persistent state recovery, simulating node crashes, etc. Additionally, each time the node is restarted, the caller can pass a set of SCBs to pass in via the Unlock method allowing them to restore channels during restart.

func (*NetworkHarness) RestartNodeNoUnlock added in v0.5.0

func (n *NetworkHarness) RestartNodeNoUnlock(node *HarnessNode,
	callback func() error, wait bool) error

RestartNodeNoUnlock attempts to restart a lightning node by shutting it down cleanly, then restarting the process. In case the node was setup with a seed, it will be left in the unlocked state. This function is fully blocking. If the callback parameter is non-nil, then the function will be executed after the node shuts down, but *before* the process has been started up again.

func (*NetworkHarness) RestoreDb added in v0.6.0

func (n *NetworkHarness) RestoreDb(hn *HarnessNode) error

RestoreDb restores a database backup.

func (*NetworkHarness) RestoreNodeWithSeed

func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string,
	password []byte, mnemonic []string, rootKey string, recoveryWindow int32,
	chanBackups *lnrpc.ChanBackupSnapshot,
	opts ...NodeOption) (*HarnessNode, error)

RestoreNodeWithSeed fully initializes a HarnessNode using a chosen mnemonic, password, recovery window, and optionally a set of static channel backups. After providing the initialization request to unlock the node, this method will finish initializing the LightningClient such that the HarnessNode can be used for regular rpc operations.

func (*NetworkHarness) SaveProfilesPages added in v0.2.0

func (n *NetworkHarness) SaveProfilesPages(t *testing.T)

SaveProfilesPages hits profiles pages of all active nodes and writes it to disk using a similar naming scheme as to the regular set of logs.

func (*NetworkHarness) SendCoins

func (n *NetworkHarness) SendCoins(t *testing.T, amt dcrutil.Amount,
	target *HarnessNode)

SendCoins attempts to send amt atoms from the internal mining node to the targeted lightning node using a P2WKH address. 6 blocks are mined after in order to confirm the transaction.

func (*NetworkHarness) SendCoinsUnconfirmed

func (n *NetworkHarness) SendCoinsUnconfirmed(t *testing.T, amt dcrutil.Amount,
	target *HarnessNode)

SendCoinsUnconfirmed sends coins from the internal mining node to the target lightning node using a P2WPKH address. No blocks are mined after, so the transaction remains unconfirmed.

func (*NetworkHarness) SetFeeEstimate added in v0.5.0

func (n *NetworkHarness) SetFeeEstimate(fee chainfee.AtomPerKByte)

func (*NetworkHarness) SetFeeEstimateWithConf added in v0.5.0

func (n *NetworkHarness) SetFeeEstimateWithConf(
	fee chainfee.AtomPerKByte, conf uint32)

func (*NetworkHarness) SetUp

func (n *NetworkHarness) SetUp(t *testing.T,
	testCase string, lndArgs []string) error

SetUp starts the initial seeder nodes within the test harness. The initial node's wallets will be funded wallets with ten 1 DCR outputs each. Finally rpc clients capable of communicating with the initial seeder nodes are created. Nodes are initialized with the given extra command line flags, which should be formatted properly - "--arg=value".

func (*NetworkHarness) ShutdownNode

func (n *NetworkHarness) ShutdownNode(node *HarnessNode) error

ShutdownNode stops an active lnd process and returns when the process has exited and any temporary directories have been cleaned up.

func (*NetworkHarness) SlowGenerate added in v0.3.0

func (n *NetworkHarness) SlowGenerate(nb uint32) ([]*chainhash.Hash, error)

SlowGenerate generates blocks with a large time interval between them. This is useful for debugging.

func (*NetworkHarness) Stop added in v0.5.0

func (n *NetworkHarness) Stop()

Stop stops the test harness.

func (*NetworkHarness) StopNode

func (n *NetworkHarness) StopNode(node *HarnessNode) error

StopNode stops the target node, but doesn't yet clean up its directories. This can be used to temporarily bring a node down during a test, to be later started up again.

func (*NetworkHarness) SuspendNode

func (n *NetworkHarness) SuspendNode(node *HarnessNode) (func() error, error)

SuspendNode stops the given node and returns a callback that can be used to start it again.

func (*NetworkHarness) TearDown added in v0.5.0

func (n *NetworkHarness) TearDown() error

TearDown tears down all active nodes within the test lightning network.

func (*NetworkHarness) WaitForChannelClose

func (n *NetworkHarness) WaitForChannelClose(
	closeChanStream lnrpc.Lightning_CloseChannelClient) (
	*chainhash.Hash, error)

WaitForChannelClose waits for a notification from the passed channel close stream that the node has deemed the channel has been fully closed. If the passed context has a timeout, then if the timeout is reached before the notification is received then an error is returned.

func (*NetworkHarness) WaitForChannelOpen

func (n *NetworkHarness) WaitForChannelOpen(
	openChanStream lnrpc.Lightning_OpenChannelClient) (
	*lnrpc.ChannelPoint, error)

WaitForChannelOpen waits for a notification that a channel is open by consuming a message from the past open channel stream. If the passed context has a timeout, then if the timeout is reached before the channel has been opened, then an error is returned.

type NodeConfig added in v0.3.0

type NodeConfig interface {
	// BaseConfig returns the base node configuration struct.
	BaseConfig() *BaseNodeConfig

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

	// GenArgs generates a slice of command line arguments from the
	// lightning node config struct.
	GenArgs() []string
}

NodeConfig is the basic interface a node configuration must implement.

type NodeOption added in v0.5.0

type NodeOption func(*BaseNodeConfig)

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

type OpenChannelParams

type OpenChannelParams struct {
	// Amt is the local amount being put into the channel.
	Amt dcrutil.Amount

	// PushAmt is the amount that should be pushed to the remote when the
	// channel is opened.
	PushAmt dcrutil.Amount

	// Private is a boolan indicating whether the opened channel should be
	// private.
	Private bool

	// SpendUnconfirmed is a boolean indicating whether we can utilize
	// unconfirmed outputs to fund the channel.
	SpendUnconfirmed bool

	// MinHtlc is the htlc_minimum_m_atoms value set when opening the
	// channel.
	MinHtlc lnwire.MilliAtom

	// RemoteMaxHtlcs is the remote_max_htlcs value set when opening the
	// channel, restricting the number of concurrent HTLCs the remote party
	// can add to a commitment.
	RemoteMaxHtlcs uint16

	// FundingShim is an optional funding shim that the caller can specify
	// in order to modify the channel funding workflow.
	FundingShim *lnrpc.FundingShim

	// AtomsPerByte is the amount of atoms to spend in chain fees per byte
	// of the transaction.
	AtomsPerByte dcrutil.Amount

	// CommitmentType is the commitment type that should be used for the
	// channel to be opened.
	CommitmentType lnrpc.CommitmentType
}

OpenChannelParams houses the params to specify when opening a new channel.

type RPCClients added in v0.6.0

type RPCClients struct {
	LN               lnrpc.LightningClient
	WalletUnlocker   lnrpc.WalletUnlockerClient
	Invoice          invoicesrpc.InvoicesClient
	Signer           signrpc.SignerClient
	Router           routerrpc.RouterClient
	WalletKit        walletrpc.WalletKitClient
	Watchtower       watchtowerrpc.WatchtowerClient
	WatchtowerClient wtclientrpc.WatchtowerClientClient
	State            lnrpc.StateClient
	// contains filtered or unexported fields
}

RPCClients wraps a list of RPC clients into a single struct for easier access.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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