Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

fix: respect LSPS1 channel max expiry blocks #449

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions lsp/lsp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ type lspService struct {
logger *logrus.Logger
}

type lspConnectionInfo struct {
Pubkey string
Address string
Port uint16
type lspInfo struct {
Pubkey string
Address string
Port uint16
MaxChannelExpiryBlocks uint64
}

func NewLSPService(svc service.Service, logger *logrus.Logger) *lspService {
Expand Down Expand Up @@ -69,7 +70,7 @@ func (ls *lspService) NewInstantChannelInvoice(ctx context.Context, request *New

ls.logger.Infoln("Requesting LSP info")

var lspInfo *lspConnectionInfo
var lspInfo *lspInfo
var err error
switch selectedLsp.LspType {
case LSP_TYPE_FLOW_2_0:
Expand Down Expand Up @@ -120,7 +121,7 @@ func (ls *lspService) NewInstantChannelInvoice(ctx context.Context, request *New
case LSP_TYPE_PMLSP:
invoice, fee, err = ls.requestPMLSPInvoice(&selectedLsp, request.Amount, nodeInfo.Pubkey)
case LSP_TYPE_LSPS1:
invoice, fee, err = ls.requestLSPS1Invoice(ctx, &selectedLsp, request.Amount, nodeInfo.Pubkey, request.Public)
invoice, fee, err = ls.requestLSPS1Invoice(ctx, &selectedLsp, request.Amount, nodeInfo.Pubkey, request.Public, lspInfo.MaxChannelExpiryBlocks)

default:
return nil, fmt.Errorf("unsupported LSP type: %v", selectedLsp.LspType)
Expand All @@ -142,13 +143,16 @@ func (ls *lspService) NewInstantChannelInvoice(ctx context.Context, request *New
return newChannelResponse, nil
}

func (ls *lspService) getLSPS1LSPInfo(url string) (*lspConnectionInfo, error) {
type LSPS1LSPInfo struct {
// TODO: implement options
Options interface{} `json:"options"`
URIs []string `json:"uris"`
func (ls *lspService) getLSPS1LSPInfo(url string) (*lspInfo, error) {

type lsps1LSPInfoOptions struct {
MaxChannelExpiryBlocks uint64 `json:"max_channel_expiry_blocks"`
}
type lsps1LSPInfo struct {
Options lsps1LSPInfoOptions `json:"options"`
URIs []string `json:"uris"`
}
var lsps1LspInfo LSPS1LSPInfo
var lsps1LspInfo lsps1LSPInfo
client := http.Client{
Timeout: time.Second * 10,
}
Expand Down Expand Up @@ -204,13 +208,14 @@ func (ls *lspService) getLSPS1LSPInfo(url string) (*lspConnectionInfo, error) {
return nil, err
}

return &lspConnectionInfo{
Pubkey: parts[1],
Address: parts[2],
Port: uint16(port),
return &lspInfo{
Pubkey: parts[1],
Address: parts[2],
Port: uint16(port),
MaxChannelExpiryBlocks: lsps1LspInfo.Options.MaxChannelExpiryBlocks,
}, nil
}
func (ls *lspService) getFlowLSPInfo(url string) (*lspConnectionInfo, error) {
func (ls *lspService) getFlowLSPInfo(url string) (*lspInfo, error) {
type FlowLSPConnectionMethod struct {
Address string `json:"address"`
Port uint16 `json:"port"`
Expand Down Expand Up @@ -271,7 +276,7 @@ func (ls *lspService) getFlowLSPInfo(url string) (*lspConnectionInfo, error) {
return nil, errors.New("unexpected LSP connection method")
}

return &lspConnectionInfo{
return &lspInfo{
Pubkey: flowLspInfo.Pubkey,
Address: flowLspInfo.ConnectionMethods[ipIndex].Address,
Port: flowLspInfo.ConnectionMethods[ipIndex].Port,
Expand Down Expand Up @@ -520,7 +525,7 @@ func (ls *lspService) requestPMLSPInvoice(selectedLsp *LSP, amount uint64, pubke
return invoice, fee, nil
}

func (ls *lspService) requestLSPS1Invoice(ctx context.Context, selectedLsp *LSP, amount uint64, pubkey string, public bool) (invoice string, fee uint64, err error) {
func (ls *lspService) requestLSPS1Invoice(ctx context.Context, selectedLsp *LSP, amount uint64, pubkey string, public bool, channelExpiryBlocks uint64) (invoice string, fee uint64, err error) {
client := http.Client{
Timeout: time.Second * 10,
}
Expand Down Expand Up @@ -557,7 +562,7 @@ func (ls *lspService) requestLSPS1Invoice(ctx context.Context, selectedLsp *LSP,
ClientBalanceSat: "0",
RequiredChannelConfirmations: requiredChannelConfirmations,
FundingConfirmsWithinBlocks: 6,
ChannelExpiryBlocks: 13000, // TODO: this should be customizable
ChannelExpiryBlocks: channelExpiryBlocks,
Token: "",
RefundOnchainAddress: refundAddress,
AnnounceChannel: public,
Expand Down
Loading