Skip to content

Commit

Permalink
Merge pull request #61 from Impa10r/v1.5.4
Browse files Browse the repository at this point in the history
v1.5.4
  • Loading branch information
Impa10r authored Jun 21, 2024
2 parents 766d7d0 + 36ed30a commit 8ee5198
Show file tree
Hide file tree
Showing 13 changed files with 670 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"program": "${workspaceFolder}/cmd/psweb/",
"showLog": false,
"envFile": "${workspaceFolder}/.env",
"args": ["-datadir", "/home/vlad/.peerswap2"]
//"args": ["-datadir", "/home/vlad/.peerswap2"]
}
]
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Versions

## 1.5.4

- Hide HTTPS option for Umbrel
- AF: apply HTLC Fail Bumps only when Local % <= Low Liq %
- AF: for HTLC Fails above Low Liq % allow increasing Low Liq % threshold
- AF: log full fee changes history, including inbound
- AF: reduce LND load when applying auto fees
- AF: add realized PPM chart for the channel to help decide AF parameters

## 1.5.3

- Add automatic channel fees management
Expand Down
3 changes: 1 addition & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ representative at an online or offline event.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
t.me/vladgoryachev.
All complaints will be reviewed and investigated promptly and fairly.
https://peerswap.dev. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023-2024 Vlad Goryachev
Copyright (c) 2023-2024 Impa10r

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Getblock runs a publicly available Bitcoin Core server. It is used as a fallback

## Reporting a Vulnerability

If you discover any vulnerability, please contact me directly at t.me/vladgoryachev
If you discover any vulnerability, please report it discretely to contributors.
122 changes: 73 additions & 49 deletions cmd/psweb/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import (
"fmt"
"io"
"log"
"math"
"net"
"net/http"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"time"

"peerswap-web/cmd/psweb/bitcoin"
"peerswap-web/cmd/psweb/config"
"peerswap-web/cmd/psweb/db"
"peerswap-web/cmd/psweb/internet"
"peerswap-web/cmd/psweb/liquid"
"peerswap-web/cmd/psweb/ln"
"peerswap-web/cmd/psweb/ps"
"sort"
"strconv"
"strings"
"time"

"github.com/elementsproject/peerswap/peerswaprpc"
"github.com/gorilla/sessions"
Expand Down Expand Up @@ -375,7 +377,7 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
rates = "*" + rates
}

feeLog := ln.AutoFeeLog[ch.ChannelId]
feeLog := ln.LastAutoFeeLog(ch.ChannelId, false)
if feeLog != nil {
rates += ", last update " + timePassedAgo(time.Unix(feeLog.TimeStamp, 0))
rates += " from " + formatWithThousandSeparators(uint64(feeLog.OldRate))
Expand Down Expand Up @@ -831,19 +833,28 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
return
}

// get fee rates for all channels
outboundFeeRates := make(map[uint64]int64)
inboundFeeRates := make(map[uint64]int64)

ln.FeeReport(cl, outboundFeeRates, inboundFeeRates)

for _, peer := range res.GetPeers() {
alias := getNodeAlias(peer.NodeId)
for _, ch := range peer.Channels {
rates, custom := ln.AutoFeeRatesSummary(ch.ChannelId)
rule, custom := ln.AutoFeeRatesSummary(ch.ChannelId)
af, _ := ln.AutoFeeRule(ch.ChannelId)
channelList = append(channelList, &ln.AutoFeeStatus{
Enabled: ln.AutoFeeEnabled[ch.ChannelId],
LocalBalance: ch.LocalBalance,
RemoteBalance: ch.RemoteBalance,
Alias: alias,
LocalPct: ch.LocalBalance * 100 / (ch.LocalBalance + ch.RemoteBalance),
Rates: rates,
Custom: custom,
ChannelId: ch.ChannelId,
Enabled: ln.AutoFeeEnabled[ch.ChannelId],
Capacity: ch.LocalBalance + ch.RemoteBalance,
Alias: alias,
LocalPct: ch.LocalBalance * 100 / (ch.LocalBalance + ch.RemoteBalance),
Rule: rule,
Custom: custom,
AutoFee: af,
FeeRate: outboundFeeRates[ch.ChannelId],
InboundRate: inboundFeeRates[ch.ChannelId],
ChannelId: ch.ChannelId,
})

if ch.ChannelId == channelId {
Expand All @@ -858,7 +869,7 @@ func afHandler(w http.ResponseWriter, r *http.Request) {

// sort by LocalPct descending
sort.Slice(channelList, func(i, j int) bool {
return channelList[i].LocalPct > channelList[j].LocalPct
return channelList[i].LocalPct < channelList[j].LocalPct
})
//check for error errorMessage to display
errorMessage := ""
Expand All @@ -874,6 +885,13 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
popupMessage = keys[0]
}

chart := ln.PlotPPM(channelId)
// bubble square area reflects amount
for i, p := range *chart {
(*chart)[i].R = uint64(math.Sqrt(float64(p.Amount) / 10_000))
(*chart)[i].Label = "Routed: " + formatWithThousandSeparators(p.Amount) + ", Fee: " + formatWithThousandSeparators(p.Fee) + ", PPM: " + formatWithThousandSeparators(p.PPM)
}

type Page struct {
Authenticated bool
ErrorMessage string
Expand All @@ -890,6 +908,7 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
Enabled bool // for the displayed channel
AnyEnabled bool // for any channel
HasInboundFees bool
Chart *[]ln.DataPoint
}

data := Page{
Expand All @@ -908,6 +927,7 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
Enabled: ln.AutoFeeEnabled[channelId],
AnyEnabled: anyEnabled,
HasInboundFees: ln.HasInboundFees(),
Chart: chart,
}

// executing template named "af"
Expand Down Expand Up @@ -1155,8 +1175,6 @@ func configHandler(w http.ResponseWriter, r *http.Request) {
IsPossibleHTTPS: os.Getenv("NO_HTTPS") == "",
}

log.Println(os.Getenv("NO_HTTPS"))

// executing template named "config"
err := templates.ExecuteTemplate(w, "config", data)
if err != nil {
Expand Down Expand Up @@ -1424,6 +1442,12 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
return
}

rule.FailedMoveThreshold, err = strconv.Atoi(r.FormValue("failedMoveThreshold"))
if err != nil {
redirectWithError(w, r, "/af?", err)
return
}

rule.LowLiqPct, err = strconv.Atoi(r.FormValue("lowLiqPct"))
if err != nil {
redirectWithError(w, r, "/af?", err)
Expand Down Expand Up @@ -1502,9 +1526,6 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
}
}

// apply the new fees
ln.ApplyAutoFeeAll()

// all done, display confirmation
http.Redirect(w, r, "/af?id="+r.FormValue("channelId")+"&msg="+msg, http.StatusSeeOther)
return
Expand Down Expand Up @@ -1566,8 +1587,6 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {

if isEnabled {
msg += "Enabled"
// apply the new fees
ln.ApplyAutoFeeAll()
} else {
msg += "Disabled"
}
Expand Down Expand Up @@ -1612,12 +1631,15 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
}
}

err = ln.SetFeeRate(r.FormValue("peerNodeId"), channelId, feeRate, inbound, false)
oldRate, err := ln.SetFeeRate(r.FormValue("peerNodeId"), channelId, feeRate, inbound, false)
if err != nil {
redirectWithError(w, r, nextPage, err)
return
}

// log change
ln.LogFee(channelId, oldRate, int(feeRate), inbound, true)

// all good, display confirmation
msg := strings.Title(r.FormValue("direction")) + " fee rate updated to " + formatSigned(feeRate)
http.Redirect(w, r, nextPage+"msg="+msg, http.StatusSeeOther)
Expand Down Expand Up @@ -1659,7 +1681,7 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
}
}

err = ln.SetFeeRate(r.FormValue("peerNodeId"), channelId, feeBase, inbound, true)
_, err = ln.SetFeeRate(r.FormValue("peerNodeId"), channelId, feeBase, inbound, true)
if err != nil {
redirectWithError(w, r, nextPage, err)
return
Expand Down Expand Up @@ -1939,36 +1961,38 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) {
return
}

secureConnection, err := strconv.ParseBool(r.FormValue("secureConnection"))
if err != nil {
redirectWithError(w, r, "/config?", err)
return
}
if os.Getenv("NO_HTTPS") != "true" {
secureConnection, err := strconv.ParseBool(r.FormValue("secureConnection"))
if err != nil {
redirectWithError(w, r, "/config?", err)
return
}

// display CA certificate installation instructions
if secureConnection && !config.Config.SecureConnection {
config.Config.ServerIPs = r.FormValue("serverIPs")
config.Save()
http.Redirect(w, r, "/ca", http.StatusSeeOther)
return
}
// display CA certificate installation instructions
if secureConnection && !config.Config.SecureConnection {
config.Config.ServerIPs = r.FormValue("serverIPs")
config.Save()
http.Redirect(w, r, "/ca", http.StatusSeeOther)
return
}

if r.FormValue("serverIPs") != config.Config.ServerIPs {
config.Config.ServerIPs = r.FormValue("serverIPs")
if secureConnection {
if err := config.GenerateServerCertificate(); err == nil {
restart(w, r, true, config.Config.Password)
} else {
log.Println("GenereateServerCertificate:", err)
redirectWithError(w, r, "/config?", err)
return
if r.FormValue("serverIPs") != config.Config.ServerIPs {
config.Config.ServerIPs = r.FormValue("serverIPs")
if secureConnection {
if err := config.GenerateServerCertificate(); err == nil {
restart(w, r, true, config.Config.Password)
} else {
log.Println("GenereateServerCertificate:", err)
redirectWithError(w, r, "/config?", err)
return
}
}
}
}

if !secureConnection && config.Config.SecureConnection {
// restart to listen on HTTP only
restart(w, r, false, "")
if !secureConnection && config.Config.SecureConnection {
// restart to listen on HTTP only
restart(w, r, false, "")
}
}

allowSwapRequests, err := strconv.ParseBool(r.FormValue("allowSwapRequests"))
Expand Down
Loading

0 comments on commit 8ee5198

Please sign in to comment.