Skip to content

Commit

Permalink
Merge pull request #97 from Impa10r/v1.7.6
Browse files Browse the repository at this point in the history
v1.7.6
  • Loading branch information
Impa10r authored Jan 14, 2025
2 parents 3f4780e + ded4ddc commit 69fb29f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 67 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/psweb/bitcoin/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
57 changes: 24 additions & 33 deletions cmd/psweb/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions cmd/psweb/ln/claimjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ func JoinClaimJoin(claimBlockHeight uint32) bool {
if myPrivateKey != nil {
// persist to db
savePrivateKey()

} else {
return false
}
Expand All @@ -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)
Expand Down Expand Up @@ -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",
})
}

Expand Down
17 changes: 5 additions & 12 deletions cmd/psweb/ln/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cmd/psweb/ln/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
21 changes: 9 additions & 12 deletions cmd/psweb/ln/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down
6 changes: 3 additions & 3 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.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
Expand Down Expand Up @@ -281,7 +281,7 @@ func startTimer() {
onTimer()

// then every minute
for range time.Tick(60 * time.Second) {
for range time.Tick(time.Minute) {
onTimer()
}
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/psweb/templates/reusable.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<hr class="dropdown-divider" />
<a href="/logout" class="dropdown-item"> Logout </a>
{{end}}
<a href="https://swapmarket.github.io" target="_blank" class="dropdown-item"> Swap Market </a>
<a href="https://swapmarket.github.io" target="_blank" class="dropdown-item"> Swap Market ↗︎ </a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion cmd/psweb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 69fb29f

Please sign in to comment.