Skip to content

Commit

Permalink
cleanup: remove openchannel rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Feb 8, 2024
1 parent a072e5c commit 81019b0
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 429 deletions.
46 changes: 0 additions & 46 deletions channel_opener_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"github.com/breez/lspd/btceclegacy"
"github.com/breez/lspd/common"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
lspdrpc "github.com/breez/lspd/rpc"
ecies "github.com/ecies/go/v2"
"google.golang.org/protobuf/proto"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwire"
)

Expand Down Expand Up @@ -169,50 +167,6 @@ func (s *channelOpenerServer) RegisterPayment(
return &lspdrpc.RegisterPaymentReply{}, nil
}

func (s *channelOpenerServer) OpenChannel(ctx context.Context, in *lspdrpc.OpenChannelRequest) (*lspdrpc.OpenChannelReply, error) {
node, _, err := lspdrpc.GetNode(ctx)
if err != nil {
return nil, err
}

r, err, _ := node.OpenChannelReqGroup.Do(in.Pubkey, func() (interface{}, error) {
pubkey, err := hex.DecodeString(in.Pubkey)
if err != nil {
return nil, err
}

channelCount, err := node.Client.GetNodeChannelCount(pubkey)
if err != nil {
return nil, err
}

var outPoint *wire.OutPoint
if channelCount == 0 {
outPoint, err = node.Client.OpenChannel(&lightning.OpenChannelRequest{
CapacitySat: node.NodeConfig.ChannelAmount,
Destination: pubkey,
TargetConf: &node.NodeConfig.TargetConf,
MinHtlcMsat: node.NodeConfig.MinHtlcMsat,
IsPrivate: node.NodeConfig.ChannelPrivate,
})

if err != nil {
log.Printf("Error in OpenChannel: %v", err)
return nil, err
}

log.Printf("Response from OpenChannel: (TX: %v)", outPoint.String())
}

return &lspdrpc.OpenChannelReply{TxHash: outPoint.Hash.String(), OutputIndex: outPoint.Index}, nil
})

if err != nil {
return nil, err
}
return r.(*lspdrpc.OpenChannelReply), err
}

func getSignedEncryptedData(n *common.Node, in *lspdrpc.Encrypted) (string, []byte, bool, error) {
usedEcies := true
signedBlob, err := ecies.Decrypt(n.EciesPrivateKey, in.Data)
Expand Down
35 changes: 3 additions & 32 deletions cln/cln_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ func (c *ClnClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi
m := uint16(*req.MinConfs)
minConfs = &m
}
var minDepth *uint16
if req.IsZeroConf {
var d uint16 = 0
minDepth = &d
}

var minDepth uint16 = 0
var rate *glightning.FeeRate
if req.FeeSatPerVByte != nil {
rate = &glightning.FeeRate{
Expand All @@ -163,10 +158,10 @@ func (c *ClnClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi
pubkey,
glightning.NewSat(int(req.CapacitySat)),
rate,
!req.IsPrivate,
false,
minConfs,
glightning.NewMsat(0),
minDepth,
&minDepth,
glightning.NewMsat(0),
)

Expand Down Expand Up @@ -233,30 +228,6 @@ func (c *ClnClient) GetChannel(peerID []byte, channelPoint wire.OutPoint) (*ligh
return nil, fmt.Errorf("no channel found")
}

func (c *ClnClient) GetNodeChannelCount(nodeID []byte) (int, error) {
client, err := c.getClient()
if err != nil {
return 0, err
}

pubkey := hex.EncodeToString(nodeID)
channels, err := client.GetPeerChannels(pubkey)
if err != nil {
log.Printf("CLN: client.GetPeer(%s) error: %v", pubkey, err)
return 0, err
}

count := 0
openPendingStatuses := append(OPEN_STATUSES, PENDING_STATUSES...)
for _, c := range channels {
if slices.Contains(openPendingStatuses, c.State) {
count++
}
}

return count, nil
}

func (c *ClnClient) GetClosedChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error) {
client, err := c.getClient()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions interceptor/intercept_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,6 @@ func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmoun
Destination: destination,
CapacitySat: uint64(capacity),
MinConfs: i.config.MinConfs,
IsPrivate: true,
IsZeroConf: true,
FeeSatPerVByte: fee.SatPerVByte,
TargetConf: fee.TargetConf,
})
Expand Down
4 changes: 0 additions & 4 deletions lightning/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ type GetChannelResult struct {
type OpenChannelRequest struct {
Destination []byte
CapacitySat uint64
MinHtlcMsat uint64
IsPrivate bool
IsZeroConf bool
MinConfs *uint32
FeeSatPerVByte *float64
TargetConf *uint32
Expand All @@ -34,7 +31,6 @@ type Client interface {
OpenChannel(req *OpenChannelRequest) (*wire.OutPoint, error)
GetChannel(peerID []byte, channelPoint wire.OutPoint) (*GetChannelResult, error)
GetPeerId(scid *ShortChannelID) ([]byte, error)
GetNodeChannelCount(nodeID []byte) (int, error)
GetClosedChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error)
WaitOnline(peerID []byte, deadline time.Time) error
WaitChannelActive(peerID []byte, deadline time.Time) error
Expand Down
32 changes: 2 additions & 30 deletions lnd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func (c *LndClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi
NodePubkey: req.Destination,
LocalFundingAmount: int64(req.CapacitySat),
PushSat: 0,
Private: req.IsPrivate,
Private: true,
CommitmentType: lnrpc.CommitmentType_ANCHORS,
ZeroConf: req.IsZeroConf,
ZeroConf: true,
}

if req.MinConfs != nil {
Expand Down Expand Up @@ -316,34 +316,6 @@ func (c *LndClient) GetChannel(peerID []byte, channelPoint wire.OutPoint) (*ligh
return nil, fmt.Errorf("no channel found")
}

func (c *LndClient) GetNodeChannelCount(nodeID []byte) (int, error) {
nodeIDStr := hex.EncodeToString(nodeID)
listResponse, err := c.client.ListChannels(context.Background(), &lnrpc.ListChannelsRequest{})
if err != nil {
return 0, err
}

pendingResponse, err := c.client.PendingChannels(context.Background(), &lnrpc.PendingChannelsRequest{})
if err != nil {
return 0, err
}

count := 0
for _, channel := range listResponse.Channels {
if channel.RemotePubkey == nodeIDStr {
count++
}
}

for _, p := range pendingResponse.PendingOpenChannels {
if p.Channel.RemoteNodePub == nodeIDStr {
count++
}
}

return count, nil
}

func (c *LndClient) GetClosedChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error) {
r := make(map[string]uint64)
if len(channelPoints) == 0 {
Expand Down
2 changes: 0 additions & 2 deletions lsps2/intercept_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
Destination: destination,
CapacitySat: uint64(capacity),
MinConfs: i.config.MinConfs,
IsPrivate: true,
IsZeroConf: true,
FeeSatPerVByte: fee.SatPerVByte,
TargetConf: fee.TargetConf,
})
Expand Down
3 changes: 0 additions & 3 deletions lsps2/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ func (c *mockLightningClient) GetChannel(peerID []byte, channelPoint wire.OutPoi
func (c *mockLightningClient) GetPeerId(scid *lightning.ShortChannelID) ([]byte, error) {
return nil, ErrNotImplemented
}
func (c *mockLightningClient) GetNodeChannelCount(nodeID []byte) (int, error) {
return 0, ErrNotImplemented
}
func (c *mockLightningClient) GetClosedChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error) {
return nil, ErrNotImplemented
}
Expand Down
33 changes: 0 additions & 33 deletions rpc/lspd.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
- [lspd.proto](#lspd.proto)
- [ChannelInformationReply](#lspd.ChannelInformationReply)
- [ChannelInformationRequest](#lspd.ChannelInformationRequest)
- [OpenChannelReply](#lspd.OpenChannelReply)
- [OpenChannelRequest](#lspd.OpenChannelRequest)
- [PaymentInformation](#lspd.PaymentInformation)
- [RegisterPaymentReply](#lspd.RegisterPaymentReply)
- [RegisterPaymentRequest](#lspd.RegisterPaymentRequest)
Expand Down Expand Up @@ -68,36 +66,6 @@



<a name="lspd.OpenChannelReply"></a>

### OpenChannelReply



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| tx_hash | [string](#string) | | The transaction hash |
| output_index | [uint32](#uint32) | | The output index |






<a name="lspd.OpenChannelRequest"></a>

### OpenChannelRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| pubkey | [string](#string) | | The identity pubkey of the Lightning node |






<a name="lspd.PaymentInformation"></a>

Expand Down Expand Up @@ -157,7 +125,6 @@
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| ChannelInformation | [ChannelInformationRequest](#lspd.ChannelInformationRequest) | [ChannelInformationReply](#lspd.ChannelInformationReply) | |
| OpenChannel | [OpenChannelRequest](#lspd.OpenChannelRequest) | [OpenChannelReply](#lspd.OpenChannelReply) | |
| RegisterPayment | [RegisterPaymentRequest](#lspd.RegisterPaymentRequest) | [RegisterPaymentReply](#lspd.RegisterPaymentReply) | |


Expand Down
Loading

0 comments on commit 81019b0

Please sign in to comment.