Skip to content

Instantly share code, notes, and snippets.

@mohamedawnallah
Last active May 11, 2024 09:47
Show Gist options
  • Save mohamedawnallah/def1cb4079fb79827b8e941f66e252fb to your computer and use it in GitHub Desktop.
Save mohamedawnallah/def1cb4079fb79827b8e941f66e252fb to your computer and use it in GitHub Desktop.
Distributed Mission Control SoB'2024 [Competency Test]

Table of Contents

  1. Setting Up Three Lightning Network (LN) Nodes
  2. Funding LN Nodes
  3. Use Case 1: Payment Successful
  4. Use Case 2: Payment Failed - Multipart Payment (MPP) Timeout Error
  5. Importing Mission Control State

Setting Up Three Lightning Network (LN) Nodes

To set up 3 lightning nodes in the network using multipass and scripting, follow these steps:

  1. Clone Repository: Clone my repository Bootstrap-Lightning-Network.

  2. Launch Nodes: Launch three Lightning Nodes named Alice, Bob, and Carol:

    multipass launch --name alice --cpus 1 --memory 1G 22.04
    multipass launch --name bob --cpus 1 --memory 1G 22.04
    multipass launch --name carol --cpus 1 --memory 1G 22.04
  3. Install Dependencies: Install dependencies, Go, Bitcoin Core, and LND from the latest commit in the master branch:

    multipass exec alice -- bash -c "curl -sSL https://raw.githubusercontent.com/mohamedawnallah/bootstrap-lightning-network/main/setup_ln | bash -s $BITCOIN_IP $LN_NODE_ALIAS"
    multipass exec bob -- bash -c "curl -sSL https://raw.githubusercontent.com/mohamedawnallah/bootstrap-lightning-network/main/setup_ln | bash -s $BITCOIN_IP $LN_NODE_ALIAS"
    multipass exec carol -- bash -c "curl -sSL https://raw.githubusercontent.com/mohamedawnallah/bootstrap-lightning-network/main/setup_ln | bash -s $BITCOIN_IP $LN_NODE_ALIAS"

This way, you can easily set up three Lightning Network nodes named Alice, Bob, and Carol using the provided script and multipass.

Funding LN Nodes

To fund Lightning Network (LN) Nodes, follow these steps:

  1. Create Bitcoin Wallet: Create a bitcoin-wallet using this command:

    bitcoin-cli createwallet test
  2. Generate Blocks: Generate at least 101 blocks for coinbase block maturity using this command:

    bitcoin-cli -generate 150
  3. Generate Pay to Witness Key Hash: Generate Pay to Witness Key Hash for each LN node using this command:

    lncli newaddress p2wkh
  4. Send Bitcoins: Send bitcoins to those addresses using this command:

    bitcoin-cli sendtoaddress <your_lnwallet_address> <bitcoins>
  5. Confirm Transactions: Mine at least one block after each send to be confirmed in the lnwallet using this command:

    bitcoin-cli -generate 1
  6. Ready for Payment Channels: Now we have enough bitcoins on each LN node to create multiple scenarios for creating payment channels.

By following these steps, you'll successfully fund the LN nodes and prepare them for setting up payment channels.

Use Case 1: Payment Successful

Setting Up Payment Channels

  1. Create Payment Channel from Alice to Bob:

    lncli openchannel --node_key <Bob's Identity Public Key> --connect <Bob's Node Ip Address>:9735 30000

    Mine at least three blocks to confirm the funding tx marking the channel as open:

    bitcoin-cli -generate 3
  2. Create Payment Channel from Bob to Carol:

    lncli openchannel --node_key <Carol's Identity Public Key> --connect <Carol's Node Ip Address>:9735 30000

    Mine at least three blocks to confirm the funding tx marking the channel as open:

    bitcoin-cli -generate 3
  3. Current Graph in the Network: first_use_case

Making a Payment from Alice through Bob to Carol

  1. Generate Invoice from Carol:

    lncli addinvoice 5000

    Obtain payment request from the response:

    {
     "r_hash": "11f0370839dacb202b1f1a54190461cc9049910ad431d0d7ddd9ff7cd348d8dd",
     "payment_request": "lnbcrt50u1pnpkh0qpp5z8crwzpemt9jq2clrf2pjprpejgynyg26scap47am8lhe56gmrwsdqqcqzzsxqyz5vqsp5gmc6l8zaq5m273mn5qmd4tgkvc5hk88ssaq8q3h7anntm0w5gefq9qyysgqxeksdq3hs896hpg3ke0e3qafn9hks82mvkathez4lnrc40jwntez6qkgx3d4dpvrz5ydak4g0zwsanzr7qxxje8wvr3sc3dp2eams7spx65x6r",
     "add_index": "1",
     "payment_addr": "46f1af9c5d0536af4773a036daad1666297b1cf087407046feece6bdbdd44652"
    }
  2. Pay Invoice from Alice:

    lncli payinvoice lnbcrt50u1pnpkh0qpp5z8crwzpemt9jq2clrf2pjprpejgynyg26scap47am8lhe56gmrwsdqqcqzzsxqyz5vqsp5gmc6l8zaq5m273mn5qmd4tgkvc5hk88ssaq8q3h7anntm0w5gefq9qyysgqxeksdq3hs896hpg3ke0e3qafn9hks82mvkathez4lnrc40jwntez6qkgx3d4dpvrz5ydak4g0zwsanzr7qxxje8wvr3sc3dp2eams7spx65x6r
  3. No Route Error after paying the invoice:

    Payment hash: 11f0370839dacb202b1f1a54190461cc9049910ad431d0d7ddd9ff7cd348d8dd
    Description:
    Amount (in satoshis): 5000
    Fee limit (in satoshis): 250
    Destination: 029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3
    Confirm payment (yes/no): yes
    +------------+--------------+--------------+--------------+-----+----------+----------+-------+
    | HTLC_STATE | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE | TIMELOCK | CHAN_OUT | ROUTE |
    +------------+--------------+--------------+--------------+-----+----------+----------+-------+
    +------------+--------------+--------------+--------------+-----+----------+----------+-------+
    Amount + fee:   0 + 0 sat
    Payment hash:   11f0370839dacb202b1f1a54190461cc9049910ad431d0d7ddd9ff7cd348d8dd
    Payment status: FAILED, reason: FAILURE_REASON_NO_ROUTE
    [lncli] FAILED
  4. Specify Outgoing Channel ID:

    Okay, So we should specify the first hop channel id in our case the outgoing channel id with Bob. We could get this using lncli listchannels command and search for the corresponding channel id in our case it would be 169324790743040.

  5. Repeat Payment:

    Pay the invoice again, ensuring the outgoing channel ID is specified.

    lncli payinvoice --outgoing_chan_id 169324790743040 lnbcrt50u1pnpkh0qpp5z8crwzpemt9jq2clrf2pjprpejgynyg26scap47am8lhe56gmrwsdqqcqzzsxqyz5vqsp5gmc6l8zaq5m273mn5qmd4tgkvc5hk88ssaq8q3h7anntm0w5gefq9qyysgqxeksdq3hs896hpg3ke0e3qafn9hks82mvkathez4lnrc40jwntez6qkgx3d4dpvrz5ydak4g0zwsanzr7qxxje8wvr3sc3dp2eams7spx65x6r
  6. Successful Payment:

    Now our payment went through returning back this response:

    Payment hash: 11f0370839dacb202b1f1a54190461cc9049910ad431d0d7ddd9ff7cd348d8dd
    Description:
    Amount (in satoshis): 5000
    Fee limit (in satoshis): 250
    Destination: 029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3
    Confirm payment (yes/no): yes
    +------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | HTLC_STATE | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE   | TIMELOCK | CHAN_OUT        | ROUTE      |
    +------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | SUCCEEDED  |        0.075 |        0.592 | 5000         | 1.005 |      332 | 169324790743040 | bob->carol |
    +------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    Amount + fee:   5000 + 1.005 sat
    Payment hash:   11f0370839dacb202b1f1a54190461cc9049910ad431d0d7ddd9ff7cd348d8dd
    Payment status: SUCCEEDED, preimage: 22e998c44efc6704fba9575d03cd6549eae43b87aa72bdb4c3edc03857e9ea48
  7. Report Payment Status to Mission Control:

    After we get payment result back we report the payment state to the mission control store (bolt db) and it updates the mission control persistent storage and its in-memory state.

  8. Query Mission Control:

    Run lncli querymc in the Alice sender node to check updated mission control data:

    {
     "pairs": [
         {
             "node_from": "02c60c3aea280fe7b161ba08722206a3fc6895fa4fb8c07ff68985a4bccb4992a4",
             "node_to": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
             "history": {
                 "fail_time": "0",
                 "fail_amt_sat": "0",
                 "fail_amt_msat": "0",
                 "success_time": "1713070997",
                 "success_amt_sat": "5001",
                 "success_amt_msat": "5001005"
             }
         },
         {
             "node_from": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
             "node_to": "029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3",
             "history": {
                 "fail_time": "0",
                 "fail_amt_sat": "0",
                 "fail_amt_msat": "0",
                 "success_time": "1713070997",
                 "success_amt_sat": "5000",
                 "success_amt_msat": "5000000"
             }
         }
     ]
    }
  9. Decoding Mission Query Response:

    a. The response we get is of type PairHistory.

    b. There are two pair histories: one for the payment from Alice (source vertex) to Bob, and the second for the payment from Bob to Carol (target_vertex).

    c. Notice that there are two HTLCs here: one between Alice and Bob, and the other between Bob and Carol. They must be fulfilled atomically—either all succeed or all fail, with no partial success. In our case, all succeeded.

    d. Additionally, note that the success_amt_sat in the first pair history between Alice and Bob is 5001, not 5000 as specified in the payment invoice by Carol. This difference is due to the configured routing fee for Bob, which is 1 satoshi, acting as an incentive to forward the payment.

  10. Repeat Invoice Creation:

    Generate another invoice from Carol with a different amount 5200 sats to figure out if success_amt_sat gets updated with the recent value i.e temporal locality or the new value must be greater than the current success_amt_sat value.

    lncli addinvoice 5200

    Obtain payment request from the response:

    {
    "r_hash": "241d2438dafc3baedf940b13d994cc4763f25ffb308ae6ef2c4d9f4b34b2f23d",
    "payment_request": "lnbcrt52u1pnpkugtpp5yswjgwx6lsa6ahu5pvfan9xvga3lyhlmxz9wdmevfk05kd9j7g7sdqqcqzzsxqyz5vqsp57xea7ydkrulzq9c35q5t5lapwd74qduhw243e7jlm0626g58u7rq9qyysgqvpvknjelaqytuk9awf2kyvr66m5fzycpy9n83t5kuatfvxwj96xrz3l43vxzqafglw0mvryu692rejdhf329rcc343hcp2fyujgr79sqvr0f88",
    "add_index": "4",
    "payment_addr": "f1b3df11b61f3e201711a028ba7fa1737d50379772ab1cfa5fdbf4ad2287e786"
    }
  11. Pay the new invoice:

    Pay the invoice again without the outgoing channel id since the route is already persisted:

    lncli payinvoice lnbcrt52u1pnpkugtpp5yswjgwx6lsa6ahu5pvfan9xvga3lyhlmxz9wdmevfk05kd9j7g7sdqqcqzzsxqyz5vqsp57xea7ydkrulzq9c35q5t5lapwd74qduhw243e7jlm0626g58u7rq9qyysgqvpvknjelaqytuk9awf2kyvr66m5fzycpy9n83t5kuatfvxwj96xrz3l43vxzqafglw0mvryu692rejdhf329rcc343hcp2fyujgr79sqvr0f88
  12. Successful Payment:

    Now our payment went through returning back this response:

    Payment hash: 241d2438dafc3baedf940b13d994cc4763f25ffb308ae6ef2c4d9f4b34b2f23d
    Description:
    Amount (in satoshis): 5200
    Fee limit (in satoshis): 260
    Destination: 029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3
    Confirm payment (yes/no): yes
    +------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | HTLC_STATE | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE   | TIMELOCK | CHAN_OUT        | ROUTE      |
    +------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | SUCCEEDED  |        0.202 |        1.825 | 5200         | 1.005 |      332 | 169324790743040 | bob->carol |
    +------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    Amount + fee:   5200 + 1.005 sat
    Payment hash:   241d2438dafc3baedf940b13d994cc4763f25ffb308ae6ef2c4d9f4b34b2f23d
    Payment status: SUCCEEDED, preimage: 49afed7761e183e7da2eed03cf3e842c585adae7d9e9b8a306267efdb6fee880
  13. Report Payment Status to Mission Control:

    After we get payment result back we report the payment state to the mission control store and updates its in-memory state like the previous example.

  14. Query Mission Control:

    Run lncli querymc in the Alice sender node to check updated mission control data:

    {
    "pairs": [
       {
             "node_from": "02c60c3aea280fe7b161ba08722206a3fc6895fa4fb8c07ff68985a4bccb4992a4",
             "node_to": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
             "history": {
                "fail_time": "0",
                "fail_amt_sat": "0",
                "fail_amt_msat": "0",
                "success_time": "1713074461",
                "success_amt_sat": "5201",
                "success_amt_msat": "5201005"
             }
       },
       {
             "node_from": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
             "node_to": "029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3",
             "history": {
                "fail_time": "0",
                "fail_amt_sat": "0",
                "fail_amt_msat": "0",
                "success_time": "1713074461",
                "success_amt_sat": "5200",
                "success_amt_msat": "5200000"
             }
       }
    ]
    }
  15. Decoding Mission Query Response:

    a. Observing Success Amount Satoshis: - We receive the highest success_amt_sat, not necessarily the most recent one. This observation is particularly relevant in cases of a Bimodal Statistical Distribution, where two local maximums (peaks) may occur.

    b. Documentation and Changes: - The highest value for the success_amt_sat field, along with its recent changes, is documented in the router.proto PairData message.

  16. Explore Route Probabilities:

    Query routes to Carol with different payment amounts to observe how success probabilities vary.

    lncli queryroutes --use_mc 029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3 5200

    We get response like this:

    {
    "routes": [
       {
             "total_time_lock": 329,
             "total_fees": "1",
             "total_amt": "5201",
             "hops": [
                {
                   "chan_id": "169324790743040",
                   "chan_capacity": "30000",
                   "amt_to_forward": "5200",
                   "fee": "1",
                   "expiry": 249,
                   "amt_to_forward_msat": "5200000",
                   "fee_msat": "1005",
                   "pub_key": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
                   "tlv_payload": true,
                   "mpp_record": null,
                   "amp_record": null,
                   "custom_records": {},
                   "metadata": "",
                   "blinding_point": "",
                   "encrypted_data": "",
                   "total_amt_msat": "0"
                },
                {
                   "chan_id": "172623325626368",
                   "chan_capacity": "30000",
                   "amt_to_forward": "5200",
                   "fee": "0",
                   "expiry": 249,
                   "amt_to_forward_msat": "5200000",
                   "fee_msat": "0",
                   "pub_key": "029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3",
                   "tlv_payload": true,
                   "mpp_record": null,
                   "amp_record": null,
                   "custom_records": {},
                   "metadata": "",
                   "blinding_point": "",
                   "encrypted_data": "",
                   "total_amt_msat": "0"
                }
             ],
             "total_fees_msat": "1005",
             "total_amt_msat": "5201005"
       }
    ],
    "success_prob": 0.9025
    }

Here's the restructured and simplified version:

  1. Decoding Routing Possibilities:

    a. Total Time Lock: - total_time_lock represents the cumulative (final) time lock across the entire route until all HTLCs are settled from the destination to the source.

    b. Total Fees and Hops: - total_fees is one satoshi, which is the routing fee advertised by Bob. - The hops include the first hop, which is the payment channel between Alice and Bob, and the second hop, which is the payment channel between Bob and Carol.

    c. Success Probability: - success_prob represents the probability of routing 5200 satoshis to Carol through Bob, based on previous history data. - Note: The probability is high in this case because the maximum payment amount we have is already 5200 satoshis, and anything less than or equal to 5200 would yield similar probabilities.

  2. Explore Route Probabilities with Different Payment Amount:

    Query routes to Carol with payment amount greater than 5200 sats to observe how success probabilities vary.

    lncli queryroutes --use_mc 029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3 5300
    

    We get response like this:

    {
    "routes": [
       {
             "total_time_lock": 329,
             "total_fees": "1",
             "total_amt": "5301",
             "hops": [
                {
                   "chan_id": "169324790743040",
                   "chan_capacity": "30000",
                   "amt_to_forward": "5300",
                   "fee": "1",
                   "expiry": 249,
                   "amt_to_forward_msat": "5300000",
                   "fee_msat": "1005",
                   "pub_key": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
                   "tlv_payload": true,
                   "mpp_record": null,
                   "amp_record": null,
                   "custom_records": {},
                   "metadata": "",
                   "blinding_point": "",
                   "encrypted_data": "",
                   "total_amt_msat": "0"
                },
                {
                   "chan_id": "172623325626368",
                   "chan_capacity": "30000",
                   "amt_to_forward": "5300",
                   "fee": "0",
                   "expiry": 249,
                   "amt_to_forward_msat": "5300000",
                   "fee_msat": "0",
                   "pub_key": "029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3",
                   "tlv_payload": true,
                   "mpp_record": null,
                   "amp_record": null,
                   "custom_records": {},
                   "metadata": "",
                   "blinding_point": "",
                   "encrypted_data": "",
                   "total_amt_msat": "0"
                }
             ],
             "total_fees_msat": "1005",
             "total_amt_msat": "5301005"
       }
    ],
    "success_prob": 0.5699999999999985
    }
  3. Decoding Routing Possibilities:

    a. Impact of Payment Amount on Success Probability: - The success probability of a payment significantly decreases when querying a route for a payment with an amount greater than 520 satoshis.

    b. Analysis of Failure Data in Mission Control: - When querying the mission control data, the fields related to payment failure are not set because our payment was successful. - However, to understand the effect of failure on the data fields, let's attempt to fail one of the HTLCs in the route and examine the values of those fields:

    "fail_time": "0",
    "fail_amt_sat": "0",
    "fail_amt_msat": "0",

Use Case 2 (Payment Failed - Multipart Payment (MPP) Timeout Error)

Setting Up Payment Channels

  1. Create Payment Channel from Alice to Bob:

    lncli openchannel --node_key <Bob's Identity Public Key> --connect <Bob's Node Ip Address>:9735 60000

    Mine at least three blocks to confirm the funding tx marking the channel as open:

    bitcoin-cli -generate 3
  2. Create Payment Channel from Bob to Carol:

    lncli openchannel --node_key <Carol's Identity Public Key> --connect <Carol's Node Ip Address>:9735 40000

    Mine at least three blocks to confirm the funding tx marking the channel as open:

    bitcoin-cli -generate 3
  3. Current Graph in the Network: second_use_case

Making a Payment from Alice through Bob to Carol

  1. Generate Invoice from Carol:

    lncli addinvoice 50000

    Obtain payment request from the response:

    {
        "r_hash": "fdb67053597cf8bfd66e5a3e28a41d7805adb4eeb86118ac68437f23eb38331b",
        "payment_request": "lnbcrt500u1pnphymapp5lkm8q56e0nutl4nwtglz3fqa0qz6md8whps33trggdlj86ecxvdsdqqcqzzsxqyz5vqsp5yq5xcl6nvr8g0umsgvpqq66uc92dgm75lfp3h23tg7984ayvu8xq9qyysgq0l5mznrce7xfgahq8raw0yg73vl6ekvz63x0a7muawvm858zyu887gpn6j83wxpq2gf5al3802u2eff7w4zy8k0rzpngdpw6wlhpdvspqqr6g0",
        "add_index": "8",
        "payment_addr": "20286c7f5360ce87f3704302006b5cc154d46fd4fa431baa2b478a7af48ce1cc"
    }
  2. Pay Invoice from Alice:

    lncli payinvoice lnbcrt500u1pnphymapp5lkm8q56e0nutl4nwtglz3fqa0qz6md8whps33trggdlj86ecxvdsdqqcqzzsxqyz5vqsp5yq5xcl6nvr8g0umsgvpqq66uc92dgm75lfp3h23tg7984ayvu8xq9qyysgq0l5mznrce7xfgahq8raw0yg73vl6ekvz63x0a7muawvm858zyu887gpn6j83wxpq2gf5al3802u2eff7w4zy8k0rzpngdpw6wlhpdvspqqr6g0
  3. No Route Error after paying the invoice:

    Payment hash: fdb67053597cf8bfd66e5a3e28a41d7805adb4eeb86118ac68437f23eb38331b
    Description:
    Amount (in satoshis): 50000
    Fee limit (in satoshis): 2500
    Destination: 029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3
    Confirm payment (yes/no): yes
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | HTLC_STATE                          | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE   | TIMELOCK | CHAN_OUT        | ROUTE      |
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | HTLC_STATE                          | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE   | TIMELOCK | CHAN_OUT        | ROUTE      |
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | IN_FLIGHT                           |        0.462 |            - | 25000        | 1.025 |      343 | 188016488415232 | bob->carol
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | HTLC_STATE                          | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE   | TIMELOCK | CHAN_OUT        | ROUTE      |
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | IN_FLIGHT                           |        0.462 |            - | 25000        | 1.025 |      343 | 188016488415232 | bob->carol
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | HTLC_STATE                          | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE   | TIMELOCK | CHAN_OUT        | ROUTE      |
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    | MPP_TIMEOUT @ 2nd hop               |        0.462 |      121.467 | 25000        | 1.025 |      343 | 188016488415232 | bob->carol |
    | TEMPORARY_CHANNEL_FAILURE @ 1st hop |        0.584 |        1.065 | 25000        | 1.025 |      343 | 188016488415232 | bob->carol |
    | TEMPORARY_CHANNEL_FAILURE @ 1st hop |        1.181 |        1.550 | 12500        | 1.012 |      343 | 188016488415232 | bob->carol |
    +-------------------------------------+--------------+--------------+--------------+-------+----------+-----------------+------------+
    Amount + fee:   0 + 0 sat
    Payment hash:   fdb67053597cf8bfd66e5a3e28a41d7805adb4eeb86118ac68437f23eb38331b
    Payment status: FAILED, reason: FAILURE_REASON_NO_ROUTE
    [lncli] FAILED
  4. Decoding No Route Error after Payment:

    a. The payment failed due to a capacity bottleneck in the payment channel between Bob and Carol, which has a capacity of 40,000 sats, smaller than the invoice amount of 50,000 sats from Carol.

    b. lnd attempted multipart payments to overcome this limitation. It divided the payment into two parts: 25,000 sats routed through the Alice-Carol channel and another 25,000 sats routed through the Bob-Carol channel.

    c. However, the multipart payment failed with a timeout error on the second payment channel between Bob and Carol.

  5. Report Payment Status to Mission Control:

    After we get payment result back we report the payment state to the mission control store and updates its in-memory state like the previous examples.

  6. Query Mission Control:

    Run lncli querymc in the Alice sender node to check updated mission control data after the failed payment:

    {
     "pairs": [
         {
             "node_from": "02c60c3aea280fe7b161ba08722206a3fc6895fa4fb8c07ff68985a4bccb4992a4",
             "node_to": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
             "history": {
                 "fail_time": "0",
                 "fail_amt_sat": "0",
                 "fail_amt_msat": "0",
                 "success_time": "1713083397",
                 "success_amt_sat": "25001",
                 "success_amt_msat": "25001025"
             }
         },
         {
             "node_from": "03dbd084631519fcaccfd3a72cad4a65f42d808b86b7e362629aa221d097cb0f71",
             "node_to": "029ab357867f95efd81d3cff3c043dcea8cb3f96db8f5754b1a4155a590f8d50f3",
             "history": {
                 "fail_time": "1713083277",
                 "fail_amt_sat": "25000",
                 "fail_amt_msat": "25000001",
                 "success_time": "1713083397",
                 "success_amt_sat": "25000",
                 "success_amt_msat": "25000000"
             }
         }
     ]
    }
  7. Decoding Mission Query Response:

    a. In the route from Alice to Bob, all HTLCs succeeded due to the sufficient payment channel capacity. The fail_time, fail_amt_sat, and fail_amt_msat fields remain zero. The success_amt_sat is updated to 25,000 sats, the peak value reached.

    b. Conversely, in the route from Bob to Carol, the multipart payment timed out due to insufficient channel capacity to route the full payment from Carol. Consequently, the fail_time and fail_amt_sat are updated to reflect the failure, with the success_amt_sat reaching its peak at 25,000 sats.

Importing Mission Control State

Importing Mission Control State Feature was implemented in this PR routing: add mission control import rpc.

Cold Cache vs Hot Cache

Cold Cache: When the cache is empty or has irrelevant data, so that CPU needs to do a slower read from main memory for your program data requirement. Operating with a cold cache can result in suboptimal routing decisions and potentially longer pathfinding times because the system needs to rebuild its memory of past routing decisions and channel performance metrics. This rebuilding process can take time and may lead to timeouts during pathfinding attempts, particularly if users have strict time limits for their operations. Example wallets are Blixt.

Hot cache: When the cache contains relevant data, and all the reads for your program are satisfied from the cache itself. It is used in Lightning Network to reduce the search space since we avoid channels with failed payments or in effective routes for example.

Import MC state using importmc

We could import the mission control state to in-memory intenral repsentation (yet) using the following command:

lncli importc [source node] [dest node] [unix ts seconds] [amount in msat]

How Import Mission Control State function works

import_mc

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