diff --git a/config.go b/config.go index a367682..af9261b 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,8 @@ package main type NodeConfig struct { + Name string `json:name,omitempty` + NodePubkey string `json:nodePubkey,omitempty` LspdPrivateKey string `json:"lspdPrivateKey"` Token string `json:"token"` Host string `json:"host"` diff --git a/itest/config_test.go b/itest/config_test.go new file mode 100644 index 0000000..8134902 --- /dev/null +++ b/itest/config_test.go @@ -0,0 +1,39 @@ +package itest + +import ( + "encoding/hex" + "log" + "testing" + "time" + + "github.com/breez/lntest" + lspd "github.com/breez/lspd/rpc" + "github.com/stretchr/testify/assert" +) + +func TestConfigParameters(t *testing.T) { + deadline, _ := t.Deadline() + h := lntest.NewTestHarness(t, deadline) + defer h.TearDown() + + m := lntest.NewMiner(h) + m.Start() + + lsp := NewClnLspdNode(h, m, "lsp") + lsp.Start() + + log.Printf("Waiting %v to allow lsp server to activate.", htlcInterceptorDelay) + <-time.After(htlcInterceptorDelay) + + info, err := lsp.Rpc().ChannelInformation( + h.Ctx, + &lspd.ChannelInformationRequest{}, + ) + + if err != nil { + t.Fatalf("failed to get channelinformation: %v", err) + } + + assert.Equal(t, hex.EncodeToString(lsp.LightningNode().NodeId()), info.Pubkey) + assert.Equal(t, "lsp", info.Name) +} diff --git a/itest/lspd_node.go b/itest/lspd_node.go index 16ac1a2..df1fc15 100644 --- a/itest/lspd_node.go +++ b/itest/lspd_node.go @@ -97,11 +97,12 @@ func newLspd(h *lntest.TestHarness, name string, lnd *string, cln *string, envEx } nodes := fmt.Sprintf( - `NODES='[ { "lspdPrivateKey": "%x", "token": "hello", "host": "host:port",`+ + `NODES='[ { "name": "%s", "lspdPrivateKey": "%x", "token": "hello", "host": "host:port",`+ ` "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false,`+ ` "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001",`+ ` "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000",`+ ` "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", %s}]'`, + name, lspdPrivateKeyBytes, ext, ) diff --git a/sample.env b/sample.env index 407136a..1057b32 100644 --- a/sample.env +++ b/sample.env @@ -17,4 +17,4 @@ CHANNELMISMATCH_NOTIFICATION_TO='["Name1 "]' CHANNELMISMATCH_NOTIFICATION_CC='["Name2 ","Name3 "]' CHANNELMISMATCH_NOTIFICATION_FROM="Name4 " -NODES='[ { "lspdPrivateKey": "", "token": "", "host": "", "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false, "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001", "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000", "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", "lnd": { "address": "", "cert": "", "macaroon": "" } }, { "lspdPrivateKey": "", "token": "", "host": "", "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false, "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001", "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000", "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", "cln": { "pluginAddress": "
", "socketPath": "" } } ]' +NODES='[ { "name": "", "nodePubkey": "", "lspdPrivateKey": "", "token": "", "host": "", "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false, "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001", "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000", "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", "lnd": { "address": "", "cert": "", "macaroon": "" } }, { "name": "", "nodePubkey": "", "lspdPrivateKey": "", "token": "", "host": "", "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false, "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001", "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000", "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", "cln": { "pluginAddress": "
", "socketPath": "" } } ]' diff --git a/server.go b/server.go index cfae080..16e2069 100644 --- a/server.go +++ b/server.go @@ -37,8 +37,6 @@ type server struct { type node struct { client LightningClient - nodeName string - nodePubkey string nodeConfig *NodeConfig privateKey *btcec.PrivateKey publicKey *btcec.PublicKey @@ -54,8 +52,8 @@ func (s *server) ChannelInformation(ctx context.Context, in *lspdrpc.ChannelInfo } return &lspdrpc.ChannelInformationReply{ - Name: node.nodeName, - Pubkey: node.nodePubkey, + Name: node.nodeConfig.Name, + Pubkey: node.nodeConfig.NodePubkey, Host: node.nodeConfig.Host, ChannelCapacity: int64(node.nodeConfig.PublicChannelAmount), TargetConf: int32(node.nodeConfig.TargetConf), @@ -284,7 +282,6 @@ func NewGrpcServer(configs []*NodeConfig, address string, certmagicDomain string eciesPublicKey := eciesPrivateKey.PublicKey privateKey, publicKey := btcec.PrivKeyFromBytes(pk) - // TODO: Set nodename & nodepubkey node := &node{ nodeConfig: config, privateKey: privateKey, @@ -331,6 +328,23 @@ func NewGrpcServer(configs []*NodeConfig, address string, certmagicDomain string } func (s *server) Start() error { + // Make sure all nodes are available and set name and pubkey if not set + // in config. + for _, n := range s.nodes { + info, err := n.client.GetInfo() + if err != nil { + return fmt.Errorf("failed to get info from host %s", n.nodeConfig.Host) + } + + if n.nodeConfig.Name == "" { + n.nodeConfig.Name = info.Alias + } + + if n.nodeConfig.NodePubkey == "" { + n.nodeConfig.NodePubkey = info.Pubkey + } + } + var lis net.Listener if s.certmagicDomain == "" { var err error