Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:

# If you change this value, please change it in the following files as well:
# /Dockerfile
GO_VERSION: 1.17
GO_VERSION: 1.19.2

jobs:
########################
Expand Down Expand Up @@ -123,4 +123,4 @@ jobs:
go-version: '~${{ env.GO_VERSION }}'

- name: run unit tests
run: make unit
run: make unit
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ git:
depth: false

go:
- "1.17.x"
- "1.19.2"

env:
global:
Expand Down
2 changes: 2 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -285,6 +286,7 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,

case swap.HtlcV3:
htlc, err = swap.NewHtlcV3(
input.MuSig2Version040,
pendingSwap.Contract.CltvExpiry, senderKey,
receiverKey, senderKey, receiverKey, hash,
&chaincfg.TestNet3Params,
Expand Down
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/lightninglabs/loop

require (
github.com/btcsuite/btcd v0.23.3
github.com/btcsuite/btcd/btcec/v2 v2.2.1
github.com/btcsuite/btcd/btcutil v1.1.2
github.com/btcsuite/btcd v0.23.5-0.20230125025938-be056b0a0b2f
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/btcsuite/btcd/btcutil/psbt v1.1.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet v0.16.6-0.20221208210930-6f3f55efb230
github.com/btcsuite/btcwallet/wtxmgr v1.5.0
github.com/coreos/bbolt v1.3.3
github.com/davecgh/go-spew v1.1.1
Expand All @@ -15,19 +16,19 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/aperture v0.1.18-beta
github.com/lightninglabs/lndclient v0.15.1-5
github.com/lightninglabs/lndclient v0.16.0-8
github.com/lightninglabs/loop/swapserverrpc v1.0.1
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display
github.com/lightningnetwork/lnd v0.15.4-beta
github.com/lightningnetwork/lnd/cert v1.1.1
github.com/lightningnetwork/lnd v0.15.0-beta.rc6.0.20230206122140-0cf0a7dd3b08
github.com/lightningnetwork/lnd/cert v1.2.0
github.com/lightningnetwork/lnd/clock v1.1.0
github.com/lightningnetwork/lnd/queue v1.1.0
github.com/lightningnetwork/lnd/ticker v1.1.0
github.com/lightningnetwork/lnd/tor v1.0.1
github.com/stretchr/testify v1.7.1
github.com/lightningnetwork/lnd/tor v1.1.0
github.com/stretchr/testify v1.8.0
github.com/urfave/cli v1.22.9
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
google.golang.org/grpc v1.39.0
golang.org/x/net v0.4.0
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1
gopkg.in/macaroon-bakery.v2 v2.0.1
gopkg.in/macaroon.v2 v2.1.0
Expand Down
221 changes: 166 additions & 55 deletions go.sum

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion loopd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func loadCertWithCreate(cfg *Config) (tls.Certificate, *x509.Certificate,
!lnrpc.FileExists(cfg.TLSKeyPath) {

log.Infof("Generating TLS certificates...")
err := cert.GenCertPair(
certBytes, keyBytes, err := cert.GenCertPair(
defaultSelfSignedOrganization, cfg.TLSCertPath,
cfg.TLSKeyPath, cfg.TLSExtraIPs,
cfg.TLSExtraDomains, cfg.TLSDisableAutofill,
Expand All @@ -390,6 +390,14 @@ func loadCertWithCreate(cfg *Config) (tls.Certificate, *x509.Certificate,
if err != nil {
return tls.Certificate{}, nil, err
}

err = cert.WriteCertPair(
cfg.TLSCertPath, cfg.TLSKeyPath, certBytes, keyBytes,
)
if err != nil {
return tls.Certificate{}, nil, err
}

log.Infof("Done generating TLS certificates")
}

Expand Down
23 changes: 20 additions & 3 deletions loopd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,26 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
perms.RequiredPermissions[endpoint] = perm
}

rks, db, err := lndclient.NewBoltMacaroonStore(
d.cfg.DataDir, "macarooons.db", loopdb.DefaultLoopDBTimeout,
)
if err != nil {
return err
}

cleanupMacaroonStore := func() {
err := db.Close()
if err != nil {
log.Errorf("Error closing macaroon store: %v", err)
}
}

if withMacaroonService {
// Start the macaroon service and let it create its default
// macaroon in case it doesn't exist yet.
d.macaroonService, err = lndclient.NewMacaroonService(
&lndclient.MacaroonServiceConfig{
DBPath: d.cfg.DataDir,
DBFileName: "macaroons.db",
DBTimeout: loopdb.DefaultLoopDBTimeout,
RootKeyStore: rks,
MacaroonLocation: loopMacaroonLocation,
MacaroonPath: d.cfg.MacaroonPath,
Checkers: []macaroons.Checker{
Expand All @@ -410,13 +422,15 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
},
)
if err != nil {
cleanupMacaroonStore()
return err
}

if err = d.macaroonService.Start(); err != nil {
// The client is the only thing we started yet, so if we
// clean up its connection now, nothing else needs to be
// shut down at this point.
cleanupMacaroonStore()
clientCleanup()
return err
}
Expand All @@ -438,6 +452,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
swapsList, err := d.impl.FetchSwaps()
if err != nil {
if d.macaroonService == nil {
cleanupMacaroonStore()
clientCleanup()
return err
}
Expand All @@ -449,6 +464,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
log.Errorf("Error shutting down macaroon service: %v",
err)
}
cleanupMacaroonStore()
clientCleanup()
return err
}
Expand Down Expand Up @@ -520,6 +536,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
// We need to shutdown before sending the error on the channel,
// otherwise a caller might exit the process too early.
d.stop()
cleanupMacaroonStore()
log.Info("Daemon exited")

// The caller expects exactly one message. So we send the error
Expand Down
2 changes: 1 addition & 1 deletion loopd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
LoopMinRequiredLndVersion = &verrpc.Version{
AppMajor: 0,
AppMinor: 15,
AppPatch: 4,
AppPatch: 99,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be changed to 0.16 right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once out but for now we need this to make sure that if someone runs HEAD of loop will also run with HEAD of LND.

BuildTags: []string{
"signrpc", "walletrpc", "chainrpc", "invoicesrpc",
},
Expand Down
14 changes: 7 additions & 7 deletions loopin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
invpkg "github.com/lightningnetwork/lnd/invoices"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there a conflict with invoices?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a convention that we seemed to have picked up in the LND codebase so I was just meant to conform to that.

"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntypes"
Expand Down Expand Up @@ -304,7 +304,7 @@ func awaitProbe(ctx context.Context, lnd lndclient.LndServices,
select {
case update := <-updateChan:
switch update.State {
case channeldb.ContractAccepted:
case invpkg.ContractAccepted:
log.Infof("Server probe successful")
probeResult <- nil

Expand All @@ -321,13 +321,13 @@ func awaitProbe(ctx context.Context, lnd lndclient.LndServices,

return

case channeldb.ContractCanceled:
case invpkg.ContractCanceled:
probeResult <- errors.New(
"probe invoice expired")

return

case channeldb.ContractSettled:
case invpkg.ContractSettled:
probeResult <- errors.New(
"impossible that probe " +
"invoice was settled")
Expand Down Expand Up @@ -870,7 +870,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,

switch update.State {
// Swap invoice was paid, so update server cost balance.
case channeldb.ContractSettled:
case invpkg.ContractSettled:
s.cost.Server -= update.AmtPaid

// If invoice settlement and htlc spend happen
Expand All @@ -891,7 +891,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,

// Canceled invoice has no effect on server cost
// balance.
case channeldb.ContractCanceled:
case invpkg.ContractCanceled:
invoiceFinalized = true
}

Expand Down Expand Up @@ -929,7 +929,7 @@ func (s *loopInSwap) processHtlcSpend(ctx context.Context,
// already settled. This means that the server didn't succeed in
// sweeping the htlc after paying the invoice.
err := s.lnd.Invoices.CancelInvoice(ctx, s.hash)
if err != nil && err != channeldb.ErrInvoiceAlreadySettled {
if err != nil && err != invpkg.ErrInvoiceAlreadySettled {
return err
}
}
Expand Down
10 changes: 6 additions & 4 deletions loopin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input"
invpkg "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -116,7 +117,7 @@ func testLoopInSuccess(t *testing.T) {

// Server has already paid invoice before spending the htlc. Signal
// settled.
ctx.updateInvoiceState(49000, channeldb.ContractSettled)
ctx.updateInvoiceState(49000, invpkg.ContractSettled)

// Swap is expected to move to the state InvoiceSettled
ctx.assertState(loopdb.StateInvoiceSettled)
Expand Down Expand Up @@ -327,7 +328,7 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
<-ctx.lnd.FailInvoiceChannel

// Signal that the invoice was canceled.
ctx.updateInvoiceState(0, channeldb.ContractCanceled)
ctx.updateInvoiceState(0, invpkg.ContractCanceled)

ctx.assertState(loopdb.StateFailTimeout)
state := ctx.store.assertLoopInState(loopdb.StateFailTimeout)
Expand Down Expand Up @@ -459,6 +460,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,

case swap.HtlcV3:
htlc, err = swap.NewHtlcV3(
input.MuSig2Version040,
contract.CltvExpiry, contract.SenderKey,
contract.ReceiverKey, contract.SenderKey,
contract.ReceiverKey, testPreimage.Hash(),
Expand Down Expand Up @@ -559,7 +561,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
// Server has already paid invoice before spending the htlc. Signal
// settled.
amtPaid := btcutil.Amount(49000)
ctx.updateInvoiceState(amtPaid, channeldb.ContractSettled)
ctx.updateInvoiceState(amtPaid, invpkg.ContractSettled)

// Swap is expected to move to the state InvoiceSettled
ctx.assertState(loopdb.StateInvoiceSettled)
Expand Down
8 changes: 4 additions & 4 deletions loopin_testcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/sweep"
"github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/channeldb"
invpkg "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -75,7 +75,7 @@ func (c *loopInTestContext) assertSubscribeInvoice(hash lntypes.Hash) {

// updateInvoiceState mocks an update to our swap invoice state.
func (c *loopInTestContext) updateInvoiceState(amount btcutil.Amount,
state channeldb.ContractState) {
state invpkg.ContractState) {

c.swapInvoiceSubscription.Update <- lndclient.InvoiceUpdate{
AmtPaid: amount,
Expand All @@ -84,8 +84,8 @@ func (c *loopInTestContext) updateInvoiceState(amount btcutil.Amount,

// If we're in a final state, close our update channels as lndclient
// would.
if state == channeldb.ContractCanceled ||
state == channeldb.ContractSettled {
if state == invpkg.ContractCanceled ||
state == invpkg.ContractSettled {

close(c.swapInvoiceSubscription.Update)
close(c.swapInvoiceSubscription.Err)
Expand Down
11 changes: 5 additions & 6 deletions loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,9 +1351,9 @@ func (s *loopOutSwap) createMuSig2SweepTxn(
return nil, err
}

var schnorrSenderKey, schnorrReceiverKey [32]byte
copy(schnorrSenderKey[:], s.SenderKey[1:])
copy(schnorrReceiverKey[:], s.ReceiverKey[1:])
signers := [][]byte{
s.SenderKey[1:], s.ReceiverKey[1:],
}

htlc, ok := s.htlc.HtlcScript.(*swap.HtlcScriptV3)
if !ok {
Expand All @@ -1363,9 +1363,8 @@ func (s *loopOutSwap) createMuSig2SweepTxn(
// Now we're creating a local MuSig2 session using the receiver key's
// key locator and the htlc's root hash.
musig2SessionInfo, err := s.lnd.Signer.MuSig2CreateSession(
ctx, &s.ClientKeyLocator,
[][32]byte{schnorrSenderKey, schnorrReceiverKey},
lndclient.MuSig2TaprootTweakOpt(htlc.RootHash[:], false),
ctx, input.MuSig2Version040, &s.ClientKeyLocator,
signers, lndclient.MuSig2TaprootTweakOpt(htlc.RootHash[:], false),
)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions server_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/test"
"github.com/lightningnetwork/lnd/channeldb"
invpkg "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *serverMock) NewLoopInSwap(_ context.Context, swapHash lntypes.Hash,
// cancel the probe payment.
probeSub := <-s.lnd.SingleInvoiceSubcribeChannel
probeSub.Update <- lndclient.InvoiceUpdate{
State: channeldb.ContractAccepted,
State: invpkg.ContractAccepted,
}
<-s.lnd.FailInvoiceChannel

Expand Down
2 changes: 2 additions & 0 deletions swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntypes"
)

Expand Down Expand Up @@ -82,6 +83,7 @@ func GetHtlc(hash lntypes.Hash, contract *loopdb.SwapContract,

case swap.HtlcV3:
return swap.NewHtlcV3(
input.MuSig2Version040,
contract.CltvExpiry, contract.SenderKey,
contract.ReceiverKey, contract.SenderKey,
contract.ReceiverKey, hash,
Expand Down
Loading