Skip to content

Commit c3fa12e

Browse files
authored
Merge pull request #907 from hieblmi/static-regtest
regtest: adding aperture docker instance
2 parents e734d69 + 64b1aed commit c3fa12e

File tree

3 files changed

+255
-6
lines changed

3 files changed

+255
-6
lines changed

regtest/README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,152 @@ $ ./regtest.sh mine 1
145145
2021-03-19T17:19:21Z LOOP_IN SUCCESS 0.005 BTC - P2WSH: bcrt1q4p0pead4tfepm683fff8fl8g3kpx8spjztuquu2sctfzed9rufls2z0g2f (cost: server 71, onchain 7650, offchain 0)
146146
```
147147

148+
# Static Address Loop In
149+
150+
Static Address Loop In is a new loop-in mode that, like Loop In, allows you to
151+
swap your on-chain balance for off-chain (channel) balance, but in contrast to
152+
the legacy loop-in, you can receive the off-chain balance instantly (after funds
153+
were deposited to a static address).
154+
To do so a two-step process is required, the setup and the swap phase.
155+
156+
To setup a static address and deposit funds to it, do the following:
157+
158+
```shell
159+
./regtest.sh loop static new  ✔  11:59:12
160+
161+
WARNING: Be aware that loosing your l402.token file in .loop under your home directory will take your ability to spend funds sent to the static address via loop-ins or withdrawals. You will have to wait until the deposit expires and your loop client sweeps the funds back to your lnd wallet. The deposit expiry could be months in the future.
162+
163+
CONTINUE WITH NEW ADDRESS? (y/n): y
164+
Received a new static loop-in address from the server: bcrt1pzgdmxftg3t6wghl2t72ewqyf3jvy2t85ud6pqsagx0zm9mj8f3aq23v3t4
165+
```
166+
A static address has been created. You can send funds to it across different
167+
transactions. Each transaction output to this address is considered a deposit
168+
that can be used individually or in combination with other deposits to be
169+
swapped for an off-chain payment. Let's create a few deposits and confirm them:
170+
```shell
171+
./regtest.sh lndclient sendcoins --addr bcrt1pzgdmxftg3t6wghl2t72ewqyf3jvy2t85ud6pqsagx0zm9mj8f3aq23v3t4 --amt 250000 --min_confs 0 -f
172+
{
173+
"txid": "86ccc85449957c3472a259e447a9180aff49848f0b957a85c24819a5f432eda7"
174+
}
175+
./regtest.sh lndclient sendcoins --addr bcrt1pzgdmxftg3t6wghl2t72ewqyf3jvy2t85ud6pqsagx0zm9mj8f3aq23v3t4 --amt 250000 --min_confs 0 -f
176+
{
177+
"txid": "09d72c89b2346dc068bb57621463e53637f3c0cca3ba8ebb7fcb2773d7f32ae3"
178+
}
179+
./regtest.sh lndclient sendcoins --addr bcrt1pzgdmxftg3t6wghl2t72ewqyf3jvy2t85ud6pqsagx0zm9mj8f3aq23v3t4 --amt 250000 --min_confs 0 -f
180+
{
181+
"txid": "5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f"
182+
}
183+
184+
./regtest.sh mine 6
185+
```
186+
The loop client logs should show the deposits being confirmed:
187+
```shell
188+
[DBG] SADDR: Received deposit: 5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f:0
189+
[DBG] SADDR: Deposit 5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f:0: NextState: Deposited, PreviousState: , Event: OnStart
190+
[DBG] SADDR: Received deposit: 86ccc85449957c3472a259e447a9180aff49848f0b957a85c24819a5f432eda7:1
191+
[DBG] SADDR: Deposit 86ccc85449957c3472a259e447a9180aff49848f0b957a85c24819a5f432eda7:1: NextState: Deposited, PreviousState: , Event: OnStart
192+
[DBG] SADDR: Received deposit: 09d72c89b2346dc068bb57621463e53637f3c0cca3ba8ebb7fcb2773d7f32ae3:1
193+
[DBG] SADDR: Deposit 09d72c89b2346dc068bb57621463e53637f3c0cca3ba8ebb7fcb2773d7f32ae3:1: NextState: Deposited, PreviousState: , Event: OnStart
194+
```
195+
Let's list the deposits in the loop client:
196+
```shell
197+
./regtest.sh loop static listdeposits --filter deposited  ✔  12:03:37
198+
{
199+
"filtered_deposits": [
200+
{
201+
"id": "5afc81a72464881e66aa6a5d7476b75cae26ea4c74c70424e4a68e63b9708e0c",
202+
"state": "DEPOSITED",
203+
"outpoint": "5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f:0",
204+
"value": "250000",
205+
"confirmation_height": "126",
206+
"blocks_until_expiry": "715"
207+
},
208+
{
209+
"id": "0bf419bb047922afc186021fc186970b0b71db83444b39b0dcad4550014e0ba3",
210+
"state": "DEPOSITED",
211+
"outpoint": "86ccc85449957c3472a259e447a9180aff49848f0b957a85c24819a5f432eda7:1",
212+
"value": "250000",
213+
"confirmation_height": "126",
214+
"blocks_until_expiry": "715"
215+
},
216+
{
217+
"id": "ea969e2ca53b608d4cf9ca8def249d77ee1db444bd3384ae1150ea03bb03dbbd",
218+
"state": "DEPOSITED",
219+
"outpoint": "09d72c89b2346dc068bb57621463e53637f3c0cca3ba8ebb7fcb2773d7f32ae3:1",
220+
"value": "250000",
221+
"confirmation_height": "126",
222+
"blocks_until_expiry": "715"
223+
}
224+
]
225+
}
226+
```
227+
These deposits can now be instantly swapped. Let's use the first one:
228+
```shell
229+
./regtest.sh loop static in --utxo 5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f:0
230+
On-chain fees for static address loop-ins are not included.
231+
They were already paid when the deposits were created.
232+
233+
Previously deposited on-chain: 250000 sat
234+
Receive off-chain: 249614 sat
235+
Estimated total fee: 386 sat
236+
237+
CONTINUE SWAP? (y/n): y
238+
{
239+
"swap_hash": "43ed16958d5a5bf0e6cb9a36eefb1493f39741238f06d6c7b5365c1c5c22d29e",
240+
"state": "SignHtlcTx",
241+
"amount": "250000",
242+
"htlc_cltv": 431,
243+
"quoted_swap_fee_satoshis": "386",
244+
"max_swap_fee_satoshis": "386",
245+
"initiation_height": 131,
246+
"protocol_version": "V0",
247+
"label": "",
248+
"initiator": "loop-cli",
249+
"payment_timeout_seconds": 60
250+
}
251+
```
252+
We see in the client log that the swap instantly succeeds:
253+
```shell
254+
[INF] LOOPD: Loop in quote request received
255+
[INF] LOOPD: Static loop-in request received
256+
[INF] SADDR: StaticAddr loop-in 0000000000000000000000000000000000000000000000000000000000000000: Current: InitHtlcTx
257+
[DBG] SADDR: Deposit 5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f:0: NextState: LoopingIn, PreviousState: Deposited, Event: OnLoopInInitiated
258+
[INF] SADDR: StaticAddr loop-in 43ed16958d5a5bf0e6cb9a36eefb1493f39741238f06d6c7b5365c1c5c22d29e: Current: SignHtlcTx
259+
[INF] SADDR: StaticAddr loop-in 43ed16958d5a5bf0e6cb9a36eefb1493f39741238f06d6c7b5365c1c5c22d29e: Current: MonitorInvoiceAndHtlcTx
260+
[DBG] SADDR: StaticAddr loop-in 43ed16958d5a5bf0e6cb9a36eefb1493f39741238f06d6c7b5365c1c5c22d29e: received off-chain payment update Settled
261+
[INF] SADDR: StaticAddr loop-in 43ed16958d5a5bf0e6cb9a36eefb1493f39741238f06d6c7b5365c1c5c22d29e: Current: PaymentReceived
262+
[DBG] SADDR: Deposit 5405e5cae38f9e4e193f7b5442dd005273e2e1fab8687c42a505c1a333e8884f:0: NextState: LoopedIn, PreviousState: LoopingIn, Event: OnLoopedIn
263+
[INF] SADDR: StaticAddr loop-in 43ed16958d5a5bf0e6cb9a36eefb1493f39741238f06d6c7b5365c1c5c22d29e: Current: Succeeded
264+
```
265+
We can combine the remaining two deposits in another instant swap by specifying
266+
the `--all` flag:
267+
```shell
268+
./regtest.sh loop static in --all  ✔  12:07:28
269+
On-chain fees for static address loop-ins are not included.
270+
They were already paid when the deposits were created.
271+
272+
Previously deposited on-chain: 500000 sat
273+
Receive off-chain: 499302 sat
274+
Estimated total fee: 698 sat
275+
276+
CONTINUE SWAP? (y/n): y
277+
{
278+
"swap_hash": "950a4c0017831dc9934e93faacde1819ed5801d1c7abf6b555dc36908a3b3ca8",
279+
"state": "SignHtlcTx",
280+
"amount": "500000",
281+
"htlc_cltv": 431,
282+
"quoted_swap_fee_satoshis": "698",
283+
"max_swap_fee_satoshis": "698",
284+
"initiation_height": 131,
285+
"protocol_version": "V0",
286+
"label": "",
287+
"initiator": "loop-cli",
288+
"payment_timeout_seconds": 60
289+
}
290+
```
291+
For more information on the static address loop-in feature, see the
292+
https://docs.lightning.engineering/lightning-network-tools/loop/static-loop-in-addresses
293+
148294
# Using the Loop server in an existing setup
149295
150296
This `docker-compose` is only meant as a demo and quick start help. You can of

regtest/docker-compose.yml

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
- bitcoind:/home/bitcoin/.bitcoin
3131

3232
lndserver:
33-
image: lightninglabs/lnd:v0.17.0-beta
33+
image: lightninglabs/lnd:v0.18.5-beta
3434
container_name: lndserver
3535
restart: unless-stopped
3636
networks:
@@ -68,6 +68,7 @@ services:
6868
- loopserver
6969
volumes:
7070
- "lndserver:/root/.lnd"
71+
- "loopserver:/root/loopserver"
7172
depends_on:
7273
- lndserver
7374
command:
@@ -82,8 +83,34 @@ services:
8283
- "--bitcoin.zmqpubrawblock=tcp://bitcoind:28332"
8384
- "--bitcoin.zmqpubrawtx=tcp://bitcoind:28333"
8485

86+
aperture:
87+
build:
88+
context: https://github.com/lightninglabs/aperture.git
89+
dockerfile: Dockerfile
90+
args:
91+
checkout: v0.3.8-beta
92+
container_name: aperture
93+
restart: unless-stopped
94+
depends_on:
95+
- loopserver
96+
- etcd
97+
networks:
98+
regtest:
99+
aliases:
100+
- aperture
101+
volumes:
102+
- "lndserver:/root/.lnd"
103+
- "loopserver:/root/loopserver"
104+
- "aperture:/root/.aperture"
105+
ports:
106+
- "11018:11018"
107+
entrypoint: [ "/bin/aperture" ]
108+
command:
109+
- "--configfile=/root/.aperture/aperture.yaml"
110+
111+
85112
lndclient:
86-
image: lightninglabs/lnd:v0.17.0-beta
113+
image: lightninglabs/lnd:v0.18.5-beta
87114
container_name: lndclient
88115
restart: unless-stopped
89116
networks:
@@ -124,22 +151,44 @@ services:
124151
- loopclient
125152
volumes:
126153
- "lndclient:/root/.lnd"
154+
- "aperture:/root/.aperture"
155+
- "loopclient:/root/.loop"
127156
depends_on:
128-
- lndclient
157+
- aperture
129158
command:
130159
- "loopd"
160+
- "--experimental"
131161
- "--network=regtest"
132162
- "--debuglevel=debug"
133-
- "--server.host=loopserver:11009"
134-
- "--server.notls"
163+
- "--server.host=aperture:11018"
164+
- "--server.tlspath=/root/.loop/aperture-tls.cert"
135165
- "--lnd.host=lndclient:10009"
136166
- "--lnd.macaroonpath=/root/.lnd/data/chain/bitcoin/regtest/admin.macaroon"
137167
- "--lnd.tlspath=/root/.lnd/tls.cert"
138168

169+
etcd:
170+
image: bitnami/etcd:3.3.12
171+
platform: linux/amd64
172+
container_name: etcd
173+
hostname: etcd
174+
networks:
175+
regtest:
176+
aliases:
177+
- etcd
178+
restart: unless-stopped
179+
ports:
180+
- "2379:2379"
181+
- "2380:2380"
182+
environment:
183+
- ALLOW_NONE_AUTHENTICATION=yes
184+
139185
networks:
140186
regtest:
141187

142188
volumes:
143189
bitcoind:
144190
lndserver:
145191
lndclient:
192+
loopserver:
193+
loopclient:
194+
aperture:

regtest/regtest.sh

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ function setup() {
7777

7878
lndclient openchannel --node_key $LNDSERVER --local_amt 16000000
7979
mine 6
80+
81+
docker cp aperture:/root/.aperture/tls.cert /tmp/aperture-tls.cert
82+
chmod 644 /tmp/aperture-tls.cert
83+
docker cp -a /tmp/aperture-tls.cert loopclient:/root/.loop/aperture-tls.cert
84+
8085
}
8186

8287
function stop() {
@@ -111,7 +116,6 @@ function copy_loopserver_files() {
111116
chmod 644 /tmp/loopserver-admin.macaroon
112117
docker cp -a /tmp/loopserver-admin.macaroon loopserver:/home/loopserver/admin.macaroon
113118

114-
115119
# copy invoices macaroon to loopserver
116120
docker cp lndserver:/root/.lnd/data/chain/bitcoin/regtest/invoices.macaroon /tmp/loopserver-invoices.macaroon
117121
chmod 644 /tmp/loopserver-invoices.macaroon
@@ -137,8 +141,58 @@ function copy_loopserver_files() {
137141
chmod 644 /tmp/loopserver-walletkit.macaroon
138142
docker cp -a /tmp/loopserver-walletkit.macaroon loopserver:/home/loopserver/walletkit.macaroon
139143

144+
docker cp loopserver:/home/loopserver/tls.cert /tmp/loopserver-tls.cert
145+
chmod 644 /tmp/loopserver-tls.cert
146+
docker cp -a /tmp/loopserver-tls.cert aperture:/root/.aperture/loopserver-tls.cert
147+
148+
# create the aperture config and copy it to the aperture container.
149+
write_aperture_config
150+
151+
docker cp /tmp/aperture.yaml aperture:/root/.aperture/aperture.yaml
140152
}
141153

154+
155+
function write_aperture_config() {
156+
rm -rf /tmp/aperture.yaml
157+
touch /tmp/aperture.yaml && cat > /tmp/aperture.yaml <<EOF
158+
listenaddr: '0.0.0.0:11018'
159+
staticroot: '/root/.aperture/static'
160+
servestatic: true
161+
debuglevel: trace
162+
insecure: false
163+
writetimeout: 0s
164+
165+
servername: aperture
166+
autocert: false
167+
168+
authenticator:
169+
lndhost: lndserver:10009
170+
tlspath: /root/.lnd/tls.cert
171+
macdir: /root/.lnd/data/chain/bitcoin/regtest
172+
network: regtest
173+
174+
etcd:
175+
host: 'etcd:2379'
176+
user:
177+
password:
178+
179+
services:
180+
- name: loop
181+
hostregexp: '^.*$'
182+
pathregexp: '^/looprpc.*$'
183+
address: 'loopserver:11009'
184+
protocol: https
185+
tlscertpath: /root/.aperture/loopserver-tls.cert
186+
price: 1000
187+
authwhitelistpaths:
188+
- '^/looprpc.SwapServer/LoopOutTerms.*$'
189+
- '^/looprpc.SwapServer/LoopOutQuote.*$'
190+
- '^/looprpc.SwapServer/LoopInTerms.*$'
191+
- '^/looprpc.SwapServer/LoopInQuote.*$'
192+
EOF
193+
}
194+
195+
142196
if [[ $# -lt 1 ]]; then
143197
echo "Usage: $0 start|stop|restart|info|loop"
144198
fi

0 commit comments

Comments
 (0)