lightninglabs / taproot-assets

A layer 1 daemon, for the Taproot Assets Protocol specification, written in Go (golang)
MIT License
457 stars 110 forks source link

[bug]: Invoice pay fails if multiple channels of same asset present #1111

Closed vanditshah99 closed 1 week ago

vanditshah99 commented 2 weeks ago

Background

Your environment

tapcli getinfo            
{
    "version": "0.4.1-alpha commit=v0.4.2-0.20240824000229-881ecafbeae1",
    "lnd_version": "0.18.0-beta",
    "network": "mainnet",
    "lnd_identity_pubkey": "036280ce2a8346991c39fd616d2c8693017f073709f38f3c5eaa39891e40cb2ab9",
    "node_alias": "speed3",
    "block_height": 858673,
    "block_hash": "00000000000000000002b5eda69ec783b4ad48bddcf11ed2aa6ebb02c111a6a6",
    "sync_to_chain": true
}
uname -mrsv             
Linux 6.5.0-1023-aws #23~22.04.1-Ubuntu SMP Fri Jun 21 19:23:45 UTC 2024 x86_64
bitcoind --version || btcd --version 
Bitcoin Core version v23.0.0

Steps to reproduce

Multi-Hop Payment, where there is a sender having multiple assets channel for the same asset with the peer. We tried the following command

10a3ebc80a54:/src# litcli -n mainnet --macaroonpath /root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon ln payinvoice --pay_req lnbc8500n1pnvuzdkpp5nafv4gj627rg4j6whjv7vhuunfu8d7xl609k86xqfaf9v5n6xmpqdqqcqzzsxqzfvrzjqd3gpn32sdrfj8pel4sk6tyxjvqh7pehp8ec70z74gucj8jqev4tnmpt2a376mef0uqqqqlgqqqqqqgq2qsp588nzkrn75e9q5m857alwq7wzs2kzg4p8a2855dl620clm8at4faq9qxpqysgqy0zaty5lc9ceapfgyfc6xq334vxqucv7sphtdmvry3xlkkezytk57ugtje355hyjnzmz4gzpwu3cvjgjlzk75ddjd5mswf7wheg0npsq9w2zgs --asset_id d75dae162be7cd0a2df76831ee1cce4eaeb74a32fabb0d46be7a0ad70fd6ad27 --rfq_peer_pubkey 036280ce2a8346991c39fd616d2c8693017f073709f38f3c5eaa39891e40cb2ab9
Payment hash: 9f52caa25a57868acb4ebc99e65f9c9a7876f8dfd3cb63e8c04f5256527a36c2
Description:
Amount (in satoshis): 850
Fee limit (in satoshis): 850
Destination: 038dbb70e3484da0bed806156f5270d39b480a659c82fb4b56ba3dcbe0edd74d55
Confirm payment (yes/no): yes
[litcli] rpc error: code = Unknown desc = error finding asset channel to use: multiple asset channels found for asset d75dae162be7cd0a2df76831ee1cce4eaeb74a32fabb0d46be7a0ad70fd6ad27, please specify the peer pubkey

Also, we tried passing the channel id as well

30e2309a2405:/# litcli -n mainnet --macaroonpath /root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon ln payinvoice --pay_req lnbc8500n1pnvupv7pp57l4qq48fal8x5v0dh2e97jltdxhkg2qnhnf4jg7vzhmrew50lfksdqqcqzzsxqzfvrzjqd3gpn32sdrfj8pel4sk6tyxjvqh7pehp8ec70z74gucj8jqev4tnuyuj4yq5x2xc5qqqqlgqqqqqqgq2qsp5tek4zwvcg4dc6e2trcm62zyhre8f8lxtepc8dvvjkskt0dkjkh0q9qxpqysgqpx4c3djcut3fpmzemjxwq95kv9sukz5lklp4h4rqdjxpqf84qu3z74mxa3z8vh2jzmkvexxtljz4g2peff4hu7nen57fdfxl9vk344qptcx3h5 --asset_id d75dae162be7cd0a2df76831ee1cce4eaeb74a32fabb0d46be7a0ad70fd6ad27 --rfq_peer_pubkey 036280ce2a8346991c39fd616d2c8693017f073709f38f3c5eaa39891e40cb2ab9 --outgoing_chan_id 944094559833423872
Payment hash: f7ea0054e9efce6a31edbab25f4beb69af642813bcd35923cc15f63cba8ffa6d
Description:
Amount (in satoshis): 850
Fee limit (in satoshis): 850
Destination: 0223dd7404e46eab4fd289f023d6ce338e1eb1cce66b20b10accfd11d5e028b6b5
Confirm payment (yes/no): yes
[litcli] rpc error: code = Unknown desc = error finding asset channel to use: multiple asset channels found for asset d75dae162be7cd0a2df76831ee1cce4eaeb74a32fabb0d46be7a0ad70fd6ad27, please specify the peer pubkey

Expected behavior

This invoice should be paid through, auto selection of channel, and if outgoing chan id is passed, It shouldn't restrict and try using that channel

Actual behavior

It fails with the following error

Unknown desc = error finding asset channel to use: multiple asset channels found for asset d75dae162be7cd0a2df76831ee1cce4eaeb74a32fabb0d46be7a0ad70fd6ad27, please specify the peer pubkey
Roasbeef commented 2 weeks ago

Related to: https://github.com/lightninglabs/taproot-assets/issues/1085

vanditshah99 commented 2 weeks ago

Comment is edited

Roasbeef commented 2 weeks ago

Adding some more context here:

This is a known existing gap due to this logic: https://github.com/lightninglabs/taproot-assets/blob/30e71665dddd23599eedb39e3caf3b057279ca03/rpcserver.go#L7291-L7297

Setting rfq_peer_pubkey does help with the issue referenced above, but in this case it appears that there're two channels with the same asset ID to the same node, which causes the check above to fail.

I think one solution here would be to just select one of the channels, the one that has the highest local balance that can satisfy the payment. We only need to extract the peer pubkey, and an amt for the max asset unit: https://github.com/lightninglabs/taproot-assets/blob/30e71665dddd23599eedb39e3caf3b057279ca03/rpcserver.go#L6896-L6899

We should be able to reproduce this with an itest by creating the scenario of two channels w/ the same asset ID to a single node, with one node paying an invoice created by another.

jharveyb commented 2 weeks ago

I think this is actually a simpler issue in this case, where the CLI cmd is a bit off and not propagating the peer pubkey.

One place I see a gap is the handling of outgoing_chan_id; AFAICT right now that gets passed through to LND without any special handling by tapd. I think this should be added as a filter to rfqChannel() so that the user could select a specific channel with a peer.

Otherwise, a specific channel is selected by the output of rfqChannel() before that argument is ever handled.

dstadulis commented 1 week ago

Notes:

Will the code pick from two different channels? Enumerate a testing scenario between two or three peers.

Roasbeef commented 1 week ago

Fixed by https://github.com/lightninglabs/lightning-terminal/pull/838