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

feat: chain autoswap #139

Merged
merged 35 commits into from
Jul 8, 2024
Merged

feat: chain autoswap #139

merged 35 commits into from
Jul 8, 2024

Conversation

jackstar12
Copy link
Member

No description provided.

@jackstar12 jackstar12 force-pushed the chain-autoswap branch 2 times, most recently from 02a3b53 to 2095d61 Compare April 21, 2024 16:27
@kilrau kilrau assigned jackstar12 and unassigned jackstar12 Apr 24, 2024
@jackstar12 jackstar12 force-pushed the chain-autoswap branch 2 times, most recently from 524b7ef to 74bd0c6 Compare April 28, 2024 11:57
@jackstar12 jackstar12 force-pushed the chain-autoswap branch 6 times, most recently from 3b3b7be to 1b9935e Compare May 10, 2024 07:29
@jackstar12 jackstar12 marked this pull request as ready for review May 12, 2024 17:01
@jackstar12 jackstar12 changed the title wip: chain autoswap feat: chain autoswap May 12, 2024
@jackstar12 jackstar12 force-pushed the chain-autoswap branch 3 times, most recently from 3981310 to d082fa9 Compare May 13, 2024 21:25
autoswap/autoswap.go Outdated Show resolved Hide resolved
autoswap/lightning_config.go Outdated Show resolved Hide resolved
autoswap/lightning_config.go Outdated Show resolved Hide resolved
boltzrpc/autoswaprpc/autoswaprpc.proto Outdated Show resolved Hide resolved
boltzrpc/autoswaprpc/autoswaprpc.proto Outdated Show resolved Hide resolved
@jackstar12 jackstar12 force-pushed the chain-autoswap branch 4 times, most recently from c2a29f9 to 7e70fcf Compare May 28, 2024 17:26
@kilrau
Copy link
Member

kilrau commented Jun 29, 2024

Missing as discussed is targeting 10k sats buffer for chain swaps (#140 will be shipped later)

@kilrau
Copy link
Member

kilrau commented Jul 1, 2024

No idea how I got into this config state, but definitely shouldn't crash.

$ boltzcli auto setup
? You already have an autoswap configuration. Do you want to reset it? Yes
? Which type of swaps should be executed? reverse
? Select wallet which should be used for swaps liquid
? How do you want to specify min/max balance values? percentage
? What is the maximum percentage of total capacity you want to keep in your channels? 20
? In which interval should the fee budget of the auto swapper be reset? (days) 7
? How many sats do you want to spend max on fees per budget interval? 50000

Config was saved successfully!
? Do you want to setup chain swaps as well? No
error reading from server: EOF
Jul 01 17:54:21 K-Yoga boltzd[5499]: 2024-07-01 17:54:21.398 [ERROR] Autoswap wallet configuration has become invalid: min balance must be smaller than max balance
Jul 01 17:54:24 K-Yoga boltzd[5499]: panic: runtime error: invalid memory address or nil pointer dereference
Jul 01 17:54:24 K-Yoga boltzd[5499]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xeef640]
Jul 01 17:54:24 K-Yoga boltzd[5499]: goroutine 177 [running]:
Jul 01 17:54:24 K-Yoga boltzd[5499]: github.com/BoltzExchange/boltz-client/autoswap.(*LightningConfig).GetSwapRecommendations(0xc0008d75f0)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/GitHub/boltz-client/autoswap/lightning.go:291 +0x40
Jul 01 17:54:24 K-Yoga boltzd[5499]: github.com/BoltzExchange/boltz-client/rpcserver.(*routedAutoSwapServer).GetRecommendations(0xc0000b7b20, {0x15bde30, 0xc000370690}, 0xc0003700f0)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/GitHub/boltz-client/rpcserver/autoswap.go:48 +0x85
Jul 01 17:54:24 K-Yoga boltzd[5499]: github.com/BoltzExchange/boltz-client/boltzrpc/autoswaprpc._AutoSwap_GetRecommendations_Handler.func1({0x15bde30?, 0xc000370690?}, {0x122e4c0?, 0xc0003700f0?})
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/GitHub/boltz-client/boltzrpc/autoswaprpc/autoswaprpc_grpc.pb.go:192 +0xcb
Jul 01 17:54:24 K-Yoga boltzd[5499]: github.com/BoltzExchange/boltz-client/rpcserver.(*RpcServer).Init.(*Service).UnaryServerInterceptor.func4({0x15bde30?, 0xc000370090?}, {0x122e4c0, 0xc0003700f0}, 0xc000054f00?, 0xc00082a990)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/GitHub/boltz-client/macaroons/interceptors.go:29 +0x6d
Jul 01 17:54:24 K-Yoga boltzd[5499]: google.golang.org/grpc.getChainUnaryHandler.func1({0x15bde30, 0xc000370090}, {0x122e4c0, 0xc0003700f0})
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1192 +0xb2
Jul 01 17:54:24 K-Yoga boltzd[5499]: github.com/BoltzExchange/boltz-client/rpcserver.(*RpcServer).Init.(*routedBoltzServer).UnaryServerInterceptor.func2({0x15bde30, 0xc000370090}, {0x122e4c0, 0xc0003700f0}, 0xc00056e9e0?, 0xc000054f00)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/GitHub/boltz-client/rpcserver/router.go:1493 +0x78
Jul 01 17:54:24 K-Yoga boltzd[5499]: google.golang.org/grpc.NewServer.chainUnaryServerInterceptors.chainUnaryInterceptors.func1({0x15bde30, 0xc000370090}, {0x122e4c0, 0xc0003700f0}, 0xc00056e9e0, 0x78?)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1183 +0x85
Jul 01 17:54:24 K-Yoga boltzd[5499]: github.com/BoltzExchange/boltz-client/boltzrpc/autoswaprpc._AutoSwap_GetRecommendations_Handler({0x12b95c0, 0xc0000b7b20}, {0x15bde30, 0xc000370090}, 0xc0008cca00, 0xc00056e2c0)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/GitHub/boltz-client/boltzrpc/autoswaprpc/autoswaprpc_grpc.pb.go:194 +0x143
Jul 01 17:54:24 K-Yoga boltzd[5499]: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0006f8c00, {0x15bde30, 0xc000370000}, {0x15c6880, 0xc0000df520}, 0xc0007cd200, 0xc000576030, 0x1e3f7e0, 0x0)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1372 +0xdd1
Jul 01 17:54:24 K-Yoga boltzd[5499]: google.golang.org/grpc.(*Server).handleStream(0xc0006f8c00, {0x15c6880, 0xc0000df520}, 0xc0007cd200)
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1783 +0xfb8
Jul 01 17:54:24 K-Yoga boltzd[5499]: google.golang.org/grpc.(*Server).serveStreams.func2.1()
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1016 +0x59
Jul 01 17:54:24 K-Yoga boltzd[5499]: created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 198
Jul 01 17:54:24 K-Yoga boltzd[5499]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1027 +0x106
Jul 01 17:54:24 K-Yoga systemd[1]: boltzd.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jul 01 17:54:24 K-Yoga systemd[1]: boltzd.service: Failed with result 'exit-code'.

Now it continues crashing:

Jul 01 17:55:24 K-Yoga boltzd[6417]: 2024-07-01 17:55:24.734 [ERROR] Autoswap wallet configuration has become invalid: min balance must be smaller than max balance
Jul 01 17:55:24 K-Yoga boltzd[6417]: 2024-07-01 17:55:24.735 [INFO ] Starting REST server on: 127.0.0.1:9003
Jul 01 17:55:24 K-Yoga boltzd[6417]: 2024-07-01 17:55:24.735 [INFO ] Starting RPC server on: 127.0.0.1:9002
Jul 01 17:57:36 K-Yoga boltzd[6417]: panic: runtime error: invalid memory address or nil pointer dereference
Jul 01 17:57:36 K-Yoga boltzd[6417]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xeef640]
Jul 01 17:57:36 K-Yoga boltzd[6417]: goroutine 131 [running]:
Jul 01 17:57:36 K-Yoga boltzd[6417]: github.com/BoltzExchange/boltz-client/autoswap.(*LightningConfig).GetSwapRecommendations(0xc00092d8c0)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/GitHub/boltz-client/autoswap/lightning.go:291 +0x40
Jul 01 17:57:36 K-Yoga boltzd[6417]: github.com/BoltzExchange/boltz-client/rpcserver.(*routedAutoSwapServer).GetRecommendations(0xc0002fc0a0, {0x15bde30, 0xc00070e780}, 0xc00070e3c0)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/GitHub/boltz-client/rpcserver/autoswap.go:48 +0x85
Jul 01 17:57:36 K-Yoga boltzd[6417]: github.com/BoltzExchange/boltz-client/boltzrpc/autoswaprpc._AutoSwap_GetRecommendations_Handler.func1({0x15bde30?, 0xc00070e780?}, {0x122e4c0?, 0xc00070e3c0?})
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/GitHub/boltz-client/boltzrpc/autoswaprpc/autoswaprpc_grpc.pb.go:192 +0xcb
Jul 01 17:57:36 K-Yoga boltzd[6417]: github.com/BoltzExchange/boltz-client/rpcserver.(*RpcServer).Init.(*Service).UnaryServerInterceptor.func4({0x15bde30?, 0xc00070e390?}, {0x122e4c0, 0xc00070e3c0}, 0xc000394300?, 0xc00072e1b0)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/GitHub/boltz-client/macaroons/interceptors.go:29 +0x6d
Jul 01 17:57:36 K-Yoga boltzd[6417]: google.golang.org/grpc.getChainUnaryHandler.func1({0x15bde30, 0xc00070e390}, {0x122e4c0, 0xc00070e3c0})
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1192 +0xb2
Jul 01 17:57:36 K-Yoga boltzd[6417]: github.com/BoltzExchange/boltz-client/rpcserver.(*RpcServer).Init.(*routedBoltzServer).UnaryServerInterceptor.func2({0x15bde30, 0xc00070e390}, {0x122e4c0, 0xc00070e3c0}, 0xc0007720c0?, 0xc000394300)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/GitHub/boltz-client/rpcserver/router.go:1493 +0x78
Jul 01 17:57:36 K-Yoga boltzd[6417]: google.golang.org/grpc.NewServer.chainUnaryServerInterceptors.chainUnaryInterceptors.func1({0x15bde30, 0xc00070e390}, {0x122e4c0, 0xc00070e3c0}, 0xc0007720c0, 0x78?)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1183 +0x85
Jul 01 17:57:36 K-Yoga boltzd[6417]: github.com/BoltzExchange/boltz-client/boltzrpc/autoswaprpc._AutoSwap_GetRecommendations_Handler({0x12b95c0, 0xc0002fc0a0}, {0x15bde30, 0xc00070e390}, 0xc0008d4080, 0xc0002fcec0)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/GitHub/boltz-client/boltzrpc/autoswaprpc/autoswaprpc_grpc.pb.go:194 +0x143
Jul 01 17:57:36 K-Yoga boltzd[6417]: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0003c8200, {0x15bde30, 0xc00070e2d0}, {0x15c6880, 0xc0003ca9c0}, 0xc00022cea0, 0xc000895230, 0x1e3f7e0, 0x0)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1372 +0xdd1
Jul 01 17:57:36 K-Yoga boltzd[6417]: google.golang.org/grpc.(*Server).handleStream(0xc0003c8200, {0x15c6880, 0xc0003ca9c0}, 0xc00022cea0)
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1783 +0xfb8
Jul 01 17:57:36 K-Yoga boltzd[6417]: google.golang.org/grpc.(*Server).serveStreams.func2.1()
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1016 +0x59
Jul 01 17:57:36 K-Yoga boltzd[6417]: created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 115
Jul 01 17:57:36 K-Yoga boltzd[6417]:         /home/kilrau/go/pkg/mod/google.golang.org/grpc@v1.60.1/server.go:1027 +0x106
Jul 01 17:57:36 K-Yoga systemd[1]: boltzd.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jul 01 17:57:36 K-Yoga systemd[1]: boltzd.service: Failed with result 'exit-code'.
$ boltzcli auto status
LN: Failed to start
Error: min balance must be smaller than max balance

Budget
 - From 2024-06-28T16:45:14+02:00 until 2024-07-05T16:45:14+02:00
 - Total: 50000 satoshis
 - Remaining: 50000 satoshis
Stats
 - Swaps: 0
 - Amount: 0 satoshis (avg 0 satoshis)
 - Fees: 0 satoshis (avg 0 satoshis)

Here my autoswap.toml:

[[chain]]
  budget = "50000"
  budgetInterval = "604800"
  enabled = false
  fromWallet = "liquid"
  maxBalance = "1000000"
  maxFeePercent = 1.0
  toAddress = ""
  toWallet = "LND"

[[lightning]]
  acceptZeroConf = false
  budget = "50000"
  budgetInterval = "604800"
  channelPollInterval = "30"
  currency = "LBTC"
  enabled = false
  failureBackoff = "86400"
  maxBalance = "0"
  maxBalancePercent = 20.0
  maxFeePercent = 1.0
  maxSwapAmount = "0"
  minBalance = "0"
  minBalancePercent = 25.0
  perChannel = false
  staticAddress = ""
  swapType = "reverse"
  wallet = "liquid"

boltzrpc/autoswaprpc/autoswaprpc.proto Outdated Show resolved Hide resolved
boltzrpc/autoswaprpc/autoswaprpc.proto Outdated Show resolved Hide resolved
Comment on lines +264 to +266
if onchain.Network == boltz.Regtest {
retry = 0
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not on regtest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Takes too long if you want to mock a test case where it actually isn't confirmed but is expected to

@jackstar12 jackstar12 force-pushed the chain-autoswap branch 2 times, most recently from 3ea3f98 to c50f4a1 Compare July 7, 2024 15:26
docs/autoswap.md Outdated Show resolved Hide resolved
docs/autoswap.md Outdated Show resolved Hide resolved
docs/autoswap.md Outdated
**Example**
- `inboundBalance` is set to 200k sats
- Current inbound balance of our 500k sats channel is 100k.
- Result: A 400k sats reverse swap since the inbound balance is below the set threshold.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Result: A 400k sats reverse swap since the inbound balance is below the set threshold.
- Result: A 400k sats reverse swap will be executed, to bring back inbound inbound balance to the full 500k sats channel capacity.```

@jackstar12 jackstar12 merged commit 866e454 into master Jul 8, 2024
2 checks passed
@michael1011 michael1011 deleted the chain-autoswap branch August 1, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants