Skip to content

Commit

Permalink
test: lower cltv expiry in regtest for lower swap timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 committed Feb 9, 2024
1 parent fa47db0 commit 6dbf475
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
7 changes: 7 additions & 0 deletions cln/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/boltzd/boltzd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions cmd/boltzd/boltzd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
})
})

})
Expand Down
19 changes: 11 additions & 8 deletions lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion nursery/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6dbf475

Please sign in to comment.