Close payment channels of lightning nodes running on regtest with CLN

LNROOM #6December 06, 2022

In this episode we see how to close channels on regtest with CLN using the command close. Specifically, we do 3 mutual closes and 1 unilateral close. This gives us the opportunity to show how to use the flags unilateraltimeout and destination of the command close.

Transcript with corrections and improvements

Hi guys, welcome to the LN Room, I'm Tony Aldon and today in this episode 6 we are going to close lightning channels using the sub-command close of CLN.

The plan is to close 4 channels like this:

  1. close channel cooperatively sending funds to the lightning wallet,

  2. close channel cooperatively sending funds to a Bitcoin wallet,

  3. close channel unilaterally,

  4. close channel cooperatively waiting reconnection of nodes.

The synopsis of the sub-command close is the following:

close id [unilateraltimeout] [destination] [...]

where

  • id (which is mandatory) can be either a peer ID, a channel ID or a short channel ID,

  • unilateraltimeout when is not zero forces the closing of the channel unilaterally when that number of seconds is reached, and when is zero waits indefinitely until the peer is online,

  • destination can be any Bitcoin bech32 type, when it is not specified, the default is a Core Lightning wallet address.

We don't mentioned the other optional arguments since we are not going to use them today.

Start 2 Lightning nodes running on regtest and connect them

As in the previous episode, we are in lightning repository and to start two Lightning nodes running on the Bitcoin regtest chain we source the script contrib/startup_regtest.sh and use the provided command start_ln:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ source contrib/startup_regtest.sh
lightning-cli is /usr/bin/lightning-cli
lightningd is /usr/bin/lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ start_ln 2
Bitcoin Core starting
awaiting bitcoind...
Making "default" bitcoind wallet.
[1] 22011
[2] 22043
Commands:
        l1-cli, l1-log,
        l2-cli, l2-log,
        bt-cli, stop_ln, fund_nodes

We can check that l1-cli is just an alias for lightning-cli with the base directory being /tmp/l1-regtest:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'

Then we connect the node l1 and l2 using the command connect (provided by the startup script) like this:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ connect 1 2
{
   "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
   "features": "08a000080269a2",
   "direction": "out",
   "address": {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7272
   }
}

Mutual close sending funds to the lightning wallet of the node l1

Now we fund the lightning wallet of l1 with 1btc and open a channel from l1 to l2 with 1000000sat using the handy command fund_nodes (provided by the startup script):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
Mining into address bcrt1qh8zpeudzs060pr7e7tmq52qadl8dusdaff049t... done.
bitcoind balance: 50.00000000
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.

As the channel has been announced, first we can see it listed using the sub-command listchannels like this:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": [
      {
         "source": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "destination": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "short_channel_id": "103x1x1",
         "public": false,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 0,
         "active": true,
         "last_update": 1670344947,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      },
      {
         "source": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "destination": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "short_channel_id": "103x1x1",
         "public": false,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 1,
         "active": true,
         "last_update": 1670344947,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      }
   ]
}

Now we can list the funds holds by the lightning wallet of the node l1 and also the funds locked in the channel 103x1x1 using the sub-command listfunds like this:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
         "output": 0,
         "amount_msat": 98999846000,
         "scriptpubkey": "00145e8461dc5f6bc508fbf800076e9a88eee2827da3",
         "address": "bcrt1qt6zxrhzld0zs37lcqqrkax5gam3gyldr2rd3da",
         "status": "confirmed",
         "blockheight": 103,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "103x1x1",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
         "funding_output": 1
      }
   ]
}

We can also have more information about the channel the node l1 opened with the node l2 using the sub-command listpeers.

For instance for the channel 103x1x1:

  • the attribute status contains the log of the last significant changes of the channel:

    CHANNELD_NORMAL:Funding transaction locked. Channel announced.
  • the array state_changes contains the list of the successive state changes of the channel:

    [
      {
        "timestamp": "2022-12-06T16:47:21.853Z",
        "old_state": "CHANNELD_AWAITING_LOCKIN",
        "new_state": "CHANNELD_NORMAL",
        "cause": "user",
        "message": "Lockin complete"
      }
    ]
  • and the attribute close_to_addr contains the bitcoin address bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl we will close to (unless we specify another one with the flag destination of the sub-command close of lightning-cli).

Here is the json object we get for the node l1 using listpeers:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "db618fb422bba89ef4c89318b6711024bccb8dd3a331f526c78f9d2ce35ad14f",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "channeld",
               "short_channel_id": "103x1x1",
               "direction": 1,
               "channel_id": "1fc3c4044329bc0357086ce35dd28516e04819dc0c71b54da63c293e0b7e131f",
               "funding_txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
               "close_to": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
               "private": false,
               "opener": "local",
               "alias": {
                  "local": "16496960x636393x30406",
                  "remote": "5307576x9553925x2900"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T16:47:21.853Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  }
               ],
               "status": [
                  "CHANNELD_NORMAL:Funding transaction locked. Channel announced."
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}

Now the node l1 initiate a mutual close of the channel 103x1x1 it has oppened with the node l2 running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli close 103x1x1
# Sending closing fee offer 138sat, with range 138sat-183sat
# Received closing fee offer 138sat, with range 138sat-1000000sat
{
   "tx": "02000000011fc3c4044329bc0357086ce35dd28516e04819dc0c71b54da63c293e0b7e131e0100000000ffffffff01b6410f0000000000160014a91d0f7cc612513dd7573efb85168c3e37ecd2af00000000",
   "txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
   "type": "mutual"
}

The transaction previously outputed 02000000011f...ecd2af00000000 has been sent to the mempool of the bitcoind instance running the regtest chain. Since no block including that transaction has been mined so far (remember that we manually manage the regtest chain), the channel still exist as we can see below:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": [
      {
         "source": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "destination": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "short_channel_id": "103x1x1",
         "public": true,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 2,
         "active": false,
         "last_update": 1670345458,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      },
      {
         "source": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "destination": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "short_channel_id": "103x1x1",
         "public": true,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 3,
         "active": false,
         "last_update": 1670345458,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      }
   ]
}

As we are doing a mutual close, we just have to mine one block on the regtest chain to close the channel:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default getnewaddress
bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
[
  "7a9cc18ae79fc995129806176a0d2d2d660b87642387815560cb40f5b1118161"
]

And we can check that the channel is no longer listed on the network by running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}

If we list the peers of the node l1 with the sub-command listpeers, we can see that the channel 103x1x1 is still listed:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": [
            {
               "state": "ONCHAIN",
               "scratch_txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
               "last_tx_fee_msat": 138000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "onchaind",
               "short_channel_id": "103x1x1",
               "direction": 1,
               "channel_id": "1fc3c4044329bc0357086ce35dd28516e04819dc0c71b54da63c293e0b7e131f",
               "funding_txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
               "close_to": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
               "private": false,
               "opener": "local",
               "closer": "local",
               "alias": {
                  "local": "16496960x636393x30406",
                  "remote": "5307576x9553925x2900"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T16:47:21.853Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  },
                  {
                     "timestamp": "2022-12-06T16:50:58.292Z",
                     "old_state": "CHANNELD_NORMAL",
                     "new_state": "CHANNELD_SHUTTING_DOWN",
                     "cause": "user",
                     "message": "User or plugin invoked close command"
                  },
                  {
                     "timestamp": "2022-12-06T16:50:58.646Z",
                     "old_state": "CHANNELD_SHUTTING_DOWN",
                     "new_state": "CLOSINGD_SIGEXCHANGE",
                     "cause": "user",
                     "message": "Start closingd"
                  },
                  {
                     "timestamp": "2022-12-06T16:50:58.875Z",
                     "old_state": "CLOSINGD_SIGEXCHANGE",
                     "new_state": "CLOSINGD_COMPLETE",
                     "cause": "user",
                     "message": "Closing complete"
                  },
                  {
                     "timestamp": "2022-12-06T16:53:21.823Z",
                     "old_state": "CLOSINGD_COMPLETE",
                     "new_state": "FUNDING_SPEND_SEEN",
                     "cause": "user",
                     "message": "Onchain funding spend"
                  },
                  {
                     "timestamp": "2022-12-06T16:53:21.874Z",
                     "old_state": "FUNDING_SPEND_SEEN",
                     "new_state": "ONCHAIN",
                     "cause": "user",
                     "message": "Onchain init reply"
                  }
               ],
               "status": [
                  "CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 138 satoshi for tx:12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
                  "ONCHAIN:Tracking mutual close transaction",
                  "ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel"
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}

On that outputed object, two informations are interesting to look at separatly:

  1. the list of the successive state changes of the channel:

    [
      {
        "timestamp": "2022-12-06T16:47:21.853Z",
        "old_state": "CHANNELD_AWAITING_LOCKIN",
        "new_state": "CHANNELD_NORMAL",
        "cause": "user",
        "message": "Lockin complete"
      },
      {
        "timestamp": "2022-12-06T16:50:58.292Z",
        "old_state": "CHANNELD_NORMAL",
        "new_state": "CHANNELD_SHUTTING_DOWN",
        "cause": "user",
        "message": "User or plugin invoked close command"
      },
      {
        "timestamp": "2022-12-06T16:50:58.646Z",
        "old_state": "CHANNELD_SHUTTING_DOWN",
        "new_state": "CLOSINGD_SIGEXCHANGE",
        "cause": "user",
        "message": "Start closingd"
      },
      {
        "timestamp": "2022-12-06T16:50:58.875Z",
        "old_state": "CLOSINGD_SIGEXCHANGE",
        "new_state": "CLOSINGD_COMPLETE",
        "cause": "user",
        "message": "Closing complete"
      },
      {
        "timestamp": "2022-12-06T16:53:21.823Z",
        "old_state": "CLOSINGD_COMPLETE",
        "new_state": "FUNDING_SPEND_SEEN",
        "cause": "user",
        "message": "Onchain funding spend"
      },
      {
        "timestamp": "2022-12-06T16:53:21.874Z",
        "old_state": "FUNDING_SPEND_SEEN",
        "new_state": "ONCHAIN",
        "cause": "user",
        "message": "Onchain init reply"
      }
    ]
  2. and the log of the last significant changes of the channel:

    [
      "CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 138 satoshi for tx:12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
      "ONCHAIN:Tracking mutual close transaction",
      "ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel"
    ]

Note that in the videos I said that I didn't know why we had to mine 100 blocks for the channels to be forgotten (stop being listed by the sub-command listpeers) and how we can change that value (we can't). It happens that this is something hard-coded in CLN source code and recommended by BOLT #5: Recommendations for On-chain Transaction Handling:

With that said, we can mine 100 blocks and forget that channel:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": []
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
         "output": 0,
         "amount_msat": 98999846000,
         "scriptpubkey": "00145e8461dc5f6bc508fbf800076e9a88eee2827da3",
         "address": "bcrt1qt6zxrhzld0zs37lcqqrkax5gam3gyldr2rd3da",
         "status": "confirmed",
         "blockheight": 103,
         "reserved": false
      },
      {
         "txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
         "output": 0,
         "amount_msat": 999862000,
         "scriptpubkey": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
         "address": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
         "status": "confirmed",
         "blockheight": 109,
         "reserved": false
      }
   ],
   "channels": []
}

Last things to note is the address bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl in the second output of the wallet of the node l1 which corresponds to the value of the attribute close_to_addr we've seen before.

Mutual close sending funds to a Bitcoin wallet

Now what we want to do is to see how we can send the funds of a channel to a Bitcoin wallet when we do a mutual close of that channel.

Let's first open a channel from the node l1 to the node l2 with an amount of 1000000sat as we did before:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
bitcoind balance: 5449.00000292
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
         "output": 0,
         "amount_msat": 999862000,
         "scriptpubkey": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
         "address": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
         "status": "confirmed",
         "blockheight": 109,
         "reserved": false
      },
      {
         "txid": "3512da47bf1199beffd7bff7439c89c6449589aee7f946b3f6a02206d6e7c2bb",
         "output": 0,
         "amount_msat": 97999692000,
         "scriptpubkey": "0014457f03144bdacd6dc7271eaa757e7faf77bd6f5e",
         "address": "bcrt1qg4lsx9ztmtxkm3e8r6482lnl4amm6m67g3m34q",
         "status": "confirmed",
         "blockheight": 211,
         "reserved": false
      },
      {
         "txid": "5abdf650c1e98aa767ac2b9ba7c9c2fb7ad4496c7a5f964e067e7dabf7bb16b0",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "0014d662a817055b05480b49d33d6ff11a7c0db06976",
         "address": "bcrt1q6e32s9c9tvz5sz6f6v7klug60sxmq6tkyr5gqn",
         "status": "confirmed",
         "blockheight": 210,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "211x1x1",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "3512da47bf1199beffd7bff7439c89c6449589aee7f946b3f6a02206d6e7c2bb",
         "funding_output": 1
      }
   ]
}

The short channel id of the channel we want to close is 211x1x1.

We now create a bitcoin wallet foo and generate a new bech32 address for that wallet:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest createwallet foo
{
  "name": "foo",
  "warning": ""
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getnewaddress
bcrt1q2ctxwwuem0amxqwf0jsd22ektr3qtmvpp5luuk

We can check that the bitcoin wallet foo has no fund:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
0.00000000

Now the node l1 mutually closes the channel 211x1x1 and sends the corresponding funds to the address bcrt1q2ctxwwuem0amxqwf0jsd22ektr3qtmvpp5luuk which belong to the bitcoin wallet foo by running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=211x1x1 \destination=bcrt1q2ctxwwuem0amxqwf0jsd22ektr3qtmvpp5luuk
# Sending closing fee offer 138sat, with range 138sat-183sat
# Received closing fee offer 138sat, with range 138sat-1000000sat
{
   "tx": "0200000001bbc2e7d60622a0f6b346f9e7ae899544c6899c43f7bfd7ffbe9911bf47da12350100000000ffffffff01b6410f00000000001600145616673b99dbfbb301c97ca0d52b3658e205ed8100000000",
   "txid": "91c77fccc38c7d9c03cba2e22b43bbd223dcff4685157de59ff8e6a42622249b",
   "type": "mutual"
}

Remember that since we manually manage the regtest chain, the previous outputed transaction 0200000001bbc2...5ed8100000000 has been sent to the mempool but not added to a block so far:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
0.00000000

As we are doing a mutual close, we just need to mine one block to get the channel closed:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
[
  "01c609d26d2a3daf7629158c5f4b974bbe2fe77ec41222ee7699893385e7af74"
]

We can observe that the corresponding funds of the channel have been transferred to the bitcoin wallet foo as expected and the channel has been closed:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
0.00999862
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}

To totally forget the channel, we mine 100 more blocks (99 would have been enough):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": []
      }
   ]
}

Unilateral close while the node l2 is disconnected

In this section our goal is to make the node l1 close unilaterally a channel opened with the node l2 while the node l2 is disconnected. To do so we are going to use the flag unilateraltimeout of the sub-command close.

But first, let's open a channel from the node l1 to the node l2 with an amount of 1000000sat as we did before:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
bitcoind balance: 9148.00000584
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "5abdf650c1e98aa767ac2b9ba7c9c2fb7ad4496c7a5f964e067e7dabf7bb16b0",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "0014d662a817055b05480b49d33d6ff11a7c0db06976",
         "address": "bcrt1q6e32s9c9tvz5sz6f6v7klug60sxmq6tkyr5gqn",
         "status": "confirmed",
         "blockheight": 210,
         "reserved": false
      },
      {
         "txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
         "output": 0,
         "amount_msat": 97999332000,
         "scriptpubkey": "001432cd2e5021cb16c2838c1ad0fe2aa93de615280c",
         "address": "bcrt1qxtxju5ppevtv9quvrtg0u24f8hnp22qv7v4d2y",
         "status": "confirmed",
         "blockheight": 319,
         "reserved": false
      },
      {
         "txid": "9c45993f602213ea66e9d8ddb03c774cebb68a8e59b9843a83f676eb220b840f",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "001471ce19fb1ca4b5b1836b442afb67cd5df45a5ec8",
         "address": "bcrt1qw88pn7cu5j6mrqmtgs40ke7dth695hkgyq6046",
         "status": "confirmed",
         "blockheight": 318,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "319x1x1",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
         "funding_output": 1
      }
   ]
}

The channel we are going to close has the short channel id 319x1x1.

We are going to use another terminal to stop the node l2. As we want to use the aliases l1-cli and l2-cli let's run the following commands:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l2-cli
alias l2-cli='lightning-cli --lightning-dir=/tmp/l2-regtest'

We check that the node l1 is connected to the node l2 as we can see in the attribute connected equal to true in the output of the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "channeld",
               "short_channel_id": "319x1x1",
               "direction": 1,
               "channel_id": "10610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0bb",
               "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
               "close_to": "001428e54b9433000840e071fe68c502321dea234220",
               "private": false,
               "opener": "local",
               "alias": {
                  "local": "2406575x16420005x1203",
                  "remote": "3095773x16193972x52869"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T17:04:46.797Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  }
               ],
               "status": [
                  "CHANNELD_NORMAL:Funding transaction locked. Channel announced."
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}

In the terminal 2, we defined the aliases l2-cli and l1-cli, we look for the PID of the instance of lightningd of the node l2 and we kill that process which shutdown the node l2:

# TERMINAL 2

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l2-cli='lightning-cli --lightning-dir=/tmp/l2-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
22013 pts/1    S      0:00 lightningd --lightning-dir=/tmp/l1-regtest
22045 pts/1    S      0:00 lightningd --lightning-dir=/tmp/l2-regtest
31499 pts/2    S+     0:00 grep --color=auto lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ kill 22045
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
22013 pts/1    S      0:00 lightningd --lightning-dir=/tmp/l1-regtest
31571 pts/2    S+     0:00 grep --color=auto lightningd

Note that we could have use the sub-command stop instead:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l2-cli stop

In the first terminal we see that the node l2 has been stopped:

# TERMINAL 1

Lost connection to the RPC socket.Lost connection to the RPC socket.contrib/startup_regtest.sh: line 78: 22045 Terminated              "$LIGHTNINGD" "--lightning-dir=/tmp/l$i-$network"

[2]+  Exit 143                test -f "/tmp/l$i-$network/lightningd-$network.pid" || "$LIGHTNINGD" "--lightning-dir=/tmp/l$i-$network"

We can check using the sub-command listpeers that the node l1 is no longer connected to the node l2:

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": false,
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "short_channel_id": "319x1x1",
               "direction": 1,
               "channel_id": "10610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0bb",
               "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
               "close_to": "001428e54b9433000840e071fe68c502321dea234220",
               "private": false,
               "opener": "local",
               "alias": {
                  "local": "2406575x16420005x1203",
                  "remote": "3095773x16193972x52869"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T17:04:46.797Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  }
               ],
               "status": [
                  "CHANNELD_NORMAL:Will attempt reconnect in 16 seconds"
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}

Looking at the man page of the sub-command close of lightning-cli, we can read that "If unilateraltimeout is not zero, the close command will unilaterally close the channel when that number of seconds is reached".

Let's the node l1 closes the channel 319x1x1 with an unilateraltimeout of 10 seconds like this:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=319x1x1 \unilateraltimeout=10
# peer is offline, will negotiate once they reconnect (10 seconds before unilateral close).

The command wait during 10 seconds and then closes the channel unilaterally:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=319x1x1 \unilateraltimeout=10
# peer is offline, will negotiate once they reconnect (10 seconds before unilateral close).
# Timed out, forcing close.
{
   "tx": "020000000110610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0ba0100000000462594800189410f000000000022002089f5c836151999713f2f7b9b13408d368dd191f8abc40769c46ff6a40c8ec9574cad9c20",
   "txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
   "type": "unilateral"
}

As we did before, we mine one block with that last outputed transaction in it (we sent it to the mempool):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
[
  "3f61b5707f8d7a404254c48cff247c248bc5d44c8c0b666e107fab72bd0d9da4"
]

And after waiting a few seconds we can check that the channels has been removed from the network:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}

And to forget the channel we mine 100 more blocks:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null

Mutual close waiting reconnection of node l2

In that section our goal is to make the node l1 mutually close a channel opened with the node l2 waiting (virtually indefinitely) for it to be online and reconnected.

To do so we are going to use the flag unilateraltimeout of the sub-command close.

As we stopped the node l2 in the previous section, the first thing we do is to start it again:

# TERMINAL 2

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ lightningd --lightning-dir=/tmp/l2-regtest --daemon
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
 1735 ?        Ds     0:00 lightningd --lightning-dir=/tmp/l2-regtest --daemon
 1847 pts/2    R+     0:00 grep --color=auto lightningd
22013 pts/1    S      0:01 lightningd --lightning-dir=/tmp/l1-regtest

As we can see using the command listpeers, the node l1 and l2 are not connected:

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": false,
         "channels": [
            {
               "state": "ONCHAIN",
               "scratch_txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "onchaind",
               "short_channel_id": "319x1x1",
               "direction": 1,
               "channel_id": "10610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0bb",
               "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
               "close_to": "001428e54b9433000840e071fe68c502321dea234220",
               "private": false,
               "opener": "local",
               "closer": "local",
               "alias": {
                  "local": "2406575x16420005x1203",
                  "remote": "3095773x16193972x52869"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T17:04:46.797Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  },
                  {
                     "timestamp": "2022-12-06T17:11:04.208Z",
                     "old_state": "CHANNELD_NORMAL",
                     "new_state": "CHANNELD_SHUTTING_DOWN",
                     "cause": "user",
                     "message": "User or plugin invoked close command"
                  },
                  {
                     "timestamp": "2022-12-06T17:11:14.212Z",
                     "old_state": "CHANNELD_SHUTTING_DOWN",
                     "new_state": "AWAITING_UNILATERAL",
                     "cause": "user",
                     "message": "Forcibly closed by `close` command timeout"
                  },
                  {
                     "timestamp": "2022-12-06T17:12:16.528Z",
                     "old_state": "AWAITING_UNILATERAL",
                     "new_state": "FUNDING_SPEND_SEEN",
                     "cause": "user",
                     "message": "Onchain funding spend"
                  },
                  {
                     "timestamp": "2022-12-06T17:12:16.750Z",
                     "old_state": "FUNDING_SPEND_SEEN",
                     "new_state": "ONCHAIN",
                     "cause": "user",
                     "message": "Onchain init reply"
                  }
               ],
               "status": [
                  "ONCHAIN:Tracking our own unilateral close",
                  "ONCHAIN:All outputs resolved: waiting 85 more blocks before forgetting channel"
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}

To connect them we use the sub-command connect of lightning-cli like this:

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l2-cli -F getinfo | grep -E 'id|binding'
id=0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62
binding[0].type=ipv4
binding[0].address=127.0.0.1
binding[0].port=7272
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli connect 0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62@127.0.0.1:7272
{
   "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
   "features": "08a000080269a2",
   "direction": "out",
   "address": {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7272
   }
}

For the last time we open a channel from the node l1 to the node l2 with an amount of 1000000sat as we did before:

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
bitcoind balance: 12784.50001110
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.

Now, the channel we want to close has the short channel id 528x1x0 as we see running the following command:

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
         "output": 0,
         "amount_msat": 97999332000,
         "scriptpubkey": "001432cd2e5021cb16c2838c1ad0fe2aa93de615280c",
         "address": "bcrt1qxtxju5ppevtv9quvrtg0u24f8hnp22qv7v4d2y",
         "status": "confirmed",
         "blockheight": 319,
         "reserved": false
      },
      {
         "txid": "9c45993f602213ea66e9d8ddb03c774cebb68a8e59b9843a83f676eb220b840f",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "001471ce19fb1ca4b5b1836b442afb67cd5df45a5ec8",
         "address": "bcrt1qw88pn7cu5j6mrqmtgs40ke7dth695hkgyq6046",
         "status": "confirmed",
         "blockheight": 318,
         "reserved": false
      },
      {
         "txid": "0bc4a016d956946a7e5f5c8a0e0bbf36173c7a01bbb393907f8e68f36402e4d1",
         "output": 0,
         "amount_msat": 999696000,
         "scriptpubkey": "001428e54b9433000840e071fe68c502321dea234220",
         "address": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
         "status": "confirmed",
         "blockheight": 412,
         "reserved": false
      },
      {
         "txid": "b9d3bd8f685464752ae66178ce9f96f4a7d3153646246930b7af1717873d8676",
         "output": 1,
         "amount_msat": 98999846000,
         "scriptpubkey": "001448255f22a089d401bb56846062154264f3bcfe9f",
         "address": "bcrt1qfqj47g4q382qrw6ks3sxy92zvnemel5ljj954k",
         "status": "confirmed",
         "blockheight": 528,
         "reserved": false
      },
      {
         "txid": "cafc4338b82953f253fbcdf4b72c5484f2b9284c1b23d668e2c916b7c8065464",
         "output": 0,
         "amount_msat": 100000000000,
         "scriptpubkey": "00144d30e6eb62d9af041d392a4e0ec98b41ed792b9d",
         "address": "bcrt1qf5cwd6mzmxhsg8fe9f8qajvtg8khj2uanu63f9",
         "status": "confirmed",
         "blockheight": 527,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "528x1x0",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "b9d3bd8f685464752ae66178ce9f96f4a7d3153646246930b7af1717873d8676",
         "funding_output": 0
      }
   ]
}

To put our lightning network in the right state to do our experiment, we jump in the terminal 2 and shutdown the node l2 like we did before (note that we could have use the sub-command close instead):

# TERMINAL 2

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
 1735 ?        Ss     0:00 lightningd --lightning-dir=/tmp/l2-regtest --daemon
 4546 pts/2    S+     0:00 grep --color=auto lightningd
22013 pts/1    S      0:01 lightningd --lightning-dir=/tmp/l1-regtest
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ kill 1735
Lost connection to the RPC socket.Lost connection to the RPC socket.

In the terminal 1 we check that the nodes are disconnected running the following command:

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers | less
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": false,
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "01d0eee99c83ffa925a68eeeeba2c1fed3d6f410e39dbe40f991822043b64366",

Now in the terminal 1, the node l1 close the channel 528x1x0 with unilateraltimeout set to 0 which means that the node l1 will wait until the node l2 come back online and reconnect to l1 in order to negotiate a mutual close:

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=528x1x0 \unilateraltimeout=0
# peer is offline, will negotiate once they reconnect.

While the node l1 is waiting for l2 to go back online, we jump in the terminal 2, restart the node l2 and connect it to the node l1:

# TERMINAL 2

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ lightningd --lightning-dir=/tmp/l2-regtest --daemon
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l2-cli -F getinfo | grep -E 'id|bindin'
id=0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62
binding[0].type=ipv4
binding[0].address=127.0.0.1
binding[0].port=7272
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli connect 0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62@127.0.0.1:7272
{
   "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
   "features": "08a000080269a2",
   "direction": "out",
   "address": {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7272
   }
}

At the moment the nodes are reconnected the mutual close can be terminated as we can see below (better on the video as the 2 terminals are side by side):

# TERMINAL 1

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=528x1x0 \unilateraltimeout=0
# peer is offline, will negotiate once they reconnect.
# Sending closing fee offer 138sat, with range 138sat-183sat
# Received closing fee offer 138sat, with range 138sat-1000000sat
{
   "tx": "020000000176863d871717afb7306924463615d3a7f4969fce7861e62a756454688fbdd3b90000000000ffffffff01b6410f0000000000160014eb4007658f9b82bf6bada71a0a77ce55c98f6ea700000000",
   "txid": "5ebc645034ddd40a26ebe4ecd64fd3e8e6119c4f02bb034afb4a8e017b76c3d7",
   "type": "mutual"
}

Now that we have sent the last outputed transaction 02000000017686...8f6ea700000000 to the mempool of our Bitcoin regtest chain, we just have to mine one block to close the channel (and 100 to totally forget the channel):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}

We are done.

I hope you enjoy the video and you get some value from it.

See you next time in another episode of LN Room.

Terminal sessions

Terminal 1

We ran the following commands in this order:

$ source contrib/startup_regtest.sh
$ start_ln 2
$ alias l1-cli
$ connect 1 2
$ fund_nodes 1 2
$ l1-cli listchannels
$ l1-cli listfunds
$ l1-cli listpeers
$ l1-cli close 103x1x1
$ l1-cli listchannels
$ bitcoin-cli -regtest -rpcwallet=default getnewaddress
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
$ l1-cli listchannels
$ l1-cli listpeers
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
$ l1-cli listpeers
$ l1-cli listfunds
$ fund_nodes 1 2
$ l1-cli listfunds
$ bitcoin-cli -regtest createwallet foo
$ bitcoin-cli -regtest -rpcwallet=foo getnewaddress
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
$ l1-cli -k close \
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
$ l1-cli listchannels
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
$ l1-cli listpeers
$ fund_nodes 1 2
$ l1-cli listfunds
$ alias l1-cli
$ alias l2-cli
$ l1-cli listpeers
$ l1-cli listpeers
$ l1-cli -k close \
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
$ l1-cli listchannels
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
$ l1-cli listpeers
$ l2-cli -F getinfo | grep -E 'id|binding'
$ l1-cli connect 0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62@127.0.0.1:7272
$ fund_nodes 1 2
$ l1-cli listfunds
$ l1-cli listpeers | less
$ l1-cli -k close \
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
$ l1-cli listchannels

And below you can read the terminal session (command lines and outputs):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ source contrib/startup_regtest.sh
lightning-cli is /usr/bin/lightning-cli
lightningd is /usr/bin/lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ start_ln 2
Bitcoin Core starting
awaiting bitcoind...
Making "default" bitcoind wallet.
[1] 22011
[2] 22043
Commands:
        l1-cli, l1-log,
        l2-cli, l2-log,
        bt-cli, stop_ln, fund_nodes
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ connect 1 2
{
   "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
   "features": "08a000080269a2",
   "direction": "out",
   "address": {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7272
   }
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
Mining into address bcrt1qh8zpeudzs060pr7e7tmq52qadl8dusdaff049t... done.
bitcoind balance: 50.00000000
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": [
      {
         "source": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "destination": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "short_channel_id": "103x1x1",
         "public": false,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 0,
         "active": true,
         "last_update": 1670344947,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      },
      {
         "source": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "destination": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "short_channel_id": "103x1x1",
         "public": false,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 1,
         "active": true,
         "last_update": 1670344947,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
         "output": 0,
         "amount_msat": 98999846000,
         "scriptpubkey": "00145e8461dc5f6bc508fbf800076e9a88eee2827da3",
         "address": "bcrt1qt6zxrhzld0zs37lcqqrkax5gam3gyldr2rd3da",
         "status": "confirmed",
         "blockheight": 103,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "103x1x1",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
         "funding_output": 1
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "db618fb422bba89ef4c89318b6711024bccb8dd3a331f526c78f9d2ce35ad14f",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "channeld",
               "short_channel_id": "103x1x1",
               "direction": 1,
               "channel_id": "1fc3c4044329bc0357086ce35dd28516e04819dc0c71b54da63c293e0b7e131f",
               "funding_txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
               "close_to": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
               "private": false,
               "opener": "local",
               "alias": {
                  "local": "16496960x636393x30406",
                  "remote": "5307576x9553925x2900"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T16:47:21.853Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  }
               ],
               "status": [
                  "CHANNELD_NORMAL:Funding transaction locked. Channel announced."
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli close 103x1x1
# Sending closing fee offer 138sat, with range 138sat-183sat
# Received closing fee offer 138sat, with range 138sat-1000000sat
{
   "tx": "02000000011fc3c4044329bc0357086ce35dd28516e04819dc0c71b54da63c293e0b7e131e0100000000ffffffff01b6410f0000000000160014a91d0f7cc612513dd7573efb85168c3e37ecd2af00000000",
   "txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
   "type": "mutual"
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": [
      {
         "source": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "destination": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "short_channel_id": "103x1x1",
         "public": true,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 2,
         "active": false,
         "last_update": 1670345458,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      },
      {
         "source": "02a42e0029d652461a48ed5d7d69d47fdc548370c7db7a194ce6d30bc03dd2b482",
         "destination": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "short_channel_id": "103x1x1",
         "public": true,
         "amount_msat": 1000000000,
         "message_flags": 1,
         "channel_flags": 3,
         "active": false,
         "last_update": 1670345458,
         "base_fee_millisatoshi": 1,
         "fee_per_millionth": 10,
         "delay": 6,
         "htlc_minimum_msat": 0,
         "htlc_maximum_msat": 990000000,
         "features": ""
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=default getnewaddress
bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
[
  "7a9cc18ae79fc995129806176a0d2d2d660b87642387815560cb40f5b1118161"
]
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": [
            {
               "state": "ONCHAIN",
               "scratch_txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
               "last_tx_fee_msat": 138000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "onchaind",
               "short_channel_id": "103x1x1",
               "direction": 1,
               "channel_id": "1fc3c4044329bc0357086ce35dd28516e04819dc0c71b54da63c293e0b7e131f",
               "funding_txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
               "close_to": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
               "private": false,
               "opener": "local",
               "closer": "local",
               "alias": {
                  "local": "16496960x636393x30406",
                  "remote": "5307576x9553925x2900"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T16:47:21.853Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  },
                  {
                     "timestamp": "2022-12-06T16:50:58.292Z",
                     "old_state": "CHANNELD_NORMAL",
                     "new_state": "CHANNELD_SHUTTING_DOWN",
                     "cause": "user",
                     "message": "User or plugin invoked close command"
                  },
                  {
                     "timestamp": "2022-12-06T16:50:58.646Z",
                     "old_state": "CHANNELD_SHUTTING_DOWN",
                     "new_state": "CLOSINGD_SIGEXCHANGE",
                     "cause": "user",
                     "message": "Start closingd"
                  },
                  {
                     "timestamp": "2022-12-06T16:50:58.875Z",
                     "old_state": "CLOSINGD_SIGEXCHANGE",
                     "new_state": "CLOSINGD_COMPLETE",
                     "cause": "user",
                     "message": "Closing complete"
                  },
                  {
                     "timestamp": "2022-12-06T16:53:21.823Z",
                     "old_state": "CLOSINGD_COMPLETE",
                     "new_state": "FUNDING_SPEND_SEEN",
                     "cause": "user",
                     "message": "Onchain funding spend"
                  },
                  {
                     "timestamp": "2022-12-06T16:53:21.874Z",
                     "old_state": "FUNDING_SPEND_SEEN",
                     "new_state": "ONCHAIN",
                     "cause": "user",
                     "message": "Onchain init reply"
                  }
               ],
               "status": [
                  "CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 138 satoshi for tx:12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
                  "ONCHAIN:Tracking mutual close transaction",
                  "ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel"
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": []
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "1e137e0b3e293ca64db5710cdc1948e01685d25de36c085703bc294304c4c31f",
         "output": 0,
         "amount_msat": 98999846000,
         "scriptpubkey": "00145e8461dc5f6bc508fbf800076e9a88eee2827da3",
         "address": "bcrt1qt6zxrhzld0zs37lcqqrkax5gam3gyldr2rd3da",
         "status": "confirmed",
         "blockheight": 103,
         "reserved": false
      },
      {
         "txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
         "output": 0,
         "amount_msat": 999862000,
         "scriptpubkey": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
         "address": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
         "status": "confirmed",
         "blockheight": 109,
         "reserved": false
      }
   ],
   "channels": []
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
bitcoind balance: 5449.00000292
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "12949e19bd142ea1f6bb83ec102c371349204aab2f0d2970b05cbecbfc8e8cbe",
         "output": 0,
         "amount_msat": 999862000,
         "scriptpubkey": "0014a91d0f7cc612513dd7573efb85168c3e37ecd2af",
         "address": "bcrt1q4yws7lxxzfgnm46h8mac295v8cm7e540pce7yl",
         "status": "confirmed",
         "blockheight": 109,
         "reserved": false
      },
      {
         "txid": "3512da47bf1199beffd7bff7439c89c6449589aee7f946b3f6a02206d6e7c2bb",
         "output": 0,
         "amount_msat": 97999692000,
         "scriptpubkey": "0014457f03144bdacd6dc7271eaa757e7faf77bd6f5e",
         "address": "bcrt1qg4lsx9ztmtxkm3e8r6482lnl4amm6m67g3m34q",
         "status": "confirmed",
         "blockheight": 211,
         "reserved": false
      },
      {
         "txid": "5abdf650c1e98aa767ac2b9ba7c9c2fb7ad4496c7a5f964e067e7dabf7bb16b0",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "0014d662a817055b05480b49d33d6ff11a7c0db06976",
         "address": "bcrt1q6e32s9c9tvz5sz6f6v7klug60sxmq6tkyr5gqn",
         "status": "confirmed",
         "blockheight": 210,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "211x1x1",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "3512da47bf1199beffd7bff7439c89c6449589aee7f946b3f6a02206d6e7c2bb",
         "funding_output": 1
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest createwallet foo
{
  "name": "foo",
  "warning": ""
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getnewaddress
bcrt1q2ctxwwuem0amxqwf0jsd22ektr3qtmvpp5luuk
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
0.00000000
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=211x1x1 \destination=bcrt1q2ctxwwuem0amxqwf0jsd22ektr3qtmvpp5luuk
# Sending closing fee offer 138sat, with range 138sat-183sat
# Received closing fee offer 138sat, with range 138sat-1000000sat
{
   "tx": "0200000001bbc2e7d60622a0f6b346f9e7ae899544c6899c43f7bfd7ffbe9911bf47da12350100000000ffffffff01b6410f00000000001600145616673b99dbfbb301c97ca0d52b3658e205ed8100000000",
   "txid": "91c77fccc38c7d9c03cba2e22b43bbd223dcff4685157de59ff8e6a42622249b",
   "type": "mutual"
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
0.00000000
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
[
  "01c609d26d2a3daf7629158c5f4b974bbe2fe77ec41222ee7699893385e7af74"
]
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest -rpcwallet=foo getbalance
0.00999862
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": []
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
bitcoind balance: 9148.00000584
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "5abdf650c1e98aa767ac2b9ba7c9c2fb7ad4496c7a5f964e067e7dabf7bb16b0",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "0014d662a817055b05480b49d33d6ff11a7c0db06976",
         "address": "bcrt1q6e32s9c9tvz5sz6f6v7klug60sxmq6tkyr5gqn",
         "status": "confirmed",
         "blockheight": 210,
         "reserved": false
      },
      {
         "txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
         "output": 0,
         "amount_msat": 97999332000,
         "scriptpubkey": "001432cd2e5021cb16c2838c1ad0fe2aa93de615280c",
         "address": "bcrt1qxtxju5ppevtv9quvrtg0u24f8hnp22qv7v4d2y",
         "status": "confirmed",
         "blockheight": 319,
         "reserved": false
      },
      {
         "txid": "9c45993f602213ea66e9d8ddb03c774cebb68a8e59b9843a83f676eb220b840f",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "001471ce19fb1ca4b5b1836b442afb67cd5df45a5ec8",
         "address": "bcrt1qw88pn7cu5j6mrqmtgs40ke7dth695hkgyq6046",
         "status": "confirmed",
         "blockheight": 318,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "319x1x1",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
         "funding_output": 1
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l2-cli
alias l2-cli='lightning-cli --lightning-dir=/tmp/l2-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "netaddr": [
            "127.0.0.1:7272"
         ],
         "features": "08a000080269a2",
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "channeld",
               "short_channel_id": "319x1x1",
               "direction": 1,
               "channel_id": "10610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0bb",
               "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
               "close_to": "001428e54b9433000840e071fe68c502321dea234220",
               "private": false,
               "opener": "local",
               "alias": {
                  "local": "2406575x16420005x1203",
                  "remote": "3095773x16193972x52869"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T17:04:46.797Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  }
               ],
               "status": [
                  "CHANNELD_NORMAL:Funding transaction locked. Channel announced."
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ Lost connection to the RPC socket.Lost connection to the RPC socket.contrib/startup_regtest.sh: line 78: 22045 Terminated              "$LIGHTNINGD" "--lightning-dir=/tmp/l$i-$network"

[2]+  Exit 143                test -f "/tmp/l$i-$network/lightningd-$network.pid" || "$LIGHTNINGD" "--lightning-dir=/tmp/l$i-$network"
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": false,
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "short_channel_id": "319x1x1",
               "direction": 1,
               "channel_id": "10610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0bb",
               "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
               "close_to": "001428e54b9433000840e071fe68c502321dea234220",
               "private": false,
               "opener": "local",
               "alias": {
                  "local": "2406575x16420005x1203",
                  "remote": "3095773x16193972x52869"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T17:04:46.797Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  }
               ],
               "status": [
                  "CHANNELD_NORMAL:Will attempt reconnect in 16 seconds"
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=319x1x1 \unilateraltimeout=10
# peer is offline, will negotiate once they reconnect (10 seconds before unilateral close).
# Timed out, forcing close.
{
   "tx": "020000000110610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0ba0100000000462594800189410f000000000022002089f5c836151999713f2f7b9b13408d368dd191f8abc40769c46ff6a40c8ec9574cad9c20",
   "txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
   "type": "unilateral"
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 1 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr
[
  "3f61b5707f8d7a404254c48cff247c248bc5d44c8c0b666e107fab72bd0d9da4"
]
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": false,
         "channels": [
            {
               "state": "ONCHAIN",
               "scratch_txid": "381afa9de5c78bed605d858c29ca5d103122d88b04a4356b787b01507a03229b",
               "last_tx_fee_msat": 183000,
               "feerate": {
                  "perkw": 253,
                  "perkb": 1012
               },
               "owner": "onchaind",
               "short_channel_id": "319x1x1",
               "direction": 1,
               "channel_id": "10610a7f4cfcdd28ecd6782f6b00091828eaa6aca16be6a7098537bd02c0f0bb",
               "funding_txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
               "funding_outnum": 1,
               "close_to_addr": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
               "close_to": "001428e54b9433000840e071fe68c502321dea234220",
               "private": false,
               "opener": "local",
               "closer": "local",
               "alias": {
                  "local": "2406575x16420005x1203",
                  "remote": "3095773x16193972x52869"
               },
               "features": [
                  "option_static_remotekey"
               ],
               "funding": {
                  "local_funds_msat": "1000000000msat",
                  "remote_funds_msat": "0msat",
                  "pushed_msat": 0
               },
               "to_us_msat": 1000000000,
               "min_to_us_msat": 1000000000,
               "max_to_us_msat": 1000000000,
               "total_msat": 1000000000,
               "fee_base_msat": 1,
               "fee_proportional_millionths": 10,
               "dust_limit_msat": 546000,
               "max_total_htlc_in_msat": 18446744073709551615,
               "their_reserve_msat": 10000000,
               "our_reserve_msat": 10000000,
               "spendable_msat": 989460000,
               "receivable_msat": 0,
               "minimum_htlc_in_msat": 0,
               "minimum_htlc_out_msat": 0,
               "maximum_htlc_out_msat": 990000000,
               "their_to_self_delay": 6,
               "our_to_self_delay": 6,
               "max_accepted_htlcs": 483,
               "state_changes": [
                  {
                     "timestamp": "2022-12-06T17:04:46.797Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",
                     "message": "Lockin complete"
                  },
                  {
                     "timestamp": "2022-12-06T17:11:04.208Z",
                     "old_state": "CHANNELD_NORMAL",
                     "new_state": "CHANNELD_SHUTTING_DOWN",
                     "cause": "user",
                     "message": "User or plugin invoked close command"
                  },
                  {
                     "timestamp": "2022-12-06T17:11:14.212Z",
                     "old_state": "CHANNELD_SHUTTING_DOWN",
                     "new_state": "AWAITING_UNILATERAL",
                     "cause": "user",
                     "message": "Forcibly closed by `close` command timeout"
                  },
                  {
                     "timestamp": "2022-12-06T17:12:16.528Z",
                     "old_state": "AWAITING_UNILATERAL",
                     "new_state": "FUNDING_SPEND_SEEN",
                     "cause": "user",
                     "message": "Onchain funding spend"
                  },
                  {
                     "timestamp": "2022-12-06T17:12:16.750Z",
                     "old_state": "FUNDING_SPEND_SEEN",
                     "new_state": "ONCHAIN",
                     "cause": "user",
                     "message": "Onchain init reply"
                  }
               ],
               "status": [
                  "ONCHAIN:Tracking our own unilateral close",
                  "ONCHAIN:All outputs resolved: waiting 85 more blocks before forgetting channel"
               ],
               "in_payments_offered": 0,
               "in_offered_msat": 0,
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,
               "out_payments_offered": 0,
               "out_offered_msat": 0,
               "out_payments_fulfilled": 0,
               "out_fulfilled_msat": 0,
               "htlcs": []
            }
         ]
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l2-cli -F getinfo | grep -E 'id|binding'
id=0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62
binding[0].type=ipv4
binding[0].address=127.0.0.1
binding[0].port=7272
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli connect 0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62@127.0.0.1:7272
{
   "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
   "features": "08a000080269a2",
   "direction": "out",
   "address": {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7272
   }
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ fund_nodes 1 2
bitcoind balance: 12784.50001110
Waiting for lightning node funds... found.
Funding channel from node 1 to node 2. Waiting for confirmation... done.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listfunds
{
   "outputs": [
      {
         "txid": "baf0c002bd378509a7e66ba1aca6ea281809006b2f78d6ec28ddfc4c7f0a6110",
         "output": 0,
         "amount_msat": 97999332000,
         "scriptpubkey": "001432cd2e5021cb16c2838c1ad0fe2aa93de615280c",
         "address": "bcrt1qxtxju5ppevtv9quvrtg0u24f8hnp22qv7v4d2y",
         "status": "confirmed",
         "blockheight": 319,
         "reserved": false
      },
      {
         "txid": "9c45993f602213ea66e9d8ddb03c774cebb68a8e59b9843a83f676eb220b840f",
         "output": 1,
         "amount_msat": 100000000000,
         "scriptpubkey": "001471ce19fb1ca4b5b1836b442afb67cd5df45a5ec8",
         "address": "bcrt1qw88pn7cu5j6mrqmtgs40ke7dth695hkgyq6046",
         "status": "confirmed",
         "blockheight": 318,
         "reserved": false
      },
      {
         "txid": "0bc4a016d956946a7e5f5c8a0e0bbf36173c7a01bbb393907f8e68f36402e4d1",
         "output": 0,
         "amount_msat": 999696000,
         "scriptpubkey": "001428e54b9433000840e071fe68c502321dea234220",
         "address": "bcrt1q9rj5h9pnqqyypcr3le5v2q3jrh4zxs3qkdvg5u",
         "status": "confirmed",
         "blockheight": 412,
         "reserved": false
      },
      {
         "txid": "b9d3bd8f685464752ae66178ce9f96f4a7d3153646246930b7af1717873d8676",
         "output": 1,
         "amount_msat": 98999846000,
         "scriptpubkey": "001448255f22a089d401bb56846062154264f3bcfe9f",
         "address": "bcrt1qfqj47g4q382qrw6ks3sxy92zvnemel5ljj954k",
         "status": "confirmed",
         "blockheight": 528,
         "reserved": false
      },
      {
         "txid": "cafc4338b82953f253fbcdf4b72c5484f2b9284c1b23d668e2c916b7c8065464",
         "output": 0,
         "amount_msat": 100000000000,
         "scriptpubkey": "00144d30e6eb62d9af041d392a4e0ec98b41ed792b9d",
         "address": "bcrt1qf5cwd6mzmxhsg8fe9f8qajvtg8khj2uanu63f9",
         "status": "confirmed",
         "blockheight": 527,
         "reserved": false
      }
   ],
   "channels": [
      {
         "peer_id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": true,
         "state": "CHANNELD_NORMAL",
         "short_channel_id": "528x1x0",
         "our_amount_msat": 1000000000,
         "amount_msat": 1000000000,
         "funding_txid": "b9d3bd8f685464752ae66178ce9f96f4a7d3153646246930b7af1717873d8676",
         "funding_output": 0
      }
   ]
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listpeers | less
{
   "peers": [
      {
         "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
         "connected": false,
         "channels": [
            {
               "state": "CHANNELD_NORMAL",
               "scratch_txid": "01d0eee99c83ffa925a68eeeeba2c1fed3d6f410e39dbe40f991822043b64366",
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli -k close \id=528x1x0 \unilateraltimeout=0
# peer is offline, will negotiate once they reconnect.
# Sending closing fee offer 138sat, with range 138sat-183sat
# Received closing fee offer 138sat, with range 138sat-1000000sat
{
   "tx": "020000000176863d871717afb7306924463615d3a7f4969fce7861e62a756454688fbdd3b90000000000ffffffff01b6410f0000000000160014eb4007658f9b82bf6bada71a0a77ce55c98f6ea700000000",
   "txid": "5ebc645034ddd40a26ebe4ecd64fd3e8e6119c4f02bb034afb4a8e017b76c3d7",
   "type": "mutual"
}
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ bitcoin-cli -regtest generatetoaddress 100 bcrt1qn3qz7zw95wkgfedngezgueaaz7l776tup73mjr > /dev/null
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli listchannels
{
   "channels": []
}

Terminal 2

We ran the following commands in this order:

$ alias l2-cli='lightning-cli --lightning-dir=/tmp/l2-regtest'
$ alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
$ ps -ax | grep lightningd
$ kill 22045
$ ps -ax | grep lightningd
$ lightningd --lightning-dir=/tmp/l2-regtest --daemon
$ ps -ax | grep lightningd
$ ps -ax | grep lightningd
$ kill 1735
$ lightningd --lightning-dir=/tmp/l2-regtest --daemon
$ l2-cli -F getinfo | grep -E 'id|bindin'
$ l1-cli connect 0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62@127.0.0.1:7272

And below you can read the terminal session (command lines and outputs):

◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l2-cli='lightning-cli --lightning-dir=/tmp/l2-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
22013 pts/1    S      0:00 lightningd --lightning-dir=/tmp/l1-regtest
22045 pts/1    S      0:00 lightningd --lightning-dir=/tmp/l2-regtest
31499 pts/2    S+     0:00 grep --color=auto lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ kill 22045
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
22013 pts/1    S      0:00 lightningd --lightning-dir=/tmp/l1-regtest
31571 pts/2    S+     0:00 grep --color=auto lightningd
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ lightningd --lightning-dir=/tmp/l2-regtest --daemon
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
 1735 ?        Ds     0:00 lightningd --lightning-dir=/tmp/l2-regtest --daemon
 1847 pts/2    R+     0:00 grep --color=auto lightningd
22013 pts/1    S      0:01 lightningd --lightning-dir=/tmp/l1-regtest
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ ps -ax | grep lightningd
 1735 ?        Ss     0:00 lightningd --lightning-dir=/tmp/l2-regtest --daemon
 4546 pts/2    S+     0:00 grep --color=auto lightningd
22013 pts/1    S      0:01 lightningd --lightning-dir=/tmp/l1-regtest
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ kill 1735
Lost connection to the RPC socket.Lost connection to the RPC socket.
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ lightningd --lightning-dir=/tmp/l2-regtest --daemon
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l2-cli -F getinfo | grep -E 'id|bindin'
id=0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62
binding[0].type=ipv4
binding[0].address=127.0.0.1
binding[0].port=7272
◉ tony@tony:~/lnroom/lightning:[git»(HEAD detached at v0.12.1)]
$ l1-cli connect 0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62@127.0.0.1:7272
{
   "id": "0212b9b7e2a024608e731e96a46f85ba9aa4883ea7d507e2a10a9329b1b7b15d62",
   "features": "08a000080269a2",
   "direction": "out",
   "address": {
      "type": "ipv4",
      "address": "127.0.0.1",
      "port": 7272
   }
}

Resources