diff --git a/cln/cln.go b/cln/cln.go index 616e07cc..b62113f3 100755 --- a/cln/cln.go +++ b/cln/cln.go @@ -32,6 +32,8 @@ type Cln struct { CertChain string `long:"cln.certchain" description:"Path to the client cert of the CLN gRPC"` Client protos.NodeClient + + regtest bool } const ( @@ -105,6 +107,7 @@ func (c *Cln) GetInfo() (*lightning.LightningInfo, error) { if err != nil { return nil, err } + c.regtest = info.Network == "regtest" return &lightning.LightningInfo{ Pubkey: hex.EncodeToString(info.Id), BlockHeight: info.Blockheight, @@ -177,6 +180,10 @@ func (c *Cln) CreateInvoice(value int64, preimage []byte, expiry int64, memo str Description: memo, Label: fmt.Sprint(time.Now().UTC().UnixMilli()), } + if c.regtest { + cltv := uint32(20) + request.Cltv = &cltv + } if expiry != 0 { expiryDate := uint64(time.Now().Unix()) + uint64(expiry) request.Expiry = &expiryDate diff --git a/cmd/boltzd/boltzd.go b/cmd/boltzd/boltzd.go index d11cd8bd..c15f7599 100644 --- a/cmd/boltzd/boltzd.go +++ b/cmd/boltzd/boltzd.go @@ -82,8 +82,6 @@ func Init(cfg *config.Config) { logger.Info("Parsed chain: " + network.Name) - cfg.LND.ChainParams = network.Btc - waitForLightningSynced(cfg.Lightning) setBoltzEndpoint(cfg.Boltz, network) diff --git a/cmd/boltzd/boltzd_test.go b/cmd/boltzd/boltzd_test.go index 33d6d894..d508d631 100644 --- a/cmd/boltzd/boltzd_test.go +++ b/cmd/boltzd/boltzd_test.go @@ -359,7 +359,6 @@ func TestSwap(t *testing.T) { info := next(boltzrpc.SwapState_SUCCESSFUL) checkSwap(t, info.Swap) }) - t.Run("Deposit", func(t *testing.T) { swap, err := client.CreateSwap(&boltzrpc.CreateSwapRequest{ Pair: pair, @@ -388,15 +387,6 @@ func TestSwap(t *testing.T) { require.NoError(t, err) amount := submarinePair.Limits.Minimal - t.Run("AddressRequired", func(t *testing.T) { - withoutWallet(t, client, func() { - _, err := client.CreateSwap(&boltzrpc.CreateSwapRequest{ - Pair: pairLiquid, - }) - assert.Error(t, err) - }) - }) - t.Run("Script", func(t *testing.T) { cfg.Boltz.DisablePartialSignatures = true swaps := make([]*boltzrpc.CreateSwapResponse, 3) @@ -480,6 +470,14 @@ func TestSwap(t *testing.T) { require.Equal(t, int(refundFee), int(*info.OnchainFee)) }) + t.Run("AddressRequired", func(t *testing.T) { + withoutWallet(t, client, func() { + _, err := client.CreateSwap(&boltzrpc.CreateSwapRequest{ + Pair: pairLiquid, + }) + assert.Error(t, err) + }) + }) }) }) diff --git a/lnd/lnd.go b/lnd/lnd.go index 0a12867e..8e0402cb 100644 --- a/lnd/lnd.go +++ b/lnd/lnd.go @@ -15,7 +15,6 @@ import ( "github.com/BoltzExchange/boltz-client/lightning" "github.com/BoltzExchange/boltz-client/logger" "github.com/BoltzExchange/boltz-client/onchain" - "github.com/btcsuite/btcd/chaincfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/chainrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" @@ -52,10 +51,8 @@ type LND struct { Certificate string `long:"lnd.certificate" description:"Path to a certificate file of the LND node"` DataDir string `long:"lnd.datadir" description:"Path to the data directory of the LND node"` - ChainParams *chaincfg.Params - - ctx context.Context - + ctx context.Context + regtest bool client lnrpc.LightningClient router routerrpc.RouterClient invoices invoicesrpc.InvoicesClient @@ -125,11 +122,13 @@ func (lnd *LND) GetInfo() (*lightning.LightningInfo, error) { if err != nil { return nil, err } + network := info.Chains[0].Network + lnd.regtest = network == "regtest" return &lightning.LightningInfo{ Pubkey: info.IdentityPubkey, BlockHeight: info.BlockHeight, Version: info.Version, - Network: info.Chains[0].Network, + Network: network, Synced: info.SyncedToChain, }, nil } @@ -205,12 +204,16 @@ func (lnd *LND) ListChannels() ([]*lightning.LightningChannel, error) { } func (lnd *LND) CreateInvoice(value int64, preimage []byte, expiry int64, memo string) (*lightning.AddInvoiceResponse, error) { - invoice, err := lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{ + request := &lnrpc.Invoice{ Memo: memo, Value: value, Expiry: expiry, RPreimage: preimage, - }) + } + if lnd.regtest { + request.CltvExpiry = 20 + } + invoice, err := lnd.client.AddInvoice(lnd.ctx, request) if err != nil { return nil, err } diff --git a/nursery/swap.go b/nursery/swap.go index d9e5ada9..6c4fe746 100644 --- a/nursery/swap.go +++ b/nursery/swap.go @@ -406,7 +406,6 @@ func (nursery *Nursery) handleSwapStatus(swap *database.Swap, status boltz.SwapS return } } - fmt.Println("debug2") logger.Infof("Swap %s failed, trying to refund cooperatively", swap.Id) if err := nursery.refundSwaps([]database.Swap{*swap}, true); err != nil {