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
|
package main
|
||||||
|
|
||||||
type NodeConfig struct {
|
type NodeConfig struct {
|
||||||
|
Name string `json:name,omitempty`
|
||||||
|
NodePubkey string `json:nodePubkey,omitempty`
|
||||||
LspdPrivateKey string `json:"lspdPrivateKey"`
|
LspdPrivateKey string `json:"lspdPrivateKey"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Host string `json:"host"`
|
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 := 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,`+
|
` "publicChannelAmount": "1000183", "channelAmount": "100000", "channelPrivate": false,`+
|
||||||
` "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001",`+
|
` "targetConf": "6", "minHtlcMsat": "600", "baseFeeMsat": "1000", "feeRate": "0.000001",`+
|
||||||
` "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000",`+
|
` "timeLockDelta": "144", "channelFeePermyriad": "40", "channelMinimumFeeMsat": "2000000",`+
|
||||||
` "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", %s}]'`,
|
` "additionalChannelCapacity": "100000", "maxInactiveDuration": "3888000", %s}]'`,
|
||||||
|
name,
|
||||||
lspdPrivateKeyBytes,
|
lspdPrivateKeyBytes,
|
||||||
ext,
|
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_CC='["Name2 <user2@domain.com>","Name3 <user3@domain.com>"]'
|
||||||
CHANNELMISMATCH_NOTIFICATION_FROM="Name4 <user4@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 {
|
type node struct {
|
||||||
client LightningClient
|
client LightningClient
|
||||||
nodeName string
|
|
||||||
nodePubkey string
|
|
||||||
nodeConfig *NodeConfig
|
nodeConfig *NodeConfig
|
||||||
privateKey *btcec.PrivateKey
|
privateKey *btcec.PrivateKey
|
||||||
publicKey *btcec.PublicKey
|
publicKey *btcec.PublicKey
|
||||||
@@ -54,8 +52,8 @@ func (s *server) ChannelInformation(ctx context.Context, in *lspdrpc.ChannelInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &lspdrpc.ChannelInformationReply{
|
return &lspdrpc.ChannelInformationReply{
|
||||||
Name: node.nodeName,
|
Name: node.nodeConfig.Name,
|
||||||
Pubkey: node.nodePubkey,
|
Pubkey: node.nodeConfig.NodePubkey,
|
||||||
Host: node.nodeConfig.Host,
|
Host: node.nodeConfig.Host,
|
||||||
ChannelCapacity: int64(node.nodeConfig.PublicChannelAmount),
|
ChannelCapacity: int64(node.nodeConfig.PublicChannelAmount),
|
||||||
TargetConf: int32(node.nodeConfig.TargetConf),
|
TargetConf: int32(node.nodeConfig.TargetConf),
|
||||||
@@ -284,7 +282,6 @@ func NewGrpcServer(configs []*NodeConfig, address string, certmagicDomain string
|
|||||||
eciesPublicKey := eciesPrivateKey.PublicKey
|
eciesPublicKey := eciesPrivateKey.PublicKey
|
||||||
privateKey, publicKey := btcec.PrivKeyFromBytes(pk)
|
privateKey, publicKey := btcec.PrivKeyFromBytes(pk)
|
||||||
|
|
||||||
// TODO: Set nodename & nodepubkey
|
|
||||||
node := &node{
|
node := &node{
|
||||||
nodeConfig: config,
|
nodeConfig: config,
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
@@ -331,6 +328,23 @@ func NewGrpcServer(configs []*NodeConfig, address string, certmagicDomain string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) Start() error {
|
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
|
var lis net.Listener
|
||||||
if s.certmagicDomain == "" {
|
if s.certmagicDomain == "" {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
Reference in New Issue
Block a user