diff --git a/CHANGELOG.md b/CHANGELOG.md index 41a1f24..f779774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Versions +## 1.7.6 + +- Fix BTC to sats rounding bug preventing claim init or join +- Fix external funding peg-in num of confirmations not registered +- Fix ClaimJoin OP_RETURN string +- Add timout dialing lnd +- Wait for lightning to sync before subscribing + ## 1.7.5 - CLN: allow -developer flag diff --git a/cmd/psweb/bitcoin/bitcoin.go b/cmd/psweb/bitcoin/bitcoin.go index 938b3f3..27da7ff 100644 --- a/cmd/psweb/bitcoin/bitcoin.go +++ b/cmd/psweb/bitcoin/bitcoin.go @@ -351,7 +351,7 @@ func FindVout(hexTx string, amount uint64) (uint, error) { } for i, o := range tx.Vout { - if uint64(o.Value*100_000_000) == amount { + if uint64(math.Round(o.Value*100_000_000)) == amount { return uint(i), nil } } diff --git a/cmd/psweb/handlers.go b/cmd/psweb/handlers.go index a6f1b57..7a5053e 100644 --- a/cmd/psweb/handlers.go +++ b/cmd/psweb/handlers.go @@ -725,23 +725,26 @@ func bitcoinHandler(w http.ResponseWriter, r *http.Request) { var utxos []ln.UTXO ln.ListUnspent(cl, &utxos, int32(1)) - if config.Config.PeginTxId != "" && config.Config.PeginTxId != "external" { - // update ClaimJoin status - checkPegin() - - confs, canCPFP = peginConfirmations(config.Config.PeginTxId) - if confs == 0 && config.Config.PeginFeeRate > 0 { - canBump = true - if !ln.CanRBF() { - // can bump only if there is a change output - canBump = canCPFP - if fee > 0 { - // for CPFP the fee must be 1.5x the market - fee = fee + fee/2 + isExternal := config.Config.PeginTxId == "external" + + if config.Config.PeginTxId != "" { + if !isExternal { + confs, canCPFP = peginConfirmations(config.Config.PeginTxId) + // update ClaimJoin status + checkPegin() + if confs == 0 && config.Config.PeginFeeRate > 0 { + canBump = true + if !ln.CanRBF() { + // can bump only if there is a change output + canBump = canCPFP + if fee > 0 { + // for CPFP the fee must be 1.5x the market + fee = fee + fee/2 + } + } + if fee < config.Config.PeginFeeRate+1 { + fee = config.Config.PeginFeeRate + 1 // min increment } - } - if fee < config.Config.PeginFeeRate+1 { - fee = config.Config.PeginFeeRate + 1 // min increment } } } @@ -775,7 +778,7 @@ func bitcoinHandler(w http.ResponseWriter, r *http.Request) { Outputs: &utxos, PeginTxId: config.Config.PeginTxId, IsPegin: config.Config.PeginClaimScript != "", - IsExternal: config.Config.PeginTxId == "external", + IsExternal: isExternal, PeginAddress: config.Config.PeginAddress, PeginAmount: uint64(config.Config.PeginAmount), BitcoinApi: config.Config.BitcoinApi, @@ -807,28 +810,16 @@ func bitcoinHandler(w http.ResponseWriter, r *http.Request) { // returns number of confirmations and whether the tx can be fee bumped func peginConfirmations(txid string) (int32, bool) { - cl, clean, er := ln.GetClient() - if er != nil { - return -1, false - } - - defer clean() - - // -1 indicates error - confs, canCPFP := ln.GetTxConfirmations(cl, txid) - - if confs >= 0 { - return confs, canCPFP - } // can be external funding var tx bitcoin.Transaction _, err := bitcoin.GetRawTransaction(txid, &tx) - if err != nil { - return -1, false + if err == nil { + return tx.Confirmations, len(tx.Vout) > 1 } - return tx.Confirmations, false + // -1 indicates error + return -1, false } // handles Liquid peg-in and Bitcoin send form diff --git a/cmd/psweb/ln/claimjoin.go b/cmd/psweb/ln/claimjoin.go index a0805e7..345829a 100644 --- a/cmd/psweb/ln/claimjoin.go +++ b/cmd/psweb/ln/claimjoin.go @@ -1017,7 +1017,6 @@ func JoinClaimJoin(claimBlockHeight uint32) bool { if myPrivateKey != nil { // persist to db savePrivateKey() - } else { return false } @@ -1026,7 +1025,12 @@ func JoinClaimJoin(claimBlockHeight uint32) bool { if len(ClaimParties) != 1 || ClaimParties[0].PubKey != MyPublicKey() { // initiate array of claim parties for single entry ClaimParties = nil - ClaimParties = append(ClaimParties, *createClaimParty(claimBlockHeight)) + cp := createClaimParty(claimBlockHeight) + if cp == nil { + // something went wrong + return false + } + ClaimParties = append(ClaimParties, *cp) ClaimBlockHeight = claimBlockHeight db.Save("ClaimJoin", "ClaimBlockHeight", ClaimBlockHeight) db.Save("ClaimJoin", "ClaimParties", ClaimParties) @@ -1330,7 +1334,7 @@ func createClaimPSET(totalFee int) (string, error) { if len(ClaimParties) > 1 { // add op_return outputs = append(outputs, map[string]interface{}{ - "data": "6a0f506565725377617020576562205549", + "data": "506565725377617020576562205549", }) } diff --git a/cmd/psweb/ln/cln.go b/cmd/psweb/ln/cln.go index 630b6f8..b67d86e 100644 --- a/cmd/psweb/ln/cln.go +++ b/cmd/psweb/ln/cln.go @@ -181,18 +181,6 @@ func GetBlockHeight() uint32 { return uint32(res.Blockheight) } -// returns number of confirmations and whether the tx can be fee bumped -func GetTxConfirmations(client *glightning.Lightning, txid string) (int32, bool) { - - var tx bitcoin.Transaction - _, err := bitcoin.GetRawTransaction(txid, &tx) - if err != nil { - return -1, false // signal tx not found - } - - return tx.Confirmations, true -} - func GetAlias(nodeKey string) string { // not implemented, use mempool return "" @@ -1064,6 +1052,11 @@ func DownloadAll() bool { if err != nil { return false // lightning not ready yet } + + if resp.WarningLightningSync == "Still loading latest blocks from bitcoind." { + return false // lightning not ready yet + } + MyNodeId = resp.Id MyNodeAlias = resp.Alias diff --git a/cmd/psweb/ln/common.go b/cmd/psweb/ln/common.go index 2f5fe23..897b172 100644 --- a/cmd/psweb/ln/common.go +++ b/cmd/psweb/ln/common.go @@ -567,7 +567,7 @@ func saveSwapRabate(swapId string, rebate int64) { func lastFeeIsTheSame(channelId uint64, newFee int, isInbound bool) bool { lastFee := LastAutoFeeLog(channelId, isInbound) if lastFee != nil { - if newFee == lastFee.NewRate { + if newFee == lastFee.NewRate && time.Now().Unix()-lastFee.TimeStamp < 86_400 { // only care about the last 24h return true } } diff --git a/cmd/psweb/ln/lnd.go b/cmd/psweb/ln/lnd.go index 0442458..00f0e6d 100644 --- a/cmd/psweb/ln/lnd.go +++ b/cmd/psweb/ln/lnd.go @@ -133,9 +133,11 @@ func lndConnection() (*grpc.ClientConn, error) { grpc.WithPerRPCCredentials(macCred), } - conn, err := grpc.Dial(host, opts...) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + conn, err := grpc.DialContext(ctx, host, opts...) if err != nil { - fmt.Println("lndConnection dial:", err) return nil, err } @@ -213,15 +215,6 @@ func getTransaction(client lnrpc.LightningClient, txid string) (*lnrpc.Transacti return nil, errors.New("txid not found") } -// returns number of confirmations and whether the tx can be fee bumped -func GetTxConfirmations(client lnrpc.LightningClient, txid string) (int32, bool) { - tx, err := getTransaction(client, txid) - if err == nil { - return tx.NumConfirmations, len(tx.OutputDetails) > 1 - } - return -1, false // signal tx not found in local mempool -} - func GetAlias(nodeKey string) string { client, cleanup, err := GetClient() if err != nil { @@ -1194,11 +1187,15 @@ func DownloadAll() bool { ctx := context.Background() if MyNodeId == "" { - res, err := client.GetInfo(context.Background(), &lnrpc.GetInfoRequest{}) + res, err := client.GetInfo(ctx, &lnrpc.GetInfoRequest{}) if err != nil { // lnd not ready return false } + if !res.SyncedToChain || !res.SyncedToGraph { + // lnd not ready + return false + } MyNodeAlias = res.GetAlias() MyNodeId = res.GetIdentityPubkey() } diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index 6a0dae7..f5e208c 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -34,7 +34,7 @@ import ( const ( // App VERSION tag - VERSION = "v1.7.5" + VERSION = "v1.7.6" // Swap Out reserve SWAP_OUT_CHANNEL_RESERVE = 10000 // Elements v23.02.03 introduced vsize discount enabled on testnet as default @@ -281,7 +281,7 @@ func startTimer() { onTimer() // then every minute - for range time.Tick(60 * time.Second) { + for range time.Tick(time.Minute) { onTimer() } } @@ -457,7 +457,7 @@ func setLogging(logFileName string) (func(), error) { } // add new line after start up - log.Println("------------------START-----------------") + log.Printf("------------------START %s-----------------", VERSION) return cleanup, nil } diff --git a/cmd/psweb/templates/reusable.gohtml b/cmd/psweb/templates/reusable.gohtml index 649d057..ad03b0f 100644 --- a/cmd/psweb/templates/reusable.gohtml +++ b/cmd/psweb/templates/reusable.gohtml @@ -41,7 +41,7 @@ Logout {{end}} - Swap Market ☍ + Swap Market ↗︎ diff --git a/cmd/psweb/utils.go b/cmd/psweb/utils.go index b778b9f..898ad46 100644 --- a/cmd/psweb/utils.go +++ b/cmd/psweb/utils.go @@ -149,7 +149,7 @@ func simplifySwapState(state string) string { } func toSats(amount float64) uint64 { - return uint64(math.Round(float64(100_000_000) * amount)) + return uint64(math.Round(amount * 100_000_000)) } func toUint(num int64) uint64 {