Phoenix for server

uenohiro4
Nayuta エンジニアブログ
12 min readMar 30, 2024
https://phoenix.acinq.co/server

今回は Phoenix for serverの紹介をします。

PhoenixといえばACINQさんがリリースしているLightningモバイルウォレットアプリです。Phoenix for server はそれが Linux, MacOS, Windows(WSL)で動作するサーバー版アプリです。サーバー版なのでGUI画面はありません。

ACINQさんといえば Eclair です。あちらは何でもできるフルノードで、Phoenix for server はその簡易版という位置づけだと思います(FAQ)。ノード運用というよりはウォレットとして使うアプリでしょう。

モバイルアプリだと常時動かしているという感じにはならないです。かといって PC に Lightning のフルノードを立てるのはなかなか大変です。 lnd.conf を見たことがある人はわかるでしょうが、パラメータが多いし、そもそもそのパラメータが何を意味するのか、デフォルトで良いのかどうかすら判断が難しいと思います。
Phoenix for server はほぼモバイルの Phoenix と同等なので、設定はそんなに多くないですしチャネルの運用も Phoenix と同じように LSP 任せになります。
初めての場合は Phoenix for server でやってみて、物足りなくなったらフルノードに挑戦する、みたいな使い方もできるでしょう。

個人の感想はここまでにして実際に動かしてみましょう。今回は Linux 版 v0.1.3 を Ubuntu 22.04 で動かします。

バイナリでの配布もされています。これを書いている時点では v0.1.3 でした。動かすのは非常に簡単で、このバイナリをダウンロードしてコマンドラインから実行するだけです。Linux 用と MacOS 用のバイナリが配布されています。Windows の場合は WSL を立ち上げて Linux 用をダウンロードします。

$ wget https://github.com/ACINQ/phoenixd/releases/download/v0.1.3/phoenix-0.1.3-linux-x64.zip
$ unzip phoenix-0.1.3-linux-x64.zip
$ ls phoenix-0.1.3-linux-x64
phoenix-cli phoenixd

bitcoindbitcoin-cli のようなものです。一応説明すると phoenixd は dameon 版(常駐するようなサーバーアプリ。”守護神”。)と、 phoenix-cliはそれにアクセスするクライアントアプリです。

ヘルプの出力も見ておきましょう。

$ ./phoenixd --help
Usage: phoenixd [<options>]

Liquidity Options:
--auto-liquidity=(off|2m|5m|10m) Amount automatically requested when inbound liquidity is needed (default:
2m)
--max-absolute-fee=<int> Max absolute fee for on-chain operations. Includes mining fee and service
fee for auto-liquidity. (default: 2% of auto-liquidity amount)
--max-fee-credit=(off|50k|100k) Max fee credit, if reached payments will be rejected. (default: 100k)

Options:
--chain=(mainnet|testnet) Bitcoin chain to use (default: mainnet)
--mempool-space-url=<value> Custom mempool.space instance
--http-bind-ip=<text> Bind ip for the http api (default: 127.0.0.1)
--http-bind-port=<int> Bind port for the http api (default: 9740)
--http-password=<text> Password for the http api
--webhook=<value> Webhook http endpoint for push notifications (alternative to websocket)
--silent, --verbose Verbosity level (default: prints high-level info to the console)
-v, --version Show the version and exit
-h, --help Show this message and exit
$ ./phoenix-cli --help
Usage: phoenix-cli [<options>] <command> [<args>]...

Options:
--http-bind-ip=<text> Bind ip for the http api (default: 127.0.0.1)
--http-bind-port=<int> Bind port for the http api (default: 9740)
--http-password=<text> Password for the http api (default: reads from /home/ueno/.phoenix/phoenix.conf)
-v, --version Show the version and exit
-h, --help Show this message and exit

Commands:
getinfo Show basic info about your node
getbalance Returns your current balance
listchannels List all channels
getoutgoingpayment Get outgoing payment
getincomingpayment Get incoming payment
listincomingpayments List incoming payments matching the given externalId
createinvoice Create a Lightning invoice
payinvoice Pay a Lightning invoice
sendtoaddress Send to a Bitcoin address
closechannel Close channel

今回は testnet で動かします。
初回なのでキーボードからの入力を求められていますが、一度立ち上げておくと次回以降は実行するだけで起動します。

$ ./phoenixd --chain=testnet
Generating new seed...done
Generating default api password...done
Backup
This software is self-custodial, you have full control and responsibility over your funds.
Your 12-words seed is located in /home/xxx/.phoenix, make sure to do a backup or you risk losing your funds.
Do not share the same seed with other phoenix instances (mobile or server), it will cause issues and channel force closes.

Please confirm by typing [I understand]: I understand

Continuous liquidity
Liquidity management is fully automated.
When receiving a Lightning payment that doesn't fit in your existing channel:
- If the payment amount is large enough to cover mining fees and service fees for automated liquidity, then your channel will be created or enlarged right away.
- If the payment is too small, then the full amount is added to your fee credit, and will be used later to pay for future fees. The fee credit is non-refundable.

Please confirm by typing [I understand]: I understand

Phoenix server is about to start, use phoenix-cli or the http api to interact with the daemon. This message will not be displayed next time.
Press any key to continue...

2024-03-30 07:45:02 datadir: /home/xxx/.phoenix
2024-03-30 07:45:02 chain: Testnet
2024-03-30 07:45:02 autoLiquidity: 2000000 sat
2024-03-30 07:45:02 nodeid: 03e678e692d0e0ea8c1aaf0695544cec6efa52213845328f027b06960b7fcc76e4
2024-03-30 07:45:02 connecting to lightning peer...
2024-03-30 07:45:02 connected to lightning peer
2024-03-30 07:45:02 listening on http://127.0.0.1:9740

$HOME/.phoenix/ の中にいくつかファイルが作られました。SQLite ですかね。

このままだとノードが立ち上がっただけなので、モバイルウォレットと同じようにチャネルを作ってもらわないと使えません。 Get Started からすると、 createinvoice でしょうか。

$ ./phoenix-cli createinvoice --help
Usage: phoenix-cli createinvoice [<options>]

Create a Lightning invoice

Options:
--amountSat=<int>
--description, --desc=<text>
--externalId=<text>
-h, --help Show this message and exit


$ ./phoenix-cli createinvoice --amountSat=1000 --desc="welcome"
{
"amountSat": 1000,
"paymentHash": "8ae959b42.....5c3b6c3a741cd4ce1",
"serialized": "lntb10u1pnq03dvpp....7j0upsq4nnddp"
}

別の testnet ノードから送金してみると成功しました。金額は 1,000 sats でした。では残高を見てみましょう。

$ ./phoenix-cli listchannels
[
]

$ ./phoenix-cli getbalance
{
"balanceSat": 0,
"feeCreditSat": 1000
}

チャネルは作られず、balance にも入っていないですが feeCredit に送金された金額が入りました。

これについては Auto Liquidity というページがありました。
チャネルを作るにしては受け取る金額が小さすぎる場合、LSP は受け取りを拒否するのではなく「将来 feeとして使う予定の額」として取っておくということですかね。
受取側のシナリオは3パターン「受け取ってそのまま残高に入る」「inbound liquidity 購入のために使われる」「後の inbound liquidity 購入用に確保される」です。

では、この fee credit のお金から送金できるのでしょうか? 外部で 500 sats の invoice を作り payinvoice で送金してみました。

$ ./phoenix-cli payinvoice --invoice=lntb5u1pnq0j49p......hsp5zv6q4
{
"paymentHash": "7d2014d......4bf7984",
"reason": "no channels available to send payment"
}

ダメらしい。

最初は「なんで!」と思ったのだが、「それが嫌なら手数料を払ってチャネルを先に作ってくれ」ということだから、結果としてはあまり変わらない気もします。
ならば送金を受け取らずに失敗させればよいのかもしれないですが、チャネルを作らないと使えない=そのうちチャネルは作るはず、と思えば失敗させなくてもよいという考え方もあるかもしれません。少なくとも送金側は Phoenix の LSP まで届けば送金失敗にならないから変な心配はいりませんね。

Lightning Network は Bitcoin と違って送金に失敗するという状況が発生するので、それを減らすためにはこういった割り切りが必要なのでしょう。

まだじっくりとは触っていませんが、なかなか面白いと思いました。

--

--