mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-20 07:14:22 +01:00
populate name and pubkey from config or node
This commit is contained in:
@@ -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"`
|
||||
|
||||
39
itest/config_test.go
Normal file
39
itest/config_test.go
Normal file
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -17,4 +17,4 @@ CHANNELMISMATCH_NOTIFICATION_TO='["Name1 <user1@domain.com>"]'
|
||||
CHANNELMISMATCH_NOTIFICATION_CC='["Name2 <user2@domain.com>","Name3 <user3@domain.com>"]'
|
||||
CHANNELMISMATCH_NOTIFICATION_FROM="Name4 <user4@domain.com>"
|
||||
|
||||
NODES='[ { "lspdPrivateKey": "<LSPD PRIVATE KEY>", "token": "<ACCESS TOKEN>", "host": "<HOSTNAME:PORT for lightning clients>", "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": "<HOSTNAME:PORT>", "cert": "<LND_CERT base64>", "macaroon": "<LND_MACAROON hex>" } }, { "lspdPrivateKey": "<LSPD PRIVATE KEY>", "token": "<ACCESS TOKEN>", "host": "<HOSTNAME:PORT for lightning clients>", "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": "<address the lsp cln plugin listens on (ip:port)>", "socketPath": "<path to the cln lightning-rpc socket file>" } } ]'
|
||||
NODES='[ { "name": "<LSP NAME>", "nodePubkey": "<LIGHTNING NODE PUBKEY>", "lspdPrivateKey": "<LSPD PRIVATE KEY>", "token": "<ACCESS TOKEN>", "host": "<HOSTNAME:PORT for lightning clients>", "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": "<HOSTNAME:PORT>", "cert": "<LND_CERT base64>", "macaroon": "<LND_MACAROON hex>" } }, { "name": "<LSP NAME>", "nodePubkey": "<LIGHTNING NODE PUBKEY>", "lspdPrivateKey": "<LSPD PRIVATE KEY>", "token": "<ACCESS TOKEN>", "host": "<HOSTNAME:PORT for lightning clients>", "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": "<address the lsp cln plugin listens on (ip:port)>", "socketPath": "<path to the cln lightning-rpc socket file>" } } ]'
|
||||
|
||||
24
server.go
24
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
|
||||
|
||||
Reference in New Issue
Block a user