mirror of
https://github.com/aljazceru/lspd.git
synced 2026-02-09 16:24:28 +01:00
pass forward_to to htlc accepted response
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/niftynei/glightning/glightning"
|
||||
"golang.org/x/exp/slices"
|
||||
@@ -92,15 +93,15 @@ func (c *ClnClient) OpenChannel(req *OpenChannelRequest) (*wire.OutPoint, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fundingTxId, err := hex.DecodeString(fundResult.FundingTxId)
|
||||
fundingTxId, err := chainhash.NewHashFromStr(fundResult.FundingTxId)
|
||||
if err != nil {
|
||||
log.Printf("CLN: hex.DecodeString(%s) error: %v", fundResult.FundingTxId, err)
|
||||
log.Printf("CLN: chainhash.NewHashFromStr(%s) error: %v", fundResult.FundingTxId, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelPoint, err := NewOutPoint(fundingTxId, uint32(fundResult.FundingTxOutputNum))
|
||||
channelPoint, err := NewOutPoint(fundingTxId[:], uint32(fundResult.FundingTxOutputNum))
|
||||
if err != nil {
|
||||
log.Printf("CLN: NewOutPoint(%x, %d) error: %v", fundingTxId, fundResult.FundingTxOutputNum, err)
|
||||
log.Printf("CLN: NewOutPoint(%s, %d) error: %v", fundingTxId.String(), fundResult.FundingTxOutputNum, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -110,12 +111,12 @@ func (c *ClnClient) OpenChannel(req *OpenChannelRequest) (*wire.OutPoint, error)
|
||||
func (c *ClnClient) GetChannel(peerID []byte, channelPoint wire.OutPoint) (*GetChannelResult, error) {
|
||||
pubkey := hex.EncodeToString(peerID)
|
||||
peer, err := c.client.GetPeer(pubkey)
|
||||
fundingTxID := hex.EncodeToString(channelPoint.Hash[:])
|
||||
if err != nil {
|
||||
log.Printf("CLN: client.GetPeer(%s) error: %v", pubkey, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fundingTxID := channelPoint.Hash.String()
|
||||
for _, c := range peer.Channels {
|
||||
log.Printf("getChannel destination: %s, Short channel id: %v, local alias: %v , FundingTxID:%v, State:%v ", pubkey, c.ShortChannelId, c.Alias.Local, c.FundingTxId, c.State)
|
||||
if slices.Contains(OPEN_STATUSES, c.State) && c.FundingTxId == fundingTxID {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
"github.com/niftynei/glightning/glightning"
|
||||
@@ -120,8 +121,9 @@ func (i *ClnHtlcInterceptor) resumeWithOnion(event *glightning.HtlcAcceptedEvent
|
||||
return event.Fail(uint16(FAILURE_TEMPORARY_CHANNEL_FAILURE))
|
||||
}
|
||||
|
||||
chanId := lnwire.NewChanIDFromOutPoint(interceptResult.channelPoint)
|
||||
log.Printf("forwarding htlc to the destination node and a new private channel was opened")
|
||||
return event.ContinueWithPayload(newPayload)
|
||||
return event.ContinueWith(chanId.String(), newPayload)
|
||||
}
|
||||
|
||||
func encodePayloadWithNextHop(payloadHex string, channelId uint64) (string, error) {
|
||||
|
||||
2
db.go
2
db.go
@@ -62,7 +62,7 @@ func setFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error {
|
||||
SET funding_tx_id = $2, funding_tx_outnum = $3
|
||||
WHERE payment_hash=$1`,
|
||||
paymentHash, channelPoint.Hash[:], channelPoint.Index)
|
||||
log.Printf("setFundingTx(%x, %x, %v): %s err: %v", paymentHash, channelPoint.Hash[:], channelPoint.Index, commandTag, err)
|
||||
log.Printf("setFundingTx(%x, %s, %d): %s err: %v", paymentHash, channelPoint.Hash.String(), channelPoint.Index, commandTag, err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
4
go.mod
4
go.mod
@@ -4,7 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go v1.30.20
|
||||
github.com/breez/lntest v0.0.6
|
||||
github.com/breez/lntest v0.0.7
|
||||
github.com/btcsuite/btcd v0.23.1
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.1
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
|
||||
@@ -176,4 +176,4 @@ require (
|
||||
|
||||
replace github.com/lightningnetwork/lnd v0.15.1-beta => github.com/breez/lnd v0.15.0-beta.rc6.0.20220831104847-00b86a81e57a
|
||||
|
||||
replace github.com/niftynei/glightning v0.8.2 => github.com/breez/glightning v0.0.0-20221201092709-02feadd1d0ad
|
||||
replace github.com/niftynei/glightning v0.8.2 => github.com/breez/glightning v0.0.0-20221207122347-03c2d8cb69dd
|
||||
@@ -2,25 +2,24 @@ package itest
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lntest"
|
||||
lspd "github.com/breez/lspd/rpc"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func testOpenZeroConfChannelOnReceive(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner, timeout time.Time) {
|
||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice", timeout)
|
||||
bob := NewZeroConfNode(h, miner, "Bob", timeout)
|
||||
func testOpenZeroConfChannelOnReceive(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner) {
|
||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice")
|
||||
bob := NewZeroConfNode(h, miner, "Bob")
|
||||
|
||||
alice.Fund(10000000, timeout)
|
||||
lsp.LightningNode().Fund(10000000, timeout)
|
||||
alice.Fund(10000000)
|
||||
lsp.LightningNode().Fund(10000000)
|
||||
|
||||
log.Print("Opening channel between Alice and the lsp")
|
||||
channel := alice.OpenChannel(lsp.LightningNode(), &lntest.OpenChannelOptions{
|
||||
AmountSat: 1000000,
|
||||
})
|
||||
alice.WaitForChannelReady(channel, timeout)
|
||||
alice.WaitForChannelReady(channel)
|
||||
|
||||
log.Printf("Adding bob's invoices")
|
||||
outerAmountMsat := uint64(2100000)
|
||||
@@ -48,25 +47,25 @@ func testOpenZeroConfChannelOnReceive(h *lntest.TestHarness, lsp LspNode, miner
|
||||
})
|
||||
|
||||
log.Printf("Alice paying")
|
||||
payResp := alice.Pay(outerInvoice.bolt11, timeout)
|
||||
payResp := alice.Pay(outerInvoice.bolt11)
|
||||
bobInvoice := bob.lightningNode.GetInvoice(payResp.PaymentHash)
|
||||
|
||||
assert.DeepEqual(h.T, payResp.PaymentPreimage, bobInvoice.PaymentPreimage)
|
||||
assert.Equal(h.T, outerAmountMsat, bobInvoice.AmountReceivedMsat)
|
||||
}
|
||||
|
||||
func testOpenZeroConfSingleHtlc(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner, timeout time.Time) {
|
||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice", timeout)
|
||||
bob := NewZeroConfNode(h, miner, "Bob", timeout)
|
||||
func testOpenZeroConfSingleHtlc(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner) {
|
||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice")
|
||||
bob := NewZeroConfNode(h, miner, "Bob")
|
||||
|
||||
alice.Fund(10000000, timeout)
|
||||
lsp.LightningNode().Fund(10000000, timeout)
|
||||
alice.Fund(10000000)
|
||||
lsp.LightningNode().Fund(10000000)
|
||||
|
||||
log.Print("Opening channel between Alice and the lsp")
|
||||
channel := alice.OpenChannel(lsp.LightningNode(), &lntest.OpenChannelOptions{
|
||||
AmountSat: 1000000,
|
||||
})
|
||||
channelId := alice.WaitForChannelReady(channel, timeout)
|
||||
channelId := alice.WaitForChannelReady(channel)
|
||||
|
||||
log.Printf("Adding bob's invoices")
|
||||
outerAmountMsat := uint64(2100000)
|
||||
@@ -95,7 +94,7 @@ func testOpenZeroConfSingleHtlc(h *lntest.TestHarness, lsp LspNode, miner *lntes
|
||||
|
||||
log.Printf("Alice paying")
|
||||
route := constructRoute(lsp.LightningNode(), bob.lightningNode, channelId, lntest.NewShortChanIDFromString("1x0x0"), outerAmountMsat)
|
||||
payResp := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route, timeout)
|
||||
payResp := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route)
|
||||
bobInvoice := bob.lightningNode.GetInvoice(payResp.PaymentHash)
|
||||
|
||||
assert.DeepEqual(h.T, payResp.PaymentPreimage, bobInvoice.PaymentPreimage)
|
||||
|
||||
@@ -2,7 +2,7 @@ package itest
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
context "context"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lntest"
|
||||
"github.com/breez/lspd/btceclegacy"
|
||||
@@ -18,7 +17,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/golang/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
@@ -135,7 +134,7 @@ func (l *LndLspNode) LightningNode() lntest.LightningNode {
|
||||
return l.lightningNode
|
||||
}
|
||||
|
||||
func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeout time.Time) LspNode {
|
||||
func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode {
|
||||
scriptFilePath, grpcAddress, publ, postgresBackend := setupLspd(h, name, "RUN_CLN=true")
|
||||
args := []string{
|
||||
fmt.Sprintf("--plugin=%s", scriptFilePath),
|
||||
@@ -144,7 +143,7 @@ func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeout
|
||||
fmt.Sprintf("--cltv-delta=%d", lspCltvDelta),
|
||||
}
|
||||
|
||||
lightningNode := lntest.NewCoreLightningNode(h, m, name, timeout, args...)
|
||||
lightningNode := lntest.NewCoreLightningNode(h, m, name, args...)
|
||||
|
||||
conn, err := grpc.Dial(
|
||||
grpcAddress,
|
||||
@@ -168,7 +167,7 @@ func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeout
|
||||
return lspNode
|
||||
}
|
||||
|
||||
func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeout time.Time) LspNode {
|
||||
func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode {
|
||||
args := []string{
|
||||
"--protocol.zero-conf",
|
||||
"--protocol.option-scid-alias",
|
||||
@@ -180,7 +179,7 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeout
|
||||
fmt.Sprintf("--bitcoin.timelockdelta=%d", lspCltvDelta),
|
||||
}
|
||||
|
||||
lightningNode := lntest.NewLndNode(h, m, name, timeout, args...)
|
||||
lightningNode := lntest.NewLndNode(h, m, name, args...)
|
||||
tlsCert := strings.Replace(string(lightningNode.TlsCert()), "\n", "\\n", -1)
|
||||
scriptFilePath, grpcAddress, publ, postgresBackend := setupLspd(h, name,
|
||||
"RUN_LND=true",
|
||||
|
||||
@@ -13,16 +13,16 @@ var defaultTimeout time.Duration = time.Second * 120
|
||||
|
||||
func TestLspd(t *testing.T) {
|
||||
testCases := allTestCases
|
||||
// runTests(t, testCases, "LND-lspd", func(h *lntest.TestHarness, m *lntest.Miner, t time.Time) LspNode {
|
||||
// return NewLndLspdNode(h, m, "lsp", t)
|
||||
// runTests(t, testCases, "LND-lspd", func(h *lntest.TestHarness, m *lntest.Miner) LspNode {
|
||||
// return NewLndLspdNode(h, m, "lsp")
|
||||
// })
|
||||
|
||||
runTests(t, testCases, "CLN-lspd", func(h *lntest.TestHarness, m *lntest.Miner, t time.Time) LspNode {
|
||||
return NewClnLspdNode(h, m, "lsp", t)
|
||||
runTests(t, testCases, "CLN-lspd", func(h *lntest.TestHarness, m *lntest.Miner) LspNode {
|
||||
return NewClnLspdNode(h, m, "lsp")
|
||||
})
|
||||
}
|
||||
|
||||
func runTests(t *testing.T, testCases []*testCase, prefix string, lspFunc func(h *lntest.TestHarness, m *lntest.Miner, t time.Time) LspNode) {
|
||||
func runTests(t *testing.T, testCases []*testCase, prefix string, lspFunc func(h *lntest.TestHarness, m *lntest.Miner) LspNode) {
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(fmt.Sprintf("%s: %s", prefix, testCase.name), func(t *testing.T) {
|
||||
@@ -31,30 +31,31 @@ func runTests(t *testing.T, testCases []*testCase, prefix string, lspFunc func(h
|
||||
}
|
||||
}
|
||||
|
||||
func runTest(t *testing.T, testCase *testCase, prefix string, lspFunc func(h *lntest.TestHarness, m *lntest.Miner, t time.Time) LspNode) {
|
||||
func runTest(t *testing.T, testCase *testCase, prefix string, lspFunc func(h *lntest.TestHarness, m *lntest.Miner) LspNode) {
|
||||
log.Printf("%s: Running test case '%s'", prefix, testCase.name)
|
||||
harness := lntest.NewTestHarness(t)
|
||||
defer harness.TearDown()
|
||||
|
||||
var dd time.Duration
|
||||
to := testCase.timeout
|
||||
if to == dd {
|
||||
to = defaultTimeout
|
||||
}
|
||||
|
||||
timeout := time.Now().Add(to)
|
||||
log.Printf("Using timeout %v", timeout.String())
|
||||
deadline := time.Now().Add(to)
|
||||
log.Printf("Using deadline %v", deadline.String())
|
||||
|
||||
harness := lntest.NewTestHarness(t, deadline)
|
||||
defer harness.TearDown()
|
||||
|
||||
log.Printf("Creating miner")
|
||||
miner := lntest.NewMiner(harness)
|
||||
log.Printf("Creating lsp")
|
||||
lsp := lspFunc(harness, miner, timeout)
|
||||
lsp := lspFunc(harness, miner)
|
||||
log.Printf("Run testcase")
|
||||
testCase.test(harness, lsp, miner, timeout)
|
||||
testCase.test(harness, lsp, miner)
|
||||
}
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
test func(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner, timeout time.Time)
|
||||
test func(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner)
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lntest"
|
||||
btcec "github.com/btcsuite/btcd/btcec/v2"
|
||||
@@ -51,7 +50,7 @@ pip install pyln-client > /dev/null 2>&1
|
||||
python %s
|
||||
`
|
||||
|
||||
func NewZeroConfNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeout time.Time) *ZeroConfNode {
|
||||
func NewZeroConfNode(h *lntest.TestHarness, m *lntest.Miner, name string) *ZeroConfNode {
|
||||
privKey, err := btcec.NewPrivateKey()
|
||||
lntest.CheckError(h.T, err)
|
||||
|
||||
@@ -89,7 +88,6 @@ func NewZeroConfNode(h *lntest.TestHarness, m *lntest.Miner, name string, timeou
|
||||
h,
|
||||
m,
|
||||
name,
|
||||
timeout,
|
||||
fmt.Sprintf("--dev-force-privkey=%x", s),
|
||||
fmt.Sprintf("--plugin=%s", pluginFilePath),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user