Skip to content

Commit

Permalink
Merge pull request #62 from Impa10r/v1.5.5
Browse files Browse the repository at this point in the history
v1.5.5
  • Loading branch information
Impa10r authored Jun 21, 2024
2 parents 8ee5198 + dbcad2d commit 30d8c5b
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Versions

## 1.5.5

- Fix panic
- Add lines to AF chart for High/Normal/Low Liq rates

## 1.5.4

- Hide HTTPS option for Umbrel
Expand Down
21 changes: 17 additions & 4 deletions cmd/psweb/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,18 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
err := templates.ExecuteTemplate(w, "homepage", data)
if err != nil {
if strings.Contains(err.Error(), "broken pipe") || strings.Contains(err.Error(), "http2: stream closed") {
log.Printf("Detected error '%v' while executing template, retrying...", err.Error())
time.Sleep(1 * time.Second)
time.Sleep(5 * time.Second)
continue
} else {
log.Printf("Template execution error: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
}
return
}

log.Println("Failed to execute template after 3 attempts due to broken pipe")
http.Error(w, "Service Unavailable", http.StatusServiceUnavailable)
//http.Error(w, "Service Unavailable", http.StatusServiceUnavailable)
}

func peerHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -839,6 +837,11 @@ func afHandler(w http.ResponseWriter, r *http.Request) {

ln.FeeReport(cl, outboundFeeRates, inboundFeeRates)

capacity := uint64(0)
localPct := uint64(0)
feeRate := outboundFeeRates[channelId]
inboundRate := inboundFeeRates[channelId]

for _, peer := range res.GetPeers() {
alias := getNodeAlias(peer.NodeId)
for _, ch := range peer.Channels {
Expand All @@ -860,6 +863,8 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
if ch.ChannelId == channelId {
peerName = alias
peerId = peer.NodeId
capacity = ch.LocalBalance + ch.RemoteBalance
localPct = ch.LocalBalance * 100 / (ch.LocalBalance + ch.RemoteBalance)
}
if ln.AutoFeeEnabled[ch.ChannelId] {
anyEnabled = true
Expand Down Expand Up @@ -901,6 +906,10 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
ChannelId uint64
PeerName string
PeerId string
Capacity uint64
LocalPct uint64
FeeRate int64
InboundRate int64
GlobalEnabled bool
ChannelList []*ln.AutoFeeStatus
Params *ln.AutoFeeParams
Expand All @@ -920,6 +929,10 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
GlobalEnabled: ln.AutoFeeEnabledAll,
PeerName: peerName,
PeerId: peerId,
Capacity: capacity,
LocalPct: localPct,
FeeRate: feeRate,
InboundRate: inboundRate,
ChannelId: channelId,
ChannelList: channelList,
Params: rule,
Expand Down
18 changes: 18 additions & 0 deletions cmd/psweb/ln/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,3 +1210,21 @@ func ApplyAutoFees() {

autoFeeIsRunning = false
}

func PlotPPM(channelId uint64) *[]DataPoint {
var plot []DataPoint

for _, e := range forwardsOut[channelId] {
// ignore small forwards
if e.OutMsat > 1000000 {
plot = append(plot, DataPoint{
TS: uint64(e.ResolvedTime),
Amount: e.OutMsat / 1000,
Fee: e.FeeMsat / 1000,
PPM: e.FeeMsat * 1_000_000 / e.OutMsat,
})
}
}

return &plot
}
1 change: 0 additions & 1 deletion cmd/psweb/ln/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func LastAutoFeeLog(channelId uint64, isInbound bool) *AutoFeeEvent {
return AutoFeeLog[channelId][i]
}
}

return nil
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/psweb/ln/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1861,8 +1861,11 @@ func ApplyAutoFees() {
toSet = true
} else if liqPct >= params.LowLiqPct && policy.InboundFeeRateMilliMsat < 0 {
// remove discount unless it was manually set
if !LastAutoFeeLog(ch.ChanId, true).IsManual {
toSet = true
lastFee := LastAutoFeeLog(ch.ChanId, true)
if lastFee != nil {
if lastFee.IsManual {
toSet = true
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/psweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

const (
// App version tag
version = "v1.5.4"
version = "v1.5.5"
)

type SwapParams struct {
Expand Down Expand Up @@ -845,7 +845,7 @@ func convertOtherPeersToHTMLTable(peers []*peerswaprpc.PeerSwapPeer,
// alias is a link to open peer details page
peerTable += "<a href=\"/peer?id=" + peer.NodeId + "\">"

peerTable += "<span title=\"Not using PeerSwap\">🙁&nbsp</span>"
// peerTable += "<span title=\"Not using PeerSwap\">🙁&nbsp</span>"
peerTable += "<span title=\"Invite peer to PeerSwap via a direct Keysend message\">" + getNodeAlias(peer.NodeId)
peerTable += "</span></a>"

Expand Down
6 changes: 3 additions & 3 deletions cmd/psweb/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (rw *responseWriter) Write(p []byte) (int, error) {
if err != nil {
if strings.Contains(err.Error(), "stream closed") || strings.Contains(err.Error(), "broken pipe") {
rw.brokenPipe = true
log.Println("Detected broken pipe error")
} else {
log.Printf("Write error: %v", err)
}
Expand Down Expand Up @@ -57,10 +56,11 @@ func authMiddleware(next http.Handler) http.Handler {
if !rw.brokenPipe {
return
}
time.Sleep(1 * time.Second) // Wait before retrying
time.Sleep(5 * time.Second) // Wait before retrying
}

http.Error(w, "Service Unavailable", http.StatusServiceUnavailable)
// http.Error(w, "Service Unavailable", http.StatusServiceUnavailable)
return
})
}

Expand Down
13 changes: 13 additions & 0 deletions cmd/psweb/static/js/chart.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions cmd/psweb/static/js/chartjs-adapter-moment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cmd/psweb/static/js/moment.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions cmd/psweb/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,15 @@ input[type=checkbox] {
padding: 0.5em; /* reduce padding inside input cells */
}
}

/* Style for the tooltip */
#tooltip {
position: absolute;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 5px;
border-radius: 3px;
pointer-events: none;
display: none;
font-size: 12px;
}
67 changes: 58 additions & 9 deletions cmd/psweb/templates/af.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
<div style="display: grid; grid-template-columns: auto auto; padding-bottom: 0.5em;">
<div style="text-align: left;">
<h4 class="title is-4">
{{if ne .PeerName "Default Rule"}}<a href="/peer?id={{.PeerId}}">{{end}}
{{if .ChannelId}}<a href="/peer?id={{.PeerId}}">{{end}}
{{.PeerName}}
{{if ne .PeerName "Default Rule"}}</a>{{end}}
{{if .ChannelId}}</a>{{end}}
{{if .ChannelId}}
{{if .CustomRule}}
(custom)
{{else}}
(<a href="/af">default</a>)
{{end}}
{{end}}
</h4>
</h4>
</div>
<div style="display: flex; justify-content: flex-end;">
{{if .ChannelId}}
Expand All @@ -67,6 +67,9 @@
{{end}}
</div>
</div>
{{if .ChannelId}}
<p style="text-align: left;">Capacity: {{m .Capacity}}, {{.LocalPct}}% local, fee rate: {{fs .FeeRate}}{{if .HasInboundFees}}, inbound rate: {{.InboundRate}}{{end}}</p>
{{end}}
<form autocomplete="off" action="/submit" method="post" onsubmit="return confirmSubmit()">
<input autocomplete="false" name="hidden" type="text" style="display:none;">
<table style="width:100%; table-layout:fixed; margin-bottom: 0.5em">
Expand All @@ -78,7 +81,7 @@
</td>
<td>
<div class="field-body">
<input class="input is-medium" type="number" name="excessRate" min="0" required value="{{.Params.ExcessRate}}">
<input class="input is-medium" type="number" id="excessRate" name="excessRate" min="0" required value="{{.Params.ExcessRate}}" onchange="updateChart()">
</div>
</td>
<td>
Expand All @@ -100,7 +103,7 @@
</td>
<td>
<div class="field-body">
<input class="input is-medium" type="number" name="normalRate" min="0" required required value="{{.Params.NormalRate}}">
<input class="input is-medium" type="number" id="normalRate" name="normalRate" min="0" required required value="{{.Params.NormalRate}}" onchange="updateChart()">
</div>
</td>
<td>
Expand All @@ -122,7 +125,7 @@
</td>
<td>
<div class="field-body">
<input class="input is-medium" type="number" name="lowLiqRate" min="0" required value="{{.Params.LowLiqRate}}">
<input class="input is-medium" type="number" id="lowLiqRate" name="lowLiqRate" min="0" required value="{{.Params.LowLiqRate}}" onchange="updateChart()">
</div>
</td>
<td>
Expand Down Expand Up @@ -218,6 +221,7 @@
<h4 class="title is-4">Realized Routing PPM<h4>
<div style="width: 100%; margin: auto;">
<canvas id="myScatterChart"></canvas>
<div id="tooltip"></div>
</div>
</div>
{{end}}
Expand Down Expand Up @@ -305,11 +309,39 @@
}
}

// Plugin to draw horizontal lines
const horizontalLinePlugin = {
id: 'horizontalLine',
afterDraw: (chart) => {
const { ctx, chartArea: { left, right }, scales: { y } } = chart;
const lines = chart.config.options.horizontalLines;

if (lines) {
lines.forEach(line => {
const yValue = line.value;
const yPixel = y.getPixelForValue(yValue);

ctx.save();
ctx.beginPath();
ctx.moveTo(left, yPixel);
ctx.lineTo(right, yPixel);
ctx.lineWidth = line.width || 2;
ctx.strokeStyle = line.color || 'black';
ctx.stroke();
ctx.restore();
});
}
}
};

// Register the plugin
Chart.register(horizontalLinePlugin);

// Get the context of the canvas element we want to select
var ctx = document.getElementById('myScatterChart').getContext('2d');

// Create the chart
var myScatterChart = new Chart(ctx, {
var myChart = new Chart(ctx, {
type: 'bubble', // The type of chart we want to create
data: {
datasets: [{
Expand Down Expand Up @@ -346,7 +378,7 @@
}
},
y: {
beginAtZero: false,
beginAtZero: true,
{{if eq .ColorScheme "dark"}}
grid: {
color: 'rgba(255, 255, 255, 0.1)', // Set grid line color (white with reduced opacity)
Expand Down Expand Up @@ -374,10 +406,27 @@
legend: {
display: false
},
}
},
horizontalLines: [
{ value: {{.Params.ExcessRate}}, color: 'green', width: 2 },
{ value: {{.Params.NormalRate}}, color: 'blue', width: 2 },
{ value: {{.Params.LowLiqRate}}, color: 'darkred', width: 2 }
]
}
});

function updateChart() {
const line1Value = parseFloat(document.getElementById('excessRate').value);
const line2Value = parseFloat(document.getElementById('normalRate').value);
const line3Value = parseFloat(document.getElementById('lowLiqRate').value);

myChart.config.options.horizontalLines[0].value = line1Value;
myChart.config.options.horizontalLines[1].value = line2Value;
myChart.config.options.horizontalLines[2].value = line3Value;

myChart.update();
}

</script>
</div>
{{template "footer" .}}
Expand Down
6 changes: 3 additions & 3 deletions cmd/psweb/templates/reusable.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.7.1"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@1.0.0"></script>
<script src="/static/js/moment.min.js"></script>
<script src="/static/js/chart.js"></script>
<script src="/static/js/chartjs-adapter-moment.js"></script>
</head>
</header>
<section class="section">
Expand Down

0 comments on commit 30d8c5b

Please sign in to comment.