Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make lwk available #288

Merged
merged 29 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ae9ae99
txwatcher: delete deadcode
YusukeShimizu Mar 26, 2024
0735dab
multi: refactor interfaces onchain wallet
YusukeShimizu Mar 26, 2024
c1dd008
lwk: lwk package
YusukeShimizu Mar 26, 2024
baaf69d
lwk: txwatcher
YusukeShimizu Mar 26, 2024
ab80a53
multi: lwk configuration support for Liquid swaps
YusukeShimizu Mar 26, 2024
ff46495
test: add integration test for LWK
YusukeShimizu Mar 26, 2024
8ad9a7a
doc: add LWK setup guide
YusukeShimizu Mar 26, 2024
cdd89ea
nix: add lwk and blockstream-electrs packages
YusukeShimizu May 1, 2024
3fe81f6
wip: claim_coop case
YusukeShimizu May 2, 2024
383a143
txwather: wait for initial block header sub
YusukeShimizu May 10, 2024
381daa1
lwk: add TLS support for Electrum
YusukeShimizu May 13, 2024
1041bed
test: add integration test for LWK and liquid
YusukeShimizu May 23, 2024
58c516c
lwk: check if the version is supported
YusukeShimizu May 26, 2024
53e56fd
config: make lwk-related settings clear
YusukeShimizu May 29, 2024
83603a2
config: include LWK configuration in the output
YusukeShimizu May 30, 2024
d1f6a89
lwk: ensure thread safety
YusukeShimizu May 30, 2024
f2ee818
electrum: proper log output of tx watcher
YusukeShimizu May 31, 2024
3d45569
clightning: add LWK configuration options
YusukeShimizu Jun 6, 2024
aa9550b
cln+lnd: liveness check
YusukeShimizu Jun 12, 2024
1d98fe2
lwk: set prime seconds
YusukeShimizu Jun 12, 2024
cd24c35
cln+lnd: liveness check on swapout
YusukeShimizu Jun 16, 2024
2a3b3f4
test: add tests for backend down
YusukeShimizu Jun 19, 2024
8ed026d
nix: update pinned nixpkgs revision
YusukeShimizu Jun 20, 2024
6c6c802
electrum: ensure client is properly reinitialized
YusukeShimizu Jun 26, 2024
c4e9145
swap: add exponential backoff and jitter mechanism
YusukeShimizu Jun 26, 2024
22f4e66
swap: add missing Event_OnTimeout transition
YusukeShimizu Jun 26, 2024
45fb414
multi: using nix flake and upgrading lwk
YusukeShimizu Jun 29, 2024
7045055
lwkwallet: refactor fee calculations
YusukeShimizu Jun 29, 2024
66fead0
lwkwallet: implement SetLabel method
YusukeShimizu Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
test-vector: [bitcoin-cln, bitcoin-lnd, liquid-cln, liquid-lnd, misc-integration]
test-vector: [bitcoin-cln, bitcoin-lnd, liquid-cln, liquid-lnd, misc-integration, lwk-cln, lwk-lnd]

steps:
- name: Checkout code
Expand Down
26 changes: 24 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ${TEST_BIN_DIR}/peerswap:

# Test section. Has commads for local and ci testing.
test:
PAYMENT_RETRY_TIME=5 go test -tags dev -tags fast_test -timeout=10m -v ./...
PAYMENT_RETRY_TIME=5 go test -tags dev -tags fast_test -race -timeout=10m -v ./...
.PHONY: test

test-integration: test-bins
Expand Down Expand Up @@ -127,6 +127,20 @@ test-liquid-lnd: test-bins
./test
.PHONY: test-liquid-lnd

test-lwk-cln: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_ClnCln_LWK_SwapIn)'\
./test
.PHONY: test-lwk-cln

test-lwk-lnd: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_LndLnd_LWK_SwapIn)'\
./test
.PHONY: test-lwk-lnd

test-misc-integration: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
Expand Down Expand Up @@ -185,12 +199,12 @@ TOOLS_DIR := ${CURDIR}/tools
tool:
## Install an individual dependent tool.
@cd $(TOOLS_DIR) && env GOBIN=$(TOOLS_DIR)/bin go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint
@cd $(TOOLS_DIR) && env GOBIN=$(TOOLS_DIR)/bin go install -trimpath go.uber.org/mock/mockgen@latest

.PHONY: clean
clean: ## clean project directory.
env GOBIN=${TOOLS_DIR}/bin && @rm -rf ${GOBIN} $(TOOLS_DIR)/bin


.PHONY: lint
lint: lint/golangci-lint
lint: ## Lint source.
Expand All @@ -203,3 +217,11 @@ lint/golangci-lint: ## Lint source with golangci-lint.
.PHONY: lint/fix
lint/fix: ## Lint and fix source.
@${MAKE} lint/golangci-lint args='--fix'


.PHONY: mockgen
mockgen: mockgen/lwk

.PHONY: mockgen/lwk
mockgen/lwk:
$(TOOLS_DIR)/bin/mockgen -source=electrum/electrum.go -destination=electrum/mock/electrum.go
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ To run PeerSwap as a standalone daemon with LND, see the [LND setup guide](./doc

To run Elements for L-BTC swaps, see the [Elements setup guide](./docs/setup_elementsd.md).

To run LWK for L-BTC swaps, see the [LWK setup guide](./docs/setup_lwk.md).

> **Note**
> Most of the benefits of PeerSwap come from using L-BTC. Swaps using L-BTC are more private, faster, and avoid the mainchain blockchain during high fee environments that can make swaps uneconomical.

Expand Down
22 changes: 15 additions & 7 deletions clightning/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/elementsproject/glightning/gbitcoin"
"github.com/elementsproject/peerswap/onchain"

"github.com/elementsproject/glightning/gelements"
"github.com/elementsproject/glightning/glightning"
"github.com/elementsproject/glightning/jrpc2"
"github.com/elementsproject/peerswap/lightning"
Expand Down Expand Up @@ -64,14 +63,12 @@ type ClightningClient struct {
glightning *glightning.Lightning
Plugin *glightning.Plugin

liquidWallet *wallet.ElementsRpcWallet
liquidWallet wallet.Wallet
swaps *swap.SwapService
requestedSwaps *swap.RequestedSwapsPrinter
policy PolicyReloader
pollService *poll.Service

Gelements *gelements.Elements

gbitcoin *gbitcoin.Bitcoin
bitcoinChain *onchain.BitcoinOnChain
bitcoinNetwork *chaincfg.Params
Expand Down Expand Up @@ -323,14 +320,13 @@ func (cl *ClightningClient) GetPreimage() (lightning.Preimage, error) {
}

// SetupClients injects the required services
func (cl *ClightningClient) SetupClients(liquidWallet *wallet.ElementsRpcWallet,
func (cl *ClightningClient) SetupClients(liquidWallet wallet.Wallet,
swaps *swap.SwapService,
policy PolicyReloader, requestedSwaps *swap.RequestedSwapsPrinter, elements *gelements.Elements,
policy PolicyReloader, requestedSwaps *swap.RequestedSwapsPrinter,
bitcoin *gbitcoin.Bitcoin, bitcoinChain *onchain.BitcoinOnChain, pollService *poll.Service) {
cl.liquidWallet = liquidWallet
cl.requestedSwaps = requestedSwaps
cl.swaps = swaps
cl.Gelements = elements
cl.policy = policy
cl.gbitcoin = bitcoin
cl.pollService = pollService
Expand Down Expand Up @@ -359,6 +355,14 @@ func (cl *ClightningClient) SetPeerswapConfig(config *Config) {
LiquidDisabled: *config.Liquid.LiquidSwaps,
PeerswapDir: config.PeerswapDir,
}
if config.LWK != nil {
cl.peerswapConfig.LWKSignerName = config.LWK.GetSignerName()
cl.peerswapConfig.LWKWalletName = config.LWK.GetWalletName()
cl.peerswapConfig.LWKEndpoint = config.LWK.GetLWKEndpoint()
cl.peerswapConfig.ElectrumEndpoint = config.LWK.GetElectrumEndpoint()
cl.peerswapConfig.LWKNetwork = config.LWK.GetNetwork()
cl.peerswapConfig.LWKLiquidSwaps = config.LWK.GetLiquidSwaps()
}
}

func (cl *ClightningClient) GetLightningRpc() *glightning.Lightning {
Expand Down Expand Up @@ -404,6 +408,10 @@ func (cl *ClightningClient) OnCustomMsg(event *glightning.CustomMsgReceivedEvent
return event.Continue(), nil
}

type Message struct {
Message string `json:"message"`
}

// AddMessageHandler adds a listener for incoming peermessages
func (cl *ClightningClient) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error) {
cl.msgHandlers = append(cl.msgHandlers, f)
Expand Down
7 changes: 2 additions & 5 deletions clightning/clightning_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ func (l *SwapOut) Call() (jrpc2.Result, error) {
if !l.cl.swaps.LiquidEnabled {
return nil, errors.New("liquid swaps are not enabled")
}
if l.cl.Gelements == nil {
return nil, errors.New("peerswap was not started with liquid node config")
if ok, perr := l.cl.liquidWallet.Ping(); perr != nil || !ok {
return nil, fmt.Errorf("liquid wallet not reachable: %v", perr)
}

} else if strings.Compare(l.Asset, "btc") == 0 {
Expand Down Expand Up @@ -366,9 +366,6 @@ func (l *SwapIn) Call() (jrpc2.Result, error) {
if !l.cl.swaps.LiquidEnabled {
return nil, errors.New("liquid swaps are not enabled")
}
if l.cl.Gelements == nil {
return nil, errors.New("peerswap was not started with liquid node config")
}
liquidBalance, err := l.cl.liquidWallet.GetBalance()
if err != nil {
return nil, err
Expand Down
Loading
Loading