Add RPC to show current total available channel capacity #29 (#35)

This commit adds a new RPC command: `channelbalance` which returns the
sum of all available channel capacity across all open channels. The
total balance is currently returned in units of `satoshis`. Additionally
the `networkHarness` has been modified slightly to allow specifying the
additional "extra" command line parameters when creating the initial
seed nodes. Minor refactoring within the integration tests has been
undertaken in order to increase code re-use across tests.

Closes #29.
This commit is contained in:
andrew.shvv authored and Olaoluwa Osuntokun committed 2016-09-15 12:00:56 -07:00
1 parent 4c01e42670
commit 2788dbeaa8
9 files changed
+415 -239

No files matched your search

+16 -17
View File
@@ -262,14 +262,11 @@ type networkHarness struct {
watchRequests chan *watchRequest
}
// newNetworkHarness creates a new network test harness given an already
// running instance of btcd's rpctest harness. Any extra command line flags
// which should be passed to create lnd instance should be formatted properly
// in the lndArgs slice (--arg=value).
// 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'll save developers from having to manually `go install`
// within the repo each time before changes.
func newNetworkHarness(lndArgs []string) (*networkHarness, error) {
// within the repo each time before changes
func newNetworkHarness() (*networkHarness, error) {
return &networkHarness{
activeNodes: make(map[int]*lightningNode),
seenTxns: make(chan wire.ShaHash),
@@ -277,7 +274,11 @@ func newNetworkHarness(lndArgs []string) (*networkHarness, error) {
}, nil
}
func (n *networkHarness) InitializeSeedNodes(r *rpctest.Harness) error {
// InitializeSeedNodes initialized alice and bob nodes given an already
// running instance of btcd's rpctest harness and extra command line flags,
// which should be formatted properly - "--arg=value".
func (n *networkHarness) InitializeSeedNodes(r *rpctest.Harness, lndArgs []string) error {
nodeConfig := r.RPCConfig()
n.netParams = r.ActiveNet
@@ -285,11 +286,11 @@ func (n *networkHarness) InitializeSeedNodes(r *rpctest.Harness) error {
n.rpcConfig = nodeConfig
var err error
n.Alice, err = newLightningNode(&nodeConfig, nil)
n.Alice, err = newLightningNode(&nodeConfig, lndArgs)
if err != nil {
return err
}
n.Bob, err = newLightningNode(&nodeConfig, nil)
n.Bob, err = newLightningNode(&nodeConfig, lndArgs)
if err != nil {
return err
}
@@ -511,7 +512,7 @@ func (n *networkHarness) WaitForTxBroadcast(txid wire.ShaHash) {
}
// OpenChannel attemps to open a channel between srcNode and destNode with the
// passed channel funding paramters.
// passed channel funding parameters.
func (n *networkHarness) OpenChannel(ctx context.Context,
srcNode, destNode *lightningNode, amt btcutil.Amount,
numConfs uint32) (lnrpc.Lightning_OpenChannelClient, error) {
@@ -521,6 +522,7 @@ func (n *networkHarness) OpenChannel(ctx context.Context,
LocalFundingAmount: int64(amt),
NumConfs: numConfs,
}
respStream, err := srcNode.OpenChannel(ctx, openReq)
if err != nil {
return nil, fmt.Errorf("unable to open channel between "+
@@ -634,18 +636,15 @@ func (n *networkHarness) AssertChannelExists(ctx context.Context,
// 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 (n *networkHarness) DumpLogs(node *lightningNode) (string, error) {
logFile := fmt.Sprintf("%v/simnet/lnd.log", node.cfg.LogDir)
f, err := os.Open(logFile)
if err != nil {
return "", err
}
defer f.Close()
logs, err := ioutil.ReadAll(f)
buf, err := ioutil.ReadFile(logFile)
if err != nil {
return "", err
}
return string(logs), nil
return string(buf), nil
}