From 8e15390c20ea517e1ac5016b6ab5838fb741ed2a Mon Sep 17 00:00:00 2001 From: Impa10r Date: Mon, 20 May 2024 01:52:42 +0200 Subject: [PATCH 1/5] Publish branch --- CHANGELOG.md | 4 ++++ cmd/psweb/main.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98538c2..9d61451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Versions +## 1.4.5 + +- + ## 1.4.4 - Fix panic in v1.4.3 diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index a244e40..395f1a9 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -33,7 +33,7 @@ import ( const ( // App version tag - version = "v1.4.4" + version = "v1.4.5" // Liquid balance to reserve in auto swaps // Min is 1000, but the swap will spend it all on fee From 2839b24bdebf3306d93543130874afd3ad0a7471 Mon Sep 17 00:00:00 2001 From: Impa10r Date: Mon, 20 May 2024 08:47:55 +0200 Subject: [PATCH 2/5] Cache swap costs --- cmd/psweb/main.go | 31 +++++++++++++++++++++++++++++-- cmd/psweb/templates/peer.gohtml | 8 ++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index 395f1a9..fa7a4a1 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -170,6 +170,9 @@ func main() { // download and subscribe to payments go ln.CachePayments() + // fetch all chain costs + go cacheSwapCosts() + // Handle termination signals signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGPIPE) @@ -709,7 +712,7 @@ func updateHandler(w http.ResponseWriter, r *http.Request) { swapData += ` Amount:` swapData += formatWithThousandSeparators(swap.Amount) - swapData += ` + swapData += ` sats ChannelId:` swapData += swap.ChannelId swapData += `` @@ -2305,7 +2308,7 @@ func convertSwapsToHTMLTable(swaps []*peerswaprpc.PrettyPrintSwap, nodeId string // clicking on swap status will filter swaps with equal status table += "" table += visualiseSwapState(swap.State, false) + " " - table += formatWithThousandSeparators(swap.Amount) + table += " " + formatWithThousandSeparators(swap.Amount) + "" asset := "🌊" if swap.Asset == "btc" { @@ -2323,6 +2326,11 @@ func convertSwapsToHTMLTable(swaps []*peerswaprpc.PrettyPrintSwap, nodeId string table += " âš¡ â‡¨ " + asset } + cost := swapCost(swap) + if cost != 0 { + table += " " + formatSigned(cost) + "" + } + table += "" role := "" @@ -2667,3 +2675,22 @@ func onchainTxFee(asset, txId string) int64 { } return fee } + +func cacheSwapCosts() { + client, cleanup, err := ps.GetClient(config.Config.RpcHost) + if err != nil { + return + } + defer cleanup() + + res, err := ps.ListSwaps(client) + if err != nil { + return + } + + swaps := res.GetSwaps() + + for _, swap := range swaps { + swapCost(swap) + } +} diff --git a/cmd/psweb/templates/peer.gohtml b/cmd/psweb/templates/peer.gohtml index faab52e..ff3b78c 100644 --- a/cmd/psweb/templates/peer.gohtml +++ b/cmd/psweb/templates/peer.gohtml @@ -199,16 +199,16 @@ Sincerely, Sent {{m .Peer.AsSender.SatsIn}} - {{fs .SenderInFee}}{{if .SenderInFee}} ({{fs .SenderInFeePPM}}){{end}} + {{fs .SenderInFee}}{{if .SenderInFee}} ({{fs .SenderInFeePPM}}){{end}} {{m .Peer.AsSender.SatsOut}} - {{fmt .Peer.PaidFee}}{{if .Peer.PaidFee}} ({{fs .SenderOutFeePPM}}){{end}} + {{fmt .Peer.PaidFee}}{{if .Peer.PaidFee}} ({{fs .SenderOutFeePPM}}){{end}} Rcvd {{m .Peer.AsReceiver.SatsOut}} - {{fs .ReceiverOutFee}}{{if .ReceiverOutFee}} ({{fs .ReceiverOutFeePPM}}){{end}} + {{fs .ReceiverOutFee}}{{if .ReceiverOutFee}} ({{fs .ReceiverOutFeePPM}}){{end}} {{m .Peer.AsReceiver.SatsIn}} - {{fs .ReceiverInFee}}{{if .ReceiverInFee}} ({{fs .ReceiverInFeePPM}}){{end}} + {{fs .ReceiverInFee}}{{if .ReceiverInFee}} ({{fs .ReceiverInFeePPM}}){{end}} {{end}} From 75091691e08a66486f4c4f12707e89b7de46dc76 Mon Sep 17 00:00:00 2001 From: Impa10r Date: Mon, 20 May 2024 08:56:46 +0200 Subject: [PATCH 3/5] Add cost PPM --- cmd/psweb/main.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index fa7a4a1..f0617d1 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -742,14 +742,15 @@ func updateHandler(w http.ResponseWriter, r *http.Request) { swapData += strconv.FormatUint(uint64(swap.LndChanId), 10) cost := swapCost(swap) - if cost > 0 { - swapData += `Swap Cost:` - swapData += formatWithThousandSeparators(uint64(cost)) + " sats" - } - if cost < 0 { + if cost != 0 { + ppm := cost * 1_000_000 / int64(swap.Amount) + swapData += `Swap Cost:` - swapData += "Rebate " + formatWithThousandSeparators(uint64(-cost)) + " sats" + swapData += formatSigned(cost) + " sats" + swapData += `Cost PPM:` + swapData += formatSigned(ppm) } + swapData += ` @@ -2328,7 +2329,8 @@ func convertSwapsToHTMLTable(swaps []*peerswaprpc.PrettyPrintSwap, nodeId string cost := swapCost(swap) if cost != 0 { - table += " " + formatSigned(cost) + "" + ppm := cost * 1_000_000 / int64(swap.Amount) + table += " " + formatSigned(cost) + "" } table += "" From 37d5b54b4b24ef4252fb4059b6447ce2d1cc2371 Mon Sep 17 00:00:00 2001 From: Impa10r Date: Mon, 20 May 2024 10:03:18 +0200 Subject: [PATCH 4/5] Fix error reporting --- CHANGELOG.md | 3 ++- cmd/psweb/main.go | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d61451..f526838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 1.4.5 -- +- Add swap costs to home page +- Fix error reporting ## 1.4.4 diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index f0617d1..edc4ab8 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -1435,12 +1435,17 @@ func redirectWithError(w http.ResponseWriter, r *http.Request, redirectUrl strin t := fmt.Sprintln(err) // translate common errors into plain English switch { - case strings.HasPrefix(t, "rpc error"): + case strings.HasPrefix(t, "rpc error: code = Unavailable desc = connection error"): t = "Cannot connect to peerswapd. It either has not started listening yet or PeerSwap Host parameter is wrong. Check logs." case strings.HasPrefix(t, "Unable to dial socket"): t = "Cannot connect to lightningd. It either failed to start or has wrong configuration. Check logs." case strings.HasPrefix(t, "-32601:Unknown command 'peerswap-reloadpolicy'"): t = "Peerswap plugin is not installed or has wrong configuration. Check .lightning/config." + case strings.HasPrefix(t, "rpc error: code = "): + i := strings.Index(t, "desc =") + if i > 0 { + t = t[i+7:] + } } // display the error to the web page header msg := url.QueryEscape(t) From ecc083780f81d7a50c35f183f05a16246644c7ad Mon Sep 17 00:00:00 2001 From: Impa10r Date: Mon, 20 May 2024 10:10:30 +0200 Subject: [PATCH 5/5] Checj active swap on timeout --- cmd/psweb/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index edc4ab8..8a12325 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -1096,7 +1096,8 @@ func submitHandler(w http.ResponseWriter, r *http.Request) { } if err != nil { - if err.Error() == "Request timed out" { + e := err.Error() + if e == "Request timed out" || strings.HasPrefix(e, "rpc error: code = Unavailable desc = rpc timeout reached") { // sometimes the swap is pending anyway res, er := ps.ListActiveSwaps(client) if er != nil {