Skip to content

Instantly share code, notes, and snippets.

@sputn1ck
Created November 24, 2021 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sputn1ck/bc42ea1af219ed15fd54abc88ec4728c to your computer and use it in GitHub Desktop.
Save sputn1ck/bc42ea1af219ed15fd54abc88ec4728c to your computer and use it in GitHub Desktop.
preperation guide for peerswap signet

Signet Guide

This guide walks through the steps necessary to run the peerswap plugin on bitcoin signet and liquid testnet. This guide was written and tested under Ubuntu-20.04 but the same procedure also applies to different linux distributions.

Install dependencies

Peerswap requires clightning, bitcoind and if the liquid testnet should be used also an elementsd installation. If you already have all of these installed you can let them run in signet, or testnet mode and skip to the section about using the plugin.

Bitcoind (signet)

Download the following files to install bitcoin-core.

wget https://bitcoin.org/bin/bitcoin-core-0.21.1/bitcoin-0.21.1-x86_64-linux-gnu.tar.gz && \
wget https://bitcoin.org/bin/bitcoin-core-0.21.1/SHA256SUMS.asc && \
wget https://bitcoin.org/laanwj-releases.asc

Verify the downloaded data

gpg --import laanwj-releases.asc && \
gpg --verify SHA256SUMS.asc && \
sha256sum -c SHA256SUMS.asc 2>&1 | grep bitcoin-0.21.1-x86_64-linux-gnu.tar.gz

If the shasums match this command will return

bitcoin-0.21.1-x86_64-linux-gnu.tar.gz: OK

Extract the binaries

tar -zvxf bitcoin-0.21.1-x86_64-linux-gnu.tar.gz

Copy the binaries to the system path

sudo cp -vnR bitcoin-0.21.1/* /usr/

Start the bitoin daemon in signet mode

bitcoind --signet --daemon

Liquid Testnet(optional)

Download the following files to install elementsd.

wget https://github.com/ElementsProject/elements/releases/download/elements-0.21.0/elements-elements-0.21.0-x86_64-linux-gnu.tar.gz && \
wget -O ELEMENTS-SHA256SUMS.asc https://github.com/ElementsProject/elements/releases/download/elements-0.21.0/SHA256SUMS.asc

Verify the downloaded data

gpg --keyserver hkps://keyserver.ubuntu.com --recv-key "DE10E82629A8CAD55B700B972F2A88D7F8D68E87" && \
gpg --verify ELEMENTS-SHA256SUMS.asc && \
sha256sum -c ELEMENTS-SHA256SUMS.asc 2>&1 | grep OK

If the shasums match this command will return

elements-elements-0.21.0-x86_64-linux-gnu.tar.gz: OK

Extract the binaries

tar -zvxf elements-elements-0.21.0-x86_64-linux-gnu.tar.gz

Copy the binaries to the system path

sudo cp -vnR elements-elements-0.21.0/* /usr/

Create config dir in home

mkdir -p ~/.elements

Add testnet config file (avoid to override existing config files)

cat <<EOF > ~/.elements/elements.conf
chain=liquidtestnet
# Liquid Testnet (liquidtestnet) settings:
[liquidtestnet]

# General settings:
listen=1
txindex=1
validatepegin=0
anyonecanspendaremine=0
initialfreecoins=2100000000000000
con_dyna_deploy_start=0
con_max_block_sig_size=150
checkblockindex=0 
addnode=liquid-testnet.blockstream.com:18892
addnode=liquidtestnet.com:18891
fallbackfee=0.00000100
daemon=1
con_has_parent_chain=0
parentgenesisblockhash=NULL
pubkeyprefix=36
scriptprefix=19
blindedprefix=23
bech32_hrp=tex
blech32_hrp=tlq
pchmessagestart=410edd62
dynamic_epoch_length=1000
signblockscript=51210217e403ddb181872c32a0cd468c710040b2f53d8cac69f18dad07985ee37e9a7151ae

rpcport=18884
rpcuser=admin1
rpcpassword=123
rpcbind=127.0.0.1
addnode=95.217.184.148:18444
EOF

Start the daemon in testnet node

elementsd --daemon

Wait for sync

The elements node now has to be synced on liquid testnet for the plugin to work. To check this, compare the height value from

elements-cli getchaintips

with the height of the last block on liquid-testnet-explorer

C-lightning

Download the necessary files.

wget https://github.com/ElementsProject/lightning/releases/download/v0.10.2/clightning-v0.10.2-Ubuntu-20.04.tar.xz && \
wget -O LIGHTNING-SHA256SUMS.asc https://github.com/ElementsProject/lightning/releases/download/v0.10.2/SHA256SUMS.asc && \
wget https://github.com/ElementsProject/lightning/releases/download/v0.10.2/SHA256SUMS

Verify the downloaded data

gpg --keyserver hkps://keyserver.ubuntu.com --recv-key "30DE693AE0DE9E37B3E7EB6BBFF0F67810C1EED1" && \
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key "15EE8D6CAB0E7F0CF999BFCBD9200E6CD1ADB8F1" && \
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key "B7C4BE81184FC203D52C35C51416D83DC4F0E86D" && \
gpg --verify LIGHTNING-SHA256SUMS.asc SHA256SUMS && \
sha256sum -c SHA256SUMS 2>&1 | grep clightning-v0.10.2-Ubuntu-20.04.tar.xz

If the shasums match this command will return

clightning-v0.10.2-Ubuntu-20.04.tar.xz: OK

Install dependencies

sudo apt update && \
sudo apt install -y autoconf automake build-essential git libtool libgmp-dev libsqlite3-dev python3 python3-mako net-tools zlib1g-dev libsodium-dev gettext libpq5

Extract the binaries

tar -vxf clightning-v0.10.2-Ubuntu-20.04.tar.xz

Copy the binaries to the system path

sudo cp -vnR usr/* /usr/

Create config dir in home

mkdir -p ~/.lightning

Add signet config file

cat <<EOF > ~/.lightning/config
signet
bitcoin-datadir=$HOME/.bitcoin
addr=0.0.0.0:39375
log-level=debug
log-file=$HOME/.lightning/log
EOF

Peerswap

Build

Install golang from https://golang.org/doc/install

wget https://go.dev/dl/go1.17.3.linux-amd64.tar.gz && \
sudo rm -rf /usr/local/go && \
sudo tar -C /usr/local -xzf go1.17.3.linux-amd64.tar.gz && \
export PATH=$PATH:/usr/local/go/bin

Clone into the peerswap repository and build the peerswap plugin

git clone git@github.com:sputn1ck/peerswap.git && \
cd peerswap && \
make release

Policy

To ensure that only trusted nodes can send a peerswap request to your node it is necessary to create a policy in the lightning config dir (~/lightning/policy.conf) file in which the trusted nodes are specified. Change the following to your needs, replacing the <trusted node> flag. For Signet testing we add accept_all_peers=1

cat <<EOF > ~/.lightning/policy.conf
accept_all_peers=1
EOF

Cleanup

Remove all unneccessary files and folders

rm go1.17.3.linux-amd64.tar.gz && \
rm clightning-v0.10.2-Ubuntu-20.04.tar.xz && \
rm -r usr/ && \
rm LIGHTNING-SHA256SUMS.asc && \
rm SHA256SUMS && \
rm -r bitcoin-0.21.1/ && \
rm -r elements-elements-0.21.0/ && \
rm bitcoin-0.21.1-x86_64-linux-gnu.tar.gz && \
rm elements-elements-0.21.0-x86_64-linux-gnu.tar.gz && \
rm ELEMENTS-SHA256SUMS.asc && \
rm laanwj-releases.asc && \
rm SHA256SUMS.asc

Run

start the c-lightning daemon with the following config flags for bitcoin only:

lightningd --daemon \
        --plugin=$HOME/peerswap/peerswap \
        --peerswap-policy-path=$HOME/.lightning/policy.conf

Or with liquid enabled

lightningd --daemon \
        --plugin=$HOME/peerswap/peerswap \
        --peerswap-liquid-rpchost=http://localhost \
        --peerswap-liquid-rpcport=18884 \
        --peerswap-liquid-rpcuser=admin1 \
        --peerswap-liquid-rpcpassword=123 \
        --peerswap-liquid-network=testnet \
        --peerswap-liquid-rpcwallet=swap \
        --peerswap-policy-path=$HOME/.lightning/policy.conf

Create a new signet address and receive some sats from https://signet.bc-2.jp/

lightning-cli newaddr

Now connect to another node that has the peerswap plugin running, for example a development node run by @sputn1ck

lightning-cli connect 02d5ee248489d76b54015df2938318a58ee0e35e4746579bd170efc7f1dd62e799@95.217.184.148:39375

Fund a channel to the connected peer, e.g. @sputn1ck node (replace the nodes pubkey and amount to your needs)

lightning-cli fundchannel 02d5ee248489d76b54015df2938318a58ee0e35e4746579bd170efc7f1dd62e799 [amt] 

Get a new liquid address and then generate some lbtc to the address via https://liquidtestnet.com/faucet

lightning-cli peerswap-liquid-getaddress

After the channel has been funded and is in CHANNELD_NORMAL state get the short channel id per

lightning-cli listfunds | grep short_channel_id

and try a swap-out

lightning-cli peerswap-swap-out [amt] [short_channel_id] l-btc

Note: The asset could also be btc. This will perform the swap on the bitcoin signet rather than the liquid testnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment