Skip to content

Commit

Permalink
Merge pull request #51 from Impa10r/v1.5.1
Browse files Browse the repository at this point in the history
v1.5.1
  • Loading branch information
Impa10r authored May 31, 2024
2 parents b83b263 + 6884b1d commit 90be01f
Show file tree
Hide file tree
Showing 21 changed files with 727 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"buildFlags": "-tags lnd",
"buildFlags": "-tags cln",
"program": "${workspaceFolder}/cmd/psweb/",
"showLog": false,
"envFile": "${workspaceFolder}/.env",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Versions

## 1.5.1

- Enable setting fee rates, including inbound for LND 0.18+
- If failed on startup, keep trying to subscribe every minute
- Better UI colors (I think)

## 1.5.0

- Use hostname of the host in server.crt when run in Docker
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ RUN useradd -rm -s /bin/bash -u 1000 -U peerswap
USER peerswap

EXPOSE 1984
EXPOSE 1985

CMD ["/usr/bin/supervisord"]
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ docker run --net=host \
-v ~/.peerswap:/home/peerswap/.peerswap \
-e ELEMENTS_FOLDER="/home/$(whoami)/.elements" \
-e ELEMENTS_FOLDER_MAPPED="/home/peerswap/.elements" \
-e HOSTNAME="$(hostname)" \
-e NETWORK="testnet" \
ghcr.io/impa10r/peerswap-web:latest
```

This example assumes .lnd and .elements folders in the host user's home directory, and connects to LND via host network.
This example assumes .lnd and .elements folders in the host user's home directory, and connects to LND via host network. Change "testnet" to "mainnet" for production.

Config files should exist or wiil be created with default values. Depending on how your LND and Elements Core are actually installed, may require different parameters (-e). If -e NETWORK="testnet" is ommitted, mainnet assumed. See [Umbrel integration](https://github.com/Impa10r/umbrel-apps/blob/master/peerswap/docker-compose.yml) for supported env variables.
Config files should exist or wiil be created with default values. Depending on how your LND and Elements Core are actually installed, may require different parameters (-e). If -e NETWORK="testnet" is ommitted, mainnet assumed. See [Umbrel integration](https://github.com/getumbrel/umbrel-apps/blob/master/peerswap/docker-compose.yml) for all supported env variables.

If you need to run pscli in the docker container, first lookup container id with ```docker ps```. Then run ```docker exec "container id" pscli```.

Expand Down Expand Up @@ -204,11 +206,13 @@ Taken from [here](https://help.blockstream.com/hc/en-us/articles/900000632703-Ho

*Hint for Umbrel:* To save keystrokes, add these aliases to ~/.profile, then ```source .profile```
```
alias lncli="docker exec -it lightning_lnd_1 lncli" `(Umbrel 0.5 only)`
alias bcli="docker exec -it bitcoin_bitcoind_1 bitcoin-cli" `(Umbrel 0.5 only)`
alias lncli="docker exec -it lightning_lnd_1 lncli --lnddir /home/umbrel/umbrel/app-data/lightning/data/lnd"
alias bcli="docker exec -it bitcoin_bitcoind_1 bitcoin-cli -rpcuser=umbrel -rpcpassword=<your bitcoin password>"
alias ecli="docker exec -it elements_node_1 elements-cli -rpcuser=elements -rpcpassword=<your elements password>"
```

(lookup Elements and Bitcoin rpc passwords in pswebconfig.com)

# Support

Information about PeerSwap and a link to join our Discord channel is at [PeerSwap.dev](https://peerswap.dev). Additionally, there is a [Telegram group](https://t.me/PeerSwapLN) for node runners with PeerSwap. Just beware of scammers who may DM you. Immediately block and report to Telegram anyone with empty Username field.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Security Protocol

PeerSwap Web UI HTTP server offers secure communication with the clients via TLS. When HTTPS option is enabled, a self-signed root Certificate Authority certificate CA.crt is created first. It is then used to sign two certificates: server.crt and client.crt. Both CA.crt and client.crt need to be installed on the client's devices, to bootstrap a secure connection with the server. The server.crt certificate is used during the TLS handshake to authenticate the server to the client. Our communication channel is now encrypted and no third party can eavesdrop or connect to the server.
PeerSwap Web UI offers secure communication with the clients via TLS. When HTTPS option is enabled, a self-signed root Certificate Authority CA.crt is created first. It is then used to sign two certificates: server.crt and client.crt. Both CA.crt and client.crt need to be installed on the client's devices, to bootstrap a secure connection with the server. The server.crt certificate is used during the TLS handshake to authenticate the server to the client. Our communication channel is now encrypted and no third party can eavesdrop or connect to the server.

## Privacy Disclosure

Expand Down
5 changes: 2 additions & 3 deletions cmd/psweb/internet/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func GetFeeRate() float64 {
if cl == nil {
return 0
}
resp, err2 := cl.Do(req)
if err2 == nil {
resp, err := cl.Do(req)
if err == nil {
defer resp.Body.Close()
if resp.StatusCode != 200 {
return 0
Expand All @@ -93,7 +93,6 @@ func GetFeeRate() float64 {

// Unmarshal the JSON string into the struct
if err := json.Unmarshal(buf.Bytes(), &fees); err != nil {
log.Println("Mempool GetFee:", err)
return 0
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/psweb/internet/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internet

import (
"encoding/json"
"log"
"net/http"
)

Expand All @@ -13,7 +12,6 @@ func GetLatestTag() string {

req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Println("Error creating request:", err)
return ""
}

Expand Down
85 changes: 82 additions & 3 deletions cmd/psweb/ln/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
forwardsIn = make(map[uint64][]Forwarding)
forwardsOut = make(map[uint64][]Forwarding)
forwardsLastIndex uint64
downloadComplete bool
)

func GetClient() (*glightning.Lightning, func(), error) {
Expand Down Expand Up @@ -637,9 +638,12 @@ func (r ListPeerChannelsRequest) Name() string {
return "listpeerchannels"
}

// get fees on the channel
// get fees for the channel
func GetChannelInfo(client *glightning.Lightning, lndChannelId uint64, nodeId string) *ChanneInfo {
info := new(ChanneInfo)

info.ChannelId = lndChannelId

channelId := ConvertLndToClnChannelId(lndChannelId)

var response map[string]interface{}
Expand All @@ -657,8 +661,8 @@ func GetChannelInfo(client *glightning.Lightning, lndChannelId uint64, nodeId st
for _, channel := range channels {
channelMap := channel.(map[string]interface{})
if channelMap["short_channel_id"].(string) == channelId {
info.FeeBase = uint64(channelMap["fee_base_msat"].(float64))
info.FeeRate = uint64(channelMap["fee_proportional_millionths"].(float64))
info.FeeBase = int64(channelMap["fee_base_msat"].(float64))
info.FeeRate = int64(channelMap["fee_proportional_millionths"].(float64))
updates := channelMap["updates"].(map[string]interface{})
local := updates["local"].(map[string]interface{})
remote := updates["remote"].(map[string]interface{})
Expand Down Expand Up @@ -835,6 +839,11 @@ func GetMyAlias() string {

// scans all channels to get peerswap lightning fees cached
func SubscribeAll() {
if downloadComplete {
// only run once if successful
return
}

client, clean, err := GetClient()
if err != nil {
return
Expand All @@ -855,6 +864,8 @@ func SubscribeAll() {
fetchPaymentsStats(client, timestamp, channelId)
}
}

downloadComplete = true
}

// get invoicedMsat, paidOutMsat, costMsat
Expand Down Expand Up @@ -970,3 +981,71 @@ func EstimateFee() float64 {

return float64(res.Details.Urgent) / 1000
}

// get fees for all channels by filling the maps [channelId]
func FeeReport(client *glightning.Lightning, outboundFeeRates map[uint64]int64, inboundFeeRates map[uint64]int64) error {
var response map[string]interface{}

err := client.Request(&ListPeerChannelsRequest{}, &response)
if err != nil {
log.Println(err)
return err
}

// Iterate over channels to get fees
channels := response["channels"].([]interface{})
for _, channel := range channels {
channelMap := channel.(map[string]interface{})
channelId := ConvertClnToLndChannelId(channelMap["short_channel_id"].(string))
outboundFeeRates[channelId] = int64(channelMap["fee_proportional_millionths"].(float64))
}

return nil
}

type SetChannelRequest struct {
Id string `json:"id"`
BaseMilliSatoshis int64 `json:"feebase,omitempty"`
PartPerMillion int64 `json:"feeppm,omitempty"`
}

func (r *SetChannelRequest) Name() string {
return "setchannel"
}

// set fee rate for a channel
func SetFeeRate(peerNodeId string,
channelId uint64,
feeRate int64,
inbound bool,
isBase bool) error {

if inbound {
return errors.New("inbound rates are not implemented")
}

client, cleanup, err := GetClient()
if err != nil {
log.Println("SetFeeRate:", err)
return err
}
defer cleanup()

var req SetChannelRequest
var res map[string]interface{}

req.Id = ConvertLndToClnChannelId(channelId)
if isBase {
req.BaseMilliSatoshis = feeRate
} else {
req.PartPerMillion = feeRate
}

err = client.Request(&req, &res)
if err != nil {
log.Println("SetFeeRate:", err)
return err
}

return nil
}
7 changes: 5 additions & 2 deletions cmd/psweb/ln/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ type ChannelStats struct {
}

type ChanneInfo struct {
ChannelId uint64
LocalBalance uint64
RemoteBalance uint64
FeeRate uint64
FeeBase uint64
FeeRate int64 // PPM
FeeBase int64 // mSat
InboundFeeRate int64 // PPM
InboundFeeBase int64 // mSat
Active bool
OurMaxHtlcMsat uint64
OurMinHtlcMsat uint64
Expand Down
Loading

0 comments on commit 90be01f

Please sign in to comment.