RGB-Tools / rgb-lightning-node

MIT License
17 stars 19 forks source link

Channels disappearing after paying invoice (no errors in logs) #33

Closed gofman8 closed 1 month ago

gofman8 commented 1 month ago

Issue 2 : Channels disappearing

Preparing

Run nodes A,B,C

Run nodes A,B,C call /init & /unlock for each node.

Send BTC to Nodes

Run the following command on your server:

./regtest.sh sendtoaddress <address> <amount>

Example:

./regtest.sh sendtoaddress bcrt1qnc5y6j6dmejrkwy93farhvpezk0lf46gk7aecs 10

then

./regtest.sh mine 10

do it for A, B, C

Node B:

1. Issue TUSD asset (200 tokens) (RGB on-chain API)

1.1 Create Asset

Call the /createutxos endpoint:

{
  "up_to": false,
  "num": 4
}

Call the /issueassetnia endpoint with the following example body:

{
  "amounts": [200],
  "ticker": "USDT",
  "name": "Tether",
  "precision": 0
}

Node C calls /lninvoice (25 assets) Request:

{
  "amt_msat": 3000000,
  "expiry_sec": 620,
  "asset_id": "rgb:2Fy9jVd-4BCGgtPXi-wFcrAHqrD-ADBQQBKbt-cDKA7LA5y-wiuHGJT",
  "asset_amount": 25
}

Response:

{
  "invoice": "lnbcrt30u1pnglx76dqud3jxktt5w46x7unfv9kz6mn0v3jsnp4qvn3mjjxajhe5h066vyx7434cc4g2lqxu78237z03fwf9f7m23lx6pp5va66hvdzhcrljac95622ve3k20av7dhu7y8yf88l2j35fj0umk6ssp5kdllclg8s2g0wfrjnrrvhwapetzcc9wrtxwswfhjq4cu4u4vy3as9qyysgqcqpcxqznvlzlwfnkyw3jgeunj6jkvskngsjrganhg5zcdykhw3nrwfq5sutjgsk5z3zz29g5yjmzwskkx3ztgym5csf40ykhw6t4fpr554q7qpen0f0t7svud94rk3ajfvj95r98wsvujgvvz87zn86434h534mrcl5pstn30j22jx3zg88hcpzyjllfcmzk7htg0n3u059jhkxpds56eqq8ja9dg"
}

Node A sends the payment (/sendpayment)

Request:

{
  "invoice": "lnbcrt30u1pnglx76dqud3jxktt5w46x7unfv9kz6mn0v3jsnp4qvn3mjjxajhe5h066vyx7434cc4g2lqxu78237z03fwf9f7m23lx6pp5va66hvdzhcrljac95622ve3k20av7dhu7y8yf88l2j35fj0umk6ssp5kdllclg8s2g0wfrjnrrvhwapetzcc9wrtxwswfhjq4cu4u4vy3as9qyysgqcqpcxqznvlzlwfnkyw3jgeunj6jkvskngsjrganhg5zcdykhw3nrwfq5sutjgsk5z3zz29g5yjmzwskkx3ztgym5csf40ykhw6t4fpr554q7qpen0f0t7svud94rk3ajfvj95r98wsvujgvvz87zn86434h534mrcl5pstn30j22jx3zg88hcpzyjllfcmzk7htg0n3u059jhkxpds56eqq8ja9dg"
}

Response:

{
  "payment_hash": "6775abb1a2be07f97705a694a6663653facf36fcf10e449cff54a344c9fcddb5",
  "payment_secret": "b37ffc7d078290f7247298c6cbbba1cac58c15c3599d0726f20571caf2ac247b",
  "status": "Pending"
}

Node Issues

After these steps, something went wrong:

Node B /listchannels returns

{
  "channels": []
}
{
  "payments": [
    {
      "amt_msat": 3000000,
      "asset_amount": 25,
      "asset_id": "rgb:2Fy9jVd-4BCGgtPXi-wFcrAHqrD-ADBQQBKbt-cDKA7LA5y-wiuHGJT",
      "payment_hash": "52ab482fc272abf3c894f78cc4fcc6aacdabafa152ab66fae199d24658720401",
      "inbound": true,
      "status": "Succeeded"
    },
    {
      "amt_msat": 3000000,
      "asset_amount": 25,
      "asset_id": "rgb:2Fy9jVd-4BCGgtPXi-wFcrAHqrD-ADBQQBKbt-cDKA7LA5y-wiuHGJT",
      "payment_hash": "6775abb1a2be07f97705a694a6663653facf36fcf10e449cff54a344c9fcddb5",
      "inbound": false,
      "status": "Pending"
    }
  ]
}

node C /listpayments

{
  "payments": [
    {
      "amt_msat": 3000000,
      "asset_amount": 25,
      "asset_id": "rgb:2Fy9jVd-4BCGgtPXi-wFcrAHqrD-ADBQQBKbt-cDKA7LA5y-wiuHGJT",
      "payment_hash": "6775abb1a2be07f97705a694a6663653facf36fcf10e449cff54a344c9fcddb5",
      "inbound": true,
      "status": "Pending"
    }
  ]
}

It seems no errors in logs just some warnings

Warning, failed to broadcast a transaction, this is likely okay but may indicate an error: RPC error -26: non-mandatory-script-verify-flag (Witness program was passed an empty witness)
bandrivskiy commented 1 month ago

some clarification, also tried to reproduce this issue with two nodes, this case should be easier to reproduce

Steps to Reproduce

  1. Run Two Nodes

  2. Issue 200 Assets on Node A /issueassetnia

  3. Open Channel with Node B /openchannel 50 assets

  4. Check Asset Balance

Node A

{
  "settled": 200,
  "future": 150,
  "spendable": 0,
  "offchain_outbound": 50,
  "offchain_inbound": 0
}

Node B

{
  "settled": 0,
  "future": 0,
  "spendable": 0,
  "offchain_outbound": 0,
  "offchain_inbound": 50
}
  1. Create Invoice on Node B for 25 Assets /lninvoice

  2. Pay the Invoice from Node A /sendpayment

Result

The channel disappears after the payment. Here are the updated balances:

/listchannels

{
  "channels": []
}

Node A

{
  "settled": 150,
  "future": 150,
  "spendable": 150,
  "offchain_outbound": 0,
  "offchain_inbound": 0
}

Node B

{
  "settled": 0,
  "future": 0,
  "spendable": 0,
  "offchain_outbound": 0,
  "offchain_inbound": 0
}

Payment Details

{
  "payments": [
    {
      "amt_msat": 3000000,
      "asset_amount": 25,
      "asset_id": "rgb:Vhjv2DL-u2jGJ6uMU-3SxKf1QPv-igCpbD4Mt-VoR7CWtuK-TeTKgt",
      "payment_hash": "a493ffba0fd3196e0d59ae6d6c7d627f21723c6f76ff8e520a712f39b32b2213",
      "inbound": true,
      "status": "Succeeded"
    }
  ]
}
cymqqqq commented 1 month ago

I think maybe the channels you opened have closed(Because the transaction between the state channels is finished), and then the transaction sent to the regtest network, so the status changed to Succeeded, and the channels are disappeared.

gofman8 commented 1 month ago

I think maybe the channels you opened have closed(Because the transaction between the state channels is finished), and then the transaction sent to the regtest network, so the status changed to Succeeded, and the channels are disappeared.

Could you please explain this with more details? We are doing off-chain transaction only, I though the only way to close the channel it's to initiate channel closing by one on the counterparty. So it's happening by protocol design? where I can read about this?

zoedberg commented 1 month ago

@gofman8 @bandrivskiy We are trying to reproduce this with a test but the nodes are not behaving as you reported. Could you please provide the data directories of the nodes? Also, could you confirm you're doing this on a Linux machine and maybe provide more info on the system that's running this?

gofman8 commented 1 month ago

@zoedberg Issue has been resolved! Many thanks for your feedback, it was critical to identify the issue. The problem was because of docker specific, we launch RLN process with the following parameter: --ldk-peer-listening-port 9735 but actual port though which nodes connected was different: containerPort = 9735 but hostPort = min(65535, 9000 + tonumber(each.value)). We believe because of this mismatch channels were force closed with the following LDK error: HTLCTimedOut

Now everything works as expected. Closed. Many thanks for your feedback!