Get-PSLndExplorer v0.5.8

PowerShell Core script used for invoking Bitcoin Lightning Node Deamon (LND) commands

Overview

A PowerShell Core script for executing a subset of lncli commands This script should be functional on either Windows, Linux, or MacOS operating systems or where ever PowerShell Core is supported.

Testing has only been done on Linux (POP!_OS) system at this time with Lightning Node Deamon (LND) installed. Logic is coded and tested in the script to be functional on a docker BTCPayServer instance with LND.

Get-Help 👇

PS> Get-Help Get-PSLndExplorer

PS> Get-Help Get-PSLndExplorer -full

NAME: /home/cadayton/ps/Get-PSLndExplorer.ps1

SYNOPSIS: PowerShell script for executing a subset of lncli commands

SYNTAX

Get-PSLndExplorer.ps1 [[-lightningnodes] ] [[-lndcmd] ] [[-sats] ] [[-options] ] [[-new]] [[-chanInfo] ] [[-display]]

PowerShell script for executing lncli getnodeinfo or queryroutes. Script will work for stand alone LND implemenations or for BTCPayServer LND implemenations. For BTCPayServer implementation, the script will need to be copied to the btcpayserver-docker directory.

Inputs and Outputs

The input file, $PSScriptroot/LndNodes.xml is optional. If the getnodeinfo command is used for a common set of nodes, then create this xml file to avoid specifying the node aliases and/or pub keys on each execution.

The output file, $PSScriptroot/lndgraph.xml is created on initial execution and is an PowerShell object version of the describegraph dataset. On subsequent executions the output file will be used as input.

XML Schema for LndNodes.xml 👇

            <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
            <LndNodes>
              <node alias="BOW_UBETCHA">
                <pubkey>03613d24e4636baa2a1ebb2c750645edf0510e868f91a9560a6c05272840cf64b7</pubkey>
              </node>
              <node alias="SANJOSE_UBETCHA">
                <pubkey>03f576c4fe7ec82a459dbc194b33b55f4e9a606442f69364a90e18f7bea9e4b414</pubkey>
              </node>
              <node alias="TORONTO_UBETCHA">
                <pubkey>03adc0f4e8ff33ca9e8d6d480a3de35c7245159ddcd47d2d7639bc40ed64480062</pubkey>
              </node>
            </LndNodes>
          

Example getnodeinfo

PS> Get-PSLndExplorer SANJOSE_UBETCHA getnodeinfo -ch 1 -dp

-ch 1 minimual channel info it takes a value of 1 or 2

-dp option displays the data rather returning an object

Command output 👇

            Executing: Get-PSLndExplorer SANJOSE_UBETCHA getnodeinfo -ch 1 -dp
            Use the switch -new to get a current dataset
            Loaded 18772 Nodes containing 83086 Payment Channels at 01-21-2023 05:01
            Getting the details for 4 channels
        
            Alias           PubKey      Last_Update      Channels Capacity
            -----           ------      -----------      -------- --------
            SANJOSE_UBETCHA 03f576c4fe7 01-24-2023 22:01        9 0.04348 BTC
        
        
            Capacity Node1              Node1_TLFeeRate Node2           Node2_TLFeeRate
            -------- -----              --------------- -----           ---------------
                      
            595000   BOW_UBETCHA        40|491|1        SANJOSE_UBETCHA 40|491|1
            595000   BOW_UBETCHA        40|491|1        SANJOSE_UBETCHA 40|491|1
            595000   TORONTO_UBETCHA    40|491|1        SANJOSE_UBETCHA 40|491|1
            595000   TORONTO_UBETCHA    40|491|1        SANJOSE_UBETCHA 40|491|1
          

Example queryroutes

PS> Get-PSLndExplorer "River Financial 2" queryroutes 500 -dp

Test the routing of a 500 sats payment to a given node

Command output 👇

            Executing:  Get-PSLndExplorer "River Financial 2" queryroutes 500 -dp
            Use the switch -new to get a current dataset
            Loaded 18772 Nodes containing 83086 Payment Channels at 01-21-2023 05:01
            Executing: lncli queryroutes --dest 03aab7e9327716ee946b8fbfae039b0db85356549e72c5cca113ea67893d0821e5 --amt 500
                                                                                                                                    
                                    Summary of Route Query
        
            hops total_amt total_fees total_amt_msat total_fees_msat success_prob
            ---- --------- ---------- -------------- --------------- ------------
              4  500       0          500050         50                     0.205
        
        
            Alias             chan_id            forward_amt fee forward_msat fee_msat
            -----             -------            ----------- --- ------------ --------
            Kraken 🐙⚡        848642656794836993 500         0   500000       50
            Morphy            803372464550182912 500         0   500000       0
            Boltz             822519360068059136 500         0   500000       0
            River Financial 2 829098837695201280 500         0   500000       0
          

Example executing 3 commands sequently GetInfo,WTClient information, SCB

PS> Get-PSLndExplorer -lndcmd getinfo,WTInfo,SCB -dpx

Returns getinfo and wtclient towers details

Command output 👇

            PS> ./Get-PSLndExplorer.ps1 -lndcmd getinfo,WTInfo,SCB -dpx

            Executing: docker exec btcpayserver_lnd_bitcoin lncli --macaroonpath /root/.lnd/admin.macaroon getinfo
            
            Chain   Network  Block Block TS   ChainSync GraphSync Active InActive Pending Peers
            -----   -------  ----- --------   --------- --------- ------ -------- ------- -----
            bitcoin mainnet 774372 1675107443      True      True      8        0       0     6
            
            Executing: docker exec btcpayserver_lnd_bitcoin lncli --macaroonpath /root/.lnd/admin.macaroon wtclient towers --include_sessions
            
            Tower       Active Session Backups Pending  MAX sats/byte sats/vbyte
            -----       ------ ------- ------- -------  --- --------- ----------
            0214276d60e   True       0      82       0 1024        10         10
            0214276d60e   True       1      39       0 1024        10         10

            The 'SCB' command will determine if the Static Channel Backup (SCB) file needs to be updated
            based on if any new forwarding events have happened since the last execution.

            When the SCB file is updated locally a remote copy of the file is created
            using PowerShell ssh remoting feature.

            channel-all.bak last updated 02-02-2023 00:02
          

Example performing a Static Channel Backup (SCB)

PS> Get-PSLndExplorer.ps1 -lndcmd scb -dp

Creates on offsite Static Channel Backup (SCB).

Starting with v0.5.7, a file named SCBbackups.xml must exist in the btcpayserver-docker directory to define attributes associated with performing a Static Channel Backup (SBC).

Command output 👇


            SCBbackups.xml schema
              <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
              <SCBbackups>
                <SCBbackup hostname="newyork-btcpay">
                  <dstFile>channel-newyork.bak</dstFile>
                  <dstPath>/root/backup/</dstPath>
                  <scpFile>/home/username/backup/channel-newyork.bak</scpFile>
                  <scpHost>155.155.155.121</scpHost>
                  <lnAlias>NEWYORK_BTCPAY</lnAlias>
                  <kfFile>/root/.ssh/newyork-btcpay.key</kfFile>
                  <urName>username</urName>
                </SCBbackup>
                <SCBbackup hostname="texas-btcpay">
                  <dstFile>channel-texas.bak</dstFile>
                  <dstPath>/root/backup/</dstPath>
                  <scpFile>/home/username/backup/channel-texas.bak</scpFile>
                  <scpHost>172.172.172.99</scpHost>
                  <lnAlias>TEXAS_BTCPAY</lnAlias>
                  <kfFile>/root/.ssh/id_rsa</kfFile>
                  <urName>username</urName>
                </SCBbackup>
              </SCBbackups>
      
            One needs at least two functional LND nodes that are under your management control.
        
            When the SCB backup process is started, it will determine the last time it executed and calculate
            the date differences from the current date.  Based on the date difference, the forwarding history will
            be examined to determine if there are any new forwarding events in that time frame.
        
            If there are new forwarding events, the command 'lnd exportchanbackup -all' is executed and saved in a 
            file name referenced in <dstFile> in BTCPayServer's default directory location.
        
            Next <dstFile> is copied from it's default location to the path in <dstPath>.
        
            Lastly, scp is performed to copy the <dstPath> file to the <scpFile> on the remote server <scpHost>.

          

Example get the forwarding history

PS> Get-PSLndExplorer.ps1 -lndcmd fwdhist -dp

Since the -dp option is specified output goes to the console otherwise an object is returned

Command output 👇

            PS> ./Get-PSLndExplorer.ps1 -lndcmd fwdhist -dp

            Run Forwarding History Report? [Y or N] Y
            Enter Start Time for the report [1d, 1w, or (4w)] 14d

            TimeStamp        Channel_in Amount_in Amt_in_msat Channel_out Amount_out Amt_out_msat fee fee_msat
            ---------        ---------- --------- ----------- ----------- ---------- ------------ --- --------
            02-04-2023 11:02 8486426    50008     50008532    8478202     50003      50008532     5   5491
            01-30-2023 12:01 8478202    200020    200020691   8486426     200020     200020691    0   691
            01-30-2023 12:01 8484766    200020    200020691   8486426     200020     200020691    0   691
            01-30-2023 12:01 8478202    50005     50005541    8486426     50005      50005541     0   541

            The default start time is the past 4 weeks (4w) unless overridden by the command prompt.

          

Example display channel balance report

PS> Get-PSLndExplorer.ps1 -lndcmd ChBal -dp

Since the -dp option is specified output goes to the console otherwise an object is returned

Command output 👇

            PS> ./Get-PSLndExplorer.ps1 -lndcmd ChBal -dp

            Executing: Get-PSLndExplorer.ps1 -lndcmd ChBal -dpx

            InOutBalance InBound   OutBound  PendingOpen PendingIn PendingOut UnsettleIn UnsettleOut
            ------------ -------   --------  ----------- --------- ---------- ---------- -----------
            3,362,649    1,183,046 2,179,603           0         0          0          0           0
          

Example display Payment Channels report

PS> Get-PSLndExplorer.ps1 -lndcmd PayCh -dp

Since the -dp option is specified output goes to the console otherwise an object is returned

Command output 👇

            Executing: Get-PSLndExplorer.ps1 -lndcmd PayCh -dp

            Node            Active Capacity  RemBalance(In) LocBalance(Out) Sent      Received HTLCs Fee  Weight
            ----            ------ --------  -------------- --------------- ----      -------- ----- ---  ------
            Kraken            True 1,000,000 911,187        85,342          1,100,142 188,954      0 2811 1116
            MyNode1           True 595,000   0              591,530         0         0            0 3140 772
            MyNode1           True 595,000   91,475         500,054         50,003    550,058      0 2811 1116
            MyNode2           True 595,000   0              591,530         0         0            0 3140 772
            MyNode2           True 595,000   180,384        411,145         138,945   550,090      0 2811 1116
          

How to download this PowerShell script

Download References 👇

Paywall link

Donate sats with GetAlby

Donate $ with PayPal

After your donatation, Contact me (cadayton) using any of the following methods to coordinate getting these scripts.

Reach me on nostr

Reach me on Keybase