mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-20 07:14:22 +01:00
cln: use amt_to_forward in payload to charge fees
This commit is contained in:
@@ -211,7 +211,7 @@ func (i *ClnHtlcInterceptor) resumeWithOnion(request *proto.HtlcAccepted, interc
|
|||||||
log.Printf("resumeWithOnion: hex.DecodeString(%v) error: %v", request.Onion.Payload, err)
|
log.Printf("resumeWithOnion: hex.DecodeString(%v) error: %v", request.Onion.Payload, err)
|
||||||
return i.failWithCode(request, interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE)
|
return i.failWithCode(request, interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE)
|
||||||
}
|
}
|
||||||
newPayload, err := encodePayloadWithNextHop(payload, interceptResult.ChannelId)
|
newPayload, err := encodePayloadWithNextHop(payload, interceptResult.ChannelId, interceptResult.AmountMsat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("encodePayloadWithNextHop error: %v", err)
|
log.Printf("encodePayloadWithNextHop error: %v", err)
|
||||||
return i.failWithCode(request, interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE)
|
return i.failWithCode(request, interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE)
|
||||||
@@ -254,7 +254,7 @@ func (i *ClnHtlcInterceptor) failWithCode(request *proto.HtlcAccepted, code inte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodePayloadWithNextHop(payload []byte, channelId uint64) ([]byte, error) {
|
func encodePayloadWithNextHop(payload []byte, channelId uint64, amountToForward uint64) ([]byte, error) {
|
||||||
bufReader := bytes.NewBuffer(payload)
|
bufReader := bytes.NewBuffer(payload)
|
||||||
var b [8]byte
|
var b [8]byte
|
||||||
varInt, err := sphinx.ReadVarInt(bufReader, &b)
|
varInt, err := sphinx.ReadVarInt(bufReader, &b)
|
||||||
@@ -274,15 +274,26 @@ func encodePayloadWithNextHop(payload []byte, channelId uint64) ([]byte, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tt := record.NewNextHopIDRecord(&channelId)
|
tt := record.NewNextHopIDRecord(&channelId)
|
||||||
buf := bytes.NewBuffer([]byte{})
|
ttbuf := bytes.NewBuffer([]byte{})
|
||||||
if err := tt.Encode(buf); err != nil {
|
if err := tt.Encode(ttbuf); err != nil {
|
||||||
return nil, fmt.Errorf("failed to encode nexthop %x: %v", innerPayload[:], err)
|
return nil, fmt.Errorf("failed to encode nexthop %x: %v", innerPayload[:], err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amt := record.NewAmtToFwdRecord(&amountToForward)
|
||||||
|
amtbuf := bytes.NewBuffer([]byte{})
|
||||||
|
if err := amt.Encode(amtbuf); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to encode AmtToFwd %x: %v", innerPayload[:], err)
|
||||||
|
}
|
||||||
|
|
||||||
uTlvMap := make(map[uint64][]byte)
|
uTlvMap := make(map[uint64][]byte)
|
||||||
for t, b := range tlvMap {
|
for t, b := range tlvMap {
|
||||||
if t == record.NextHopOnionType {
|
if t == record.NextHopOnionType {
|
||||||
uTlvMap[uint64(t)] = buf.Bytes()
|
uTlvMap[uint64(t)] = ttbuf.Bytes()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == record.AmtOnionType {
|
||||||
|
uTlvMap[uint64(t)] = amtbuf.Bytes()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
uTlvMap[uint64(t)] = b
|
uTlvMap[uint64(t)] = b
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func testFailureBobOffline(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -33,6 +33,7 @@ func testFailureBobOffline(p *testParams) {
|
|||||||
lsp: p.lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ func testFailureBobOffline(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Kill the mobile client
|
// Kill the mobile client
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type BreezClient interface {
|
|||||||
Node() lntest.LightningNode
|
Node() lntest.LightningNode
|
||||||
Start()
|
Start()
|
||||||
Stop() error
|
Stop() error
|
||||||
|
SetHtlcAcceptor(totalMsat uint64)
|
||||||
}
|
}
|
||||||
|
|
||||||
type generateInvoicesRequest struct {
|
type generateInvoicesRequest struct {
|
||||||
|
|||||||
@@ -2,12 +2,26 @@ package itest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/breez/lntest"
|
"github.com/breez/lntest"
|
||||||
|
"github.com/breez/lspd/cln_plugin/proto"
|
||||||
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/record"
|
||||||
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
"google.golang.org/grpc/keepalive"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pluginContent string = `#!/usr/bin/env python3
|
var pluginContent string = `#!/usr/bin/env python3
|
||||||
@@ -40,6 +54,9 @@ type clnBreezClient struct {
|
|||||||
name string
|
name string
|
||||||
scriptDir string
|
scriptDir string
|
||||||
pluginFilePath string
|
pluginFilePath string
|
||||||
|
htlcAcceptorAddress string
|
||||||
|
htlcAcceptor func(*proto.HtlcAccepted) *proto.HtlcResolution
|
||||||
|
htlcAcceptorCancel context.CancelFunc
|
||||||
harness *lntest.TestHarness
|
harness *lntest.TestHarness
|
||||||
isInitialized bool
|
isInitialized bool
|
||||||
node *lntest.ClnNode
|
node *lntest.ClnNode
|
||||||
@@ -49,11 +66,19 @@ type clnBreezClient struct {
|
|||||||
func newClnBreezClient(h *lntest.TestHarness, m *lntest.Miner, name string) BreezClient {
|
func newClnBreezClient(h *lntest.TestHarness, m *lntest.Miner, name string) BreezClient {
|
||||||
scriptDir := h.GetDirectory(name)
|
scriptDir := h.GetDirectory(name)
|
||||||
pluginFilePath := filepath.Join(scriptDir, "start_zero_conf_plugin.sh")
|
pluginFilePath := filepath.Join(scriptDir, "start_zero_conf_plugin.sh")
|
||||||
|
htlcAcceptorPort, err := lntest.GetPort()
|
||||||
|
if err != nil {
|
||||||
|
h.T.Fatalf("Could not get port for htlc acceptor plugin: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
htlcAcceptorAddress := fmt.Sprintf("127.0.0.1:%v", htlcAcceptorPort)
|
||||||
node := lntest.NewClnNode(
|
node := lntest.NewClnNode(
|
||||||
h,
|
h,
|
||||||
m,
|
m,
|
||||||
name,
|
name,
|
||||||
fmt.Sprintf("--plugin=%s", pluginFilePath),
|
fmt.Sprintf("--plugin=%s", pluginFilePath),
|
||||||
|
fmt.Sprintf("--plugin=%s", *clnPluginExec),
|
||||||
|
fmt.Sprintf("--lsp.listen=%s", htlcAcceptorAddress),
|
||||||
// NOTE: max-concurrent-htlcs is 30 on mainnet by default. In cln V22.11
|
// NOTE: max-concurrent-htlcs is 30 on mainnet by default. In cln V22.11
|
||||||
// there is a check for 'all dust' commitment transactions. The max
|
// there is a check for 'all dust' commitment transactions. The max
|
||||||
// concurrent HTLCs of both sides of the channel * dust limit must be
|
// concurrent HTLCs of both sides of the channel * dust limit must be
|
||||||
@@ -69,6 +94,7 @@ func newClnBreezClient(h *lntest.TestHarness, m *lntest.Miner, name string) Bree
|
|||||||
node: node,
|
node: node,
|
||||||
scriptDir: scriptDir,
|
scriptDir: scriptDir,
|
||||||
pluginFilePath: pluginFilePath,
|
pluginFilePath: pluginFilePath,
|
||||||
|
htlcAcceptorAddress: htlcAcceptorAddress,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +120,151 @@ func (c *clnBreezClient) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.node.Start()
|
c.node.Start()
|
||||||
|
c.startHtlcAcceptor()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *clnBreezClient) SetHtlcAcceptor(totalMsat uint64) {
|
||||||
|
c.htlcAcceptor = func(htlc *proto.HtlcAccepted) *proto.HtlcResolution {
|
||||||
|
origPayload, err := hex.DecodeString(htlc.Onion.Payload)
|
||||||
|
if err != nil {
|
||||||
|
c.harness.T.Fatalf("failed to hex decode onion payload %s: %v", htlc.Onion.Payload, err)
|
||||||
|
}
|
||||||
|
bufReader := bytes.NewBuffer(origPayload)
|
||||||
|
var b [8]byte
|
||||||
|
varInt, err := sphinx.ReadVarInt(bufReader, &b)
|
||||||
|
if err != nil {
|
||||||
|
c.harness.T.Fatalf("Failed to read payload: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
innerPayload := make([]byte, varInt)
|
||||||
|
if _, err := io.ReadFull(bufReader, innerPayload[:]); err != nil {
|
||||||
|
c.harness.T.Fatalf("failed to decode payload %x: %v", innerPayload[:], err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s, _ := tlv.NewStream()
|
||||||
|
tlvMap, err := s.DecodeWithParsedTypes(bytes.NewReader(innerPayload))
|
||||||
|
if err != nil {
|
||||||
|
c.harness.T.Fatalf("DecodeWithParsedTypes failed for %x: %v", innerPayload[:], err)
|
||||||
|
}
|
||||||
|
|
||||||
|
amt := record.NewAmtToFwdRecord(&htlc.Htlc.AmountMsat)
|
||||||
|
amtbuf := bytes.NewBuffer([]byte{})
|
||||||
|
if err := amt.Encode(amtbuf); err != nil {
|
||||||
|
c.harness.T.Fatalf("failed to encode AmtToFwd %x: %v", innerPayload[:], err)
|
||||||
|
}
|
||||||
|
|
||||||
|
uTlvMap := make(map[uint64][]byte)
|
||||||
|
for t, b := range tlvMap {
|
||||||
|
if t == record.AmtOnionType {
|
||||||
|
uTlvMap[uint64(t)] = amtbuf.Bytes()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == record.MPPOnionType {
|
||||||
|
addr := [32]byte{}
|
||||||
|
copy(addr[:], b[:32])
|
||||||
|
mppbuf := bytes.NewBuffer([]byte{})
|
||||||
|
mpp := record.NewMPP(
|
||||||
|
lnwire.MilliSatoshi(totalMsat),
|
||||||
|
addr,
|
||||||
|
)
|
||||||
|
record := mpp.Record()
|
||||||
|
record.Encode(mppbuf)
|
||||||
|
uTlvMap[uint64(t)] = mppbuf.Bytes()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
uTlvMap[uint64(t)] = b
|
||||||
|
}
|
||||||
|
tlvRecords := tlv.MapToRecords(uTlvMap)
|
||||||
|
s, err = tlv.NewStream(tlvRecords...)
|
||||||
|
if err != nil {
|
||||||
|
c.harness.T.Fatalf("tlv.NewStream(%+v) error: %v", tlvRecords, err)
|
||||||
|
}
|
||||||
|
var newPayloadBuf bytes.Buffer
|
||||||
|
err = s.Encode(&newPayloadBuf)
|
||||||
|
if err != nil {
|
||||||
|
c.harness.T.Fatalf("encode error: %v", err)
|
||||||
|
}
|
||||||
|
payload := hex.EncodeToString(newPayloadBuf.Bytes())
|
||||||
|
|
||||||
|
return &proto.HtlcResolution{
|
||||||
|
Correlationid: htlc.Correlationid,
|
||||||
|
Outcome: &proto.HtlcResolution_Continue{
|
||||||
|
Continue: &proto.HtlcContinue{
|
||||||
|
Payload: &payload,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *clnBreezClient) startHtlcAcceptor() {
|
||||||
|
ctx, cancel := context.WithCancel(c.harness.Ctx)
|
||||||
|
c.htlcAcceptorCancel = cancel
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := grpc.DialContext(
|
||||||
|
ctx,
|
||||||
|
c.htlcAcceptorAddress,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
||||||
|
Time: time.Duration(10) * time.Second,
|
||||||
|
Timeout: time.Duration(10) * time.Second,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%s: Dial htlc acceptor error: %v", c.name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
client := proto.NewClnPluginClient(conn)
|
||||||
|
for {
|
||||||
|
acceptor, err := client.HtlcStream(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%s: client.HtlcStream() error: %v", c.name, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
htlc, err := acceptor.Recv()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%s: acceptor.Recv() error: %v", c.name, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
f := c.htlcAcceptor
|
||||||
|
var resp *proto.HtlcResolution
|
||||||
|
if f != nil {
|
||||||
|
resp = f(htlc)
|
||||||
|
}
|
||||||
|
if resp == nil {
|
||||||
|
resp = &proto.HtlcResolution{
|
||||||
|
Correlationid: htlc.Correlationid,
|
||||||
|
Outcome: &proto.HtlcResolution_Continue{
|
||||||
|
Continue: &proto.HtlcContinue{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = acceptor.Send(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%s: acceptor.Send() error: %v", c.name, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clnBreezClient) initialize() error {
|
func (c *clnBreezClient) initialize() error {
|
||||||
@@ -146,10 +317,17 @@ func (c *clnBreezClient) initialize() error {
|
|||||||
lntest.PerformCleanup(cleanups)
|
lntest.PerformCleanup(cleanups)
|
||||||
return fmt.Errorf("failed to flush plugin file '%s': %v", c.pluginFilePath, err)
|
return fmt.Errorf("failed to flush plugin file '%s': %v", c.pluginFilePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lntest.PerformCleanup(cleanups)
|
lntest.PerformCleanup(cleanups)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clnBreezClient) Stop() error {
|
func (c *clnBreezClient) Stop() error {
|
||||||
|
c.mtx.Lock()
|
||||||
|
defer c.mtx.Unlock()
|
||||||
|
if c.htlcAcceptorCancel != nil {
|
||||||
|
c.htlcAcceptorCancel()
|
||||||
|
c.htlcAcceptorCancel = nil
|
||||||
|
}
|
||||||
return c.node.Stop()
|
return c.node.Stop()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,9 +214,6 @@ func (l *ClnLspNode) LightningNode() lntest.LightningNode {
|
|||||||
return l.lightningNode
|
return l.lightningNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ClnLspNode) SupportsChargingFees() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
func (l *ClnLspNode) PostgresBackend() *PostgresContainer {
|
func (l *ClnLspNode) PostgresBackend() *PostgresContainer {
|
||||||
return l.lspBase.postgresBackend
|
return l.lspBase.postgresBackend
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func testInvalidCltv(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -42,7 +42,7 @@ func testInvalidCltv(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func testOpenZeroConfChannelOnReceive(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -34,6 +34,7 @@ func testOpenZeroConfChannelOnReceive(p *testParams) {
|
|||||||
description: description,
|
description: description,
|
||||||
lsp: p.lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
||||||
@@ -44,7 +45,7 @@ func testOpenZeroConfChannelOnReceive(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
@@ -78,7 +79,7 @@ func testOpenZeroConfSingleHtlc(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -88,6 +89,7 @@ func testOpenZeroConfSingleHtlc(p *testParams) {
|
|||||||
lsp: p.lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
||||||
|
|
||||||
@@ -97,7 +99,7 @@ func testOpenZeroConfSingleHtlc(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ func (c *lndBreezClient) Stop() error {
|
|||||||
return c.node.Stop()
|
return c.node.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *lndBreezClient) SetHtlcAcceptor(totalMsat uint64) {
|
||||||
|
// No need for a htlc acceptor in the LND breez client
|
||||||
|
}
|
||||||
|
|
||||||
func (c *lndBreezClient) startChannelAcceptor(ctx context.Context) error {
|
func (c *lndBreezClient) startChannelAcceptor(ctx context.Context) error {
|
||||||
client, err := c.node.LightningClient().ChannelAcceptor(ctx)
|
client, err := c.node.LightningClient().ChannelAcceptor(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -230,10 +230,6 @@ func (c *LndLspNode) Rpc() lspd.ChannelOpenerClient {
|
|||||||
return c.runtime.rpc
|
return c.runtime.rpc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LndLspNode) SupportsChargingFees() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *LndLspNode) NodeId() []byte {
|
func (l *LndLspNode) NodeId() []byte {
|
||||||
return l.lightningNode.NodeId()
|
return l.lightningNode.NodeId()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ type LspNode interface {
|
|||||||
Rpc() lspd.ChannelOpenerClient
|
Rpc() lspd.ChannelOpenerClient
|
||||||
NodeId() []byte
|
NodeId() []byte
|
||||||
LightningNode() lntest.LightningNode
|
LightningNode() lntest.LightningNode
|
||||||
SupportsChargingFees() bool
|
|
||||||
PostgresBackend() *PostgresContainer
|
PostgresBackend() *PostgresContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func testNoBalance(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -31,6 +31,7 @@ func testNoBalance(p *testParams) {
|
|||||||
description: description,
|
description: description,
|
||||||
lsp: p.lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
||||||
@@ -41,7 +42,7 @@ func testNoBalance(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func testProbing(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -33,6 +33,7 @@ func testProbing(p *testParams) {
|
|||||||
description: description,
|
description: description,
|
||||||
lsp: p.lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
||||||
@@ -43,7 +44,7 @@ func testProbing(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func AssertChannelCapacity(
|
|||||||
assert.Equal(t, ((outerAmountMsat/1000)+100000)*1000, capacityMsat)
|
assert.Equal(t, ((outerAmountMsat/1000)+100000)*1000, capacityMsat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateInnerAmountMsat(lsp LspNode, outerAmountMsat uint64) (uint64, uint64) {
|
func calculateInnerAmountMsat(lsp LspNode, outerAmountMsat uint64) uint64 {
|
||||||
fee := outerAmountMsat * 40 / 10_000 / 1_000 * 1_000
|
fee := outerAmountMsat * 40 / 10_000 / 1_000 * 1_000
|
||||||
if fee < 2000000 {
|
if fee < 2000000 {
|
||||||
fee = 2000000
|
fee = 2000000
|
||||||
@@ -34,14 +34,7 @@ func calculateInnerAmountMsat(lsp LspNode, outerAmountMsat uint64) (uint64, uint
|
|||||||
|
|
||||||
inner := outerAmountMsat - fee
|
inner := outerAmountMsat - fee
|
||||||
|
|
||||||
// NOTE: If the LSP does not support charging fees (the CLN version doesn't)
|
return inner
|
||||||
// We have to pretend in the registerpayment call that the LSP WILL charge
|
|
||||||
// fees. If we update the CLN lsp to charge fees, this check can be removed.
|
|
||||||
if lsp.SupportsChargingFees() {
|
|
||||||
return inner, inner
|
|
||||||
} else {
|
|
||||||
return outerAmountMsat, inner
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var publicChanAmount uint64 = 1000183
|
var publicChanAmount uint64 = 1000183
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func testOpenZeroConfUtxo(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -45,6 +45,7 @@ func testOpenZeroConfUtxo(p *testParams) {
|
|||||||
description: description,
|
description: description,
|
||||||
lsp: lsp,
|
lsp: lsp,
|
||||||
})
|
})
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(lsp.LightningNode())
|
||||||
@@ -55,7 +56,7 @@ func testOpenZeroConfUtxo(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func testZeroReserve(p *testParams) {
|
|||||||
|
|
||||||
log.Printf("Adding bob's invoices")
|
log.Printf("Adding bob's invoices")
|
||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(),
|
||||||
generateInvoicesRequest{
|
generateInvoicesRequest{
|
||||||
@@ -32,6 +32,7 @@ func testZeroReserve(p *testParams) {
|
|||||||
description: description,
|
description: description,
|
||||||
lsp: p.lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
p.BreezClient().SetHtlcAcceptor(innerAmountMsat)
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode())
|
||||||
@@ -42,7 +43,7 @@ func testZeroReserve(p *testParams) {
|
|||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: p.BreezClient().Node().NodeId(),
|
Destination: p.BreezClient().Node().NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(lspAmountMsat),
|
OutgoingAmountMsat: int64(innerAmountMsat),
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Fix race waiting for htlc interceptor.
|
// TODO: Fix race waiting for htlc interceptor.
|
||||||
|
|||||||
Reference in New Issue
Block a user