lightningdevkit / rust-lightning

A highly modular Bitcoin Lightning library written in Rust. It's rust-lightning, not Rusty's Lightning!
Other
1.14k stars 357 forks source link

CLN uses in-flight limits to decide if a channel meets their min-size, rejecting their own channel opens when we set in-flight limits to < 100% #1132

Closed TheBlueMatt closed 1 week ago

TheBlueMatt commented 2 years ago

Got a channel open from a rando node which it didn't like our accept_channel parameters. I'm not 100% sure on the error message, but it looks like its mad that the max_htlc_value_in_flight_msat is the full channel, and not the channel - the two reserve values. Doesn't seem like there's any harm in just substracting the reserve values so we should do that.

2021-10-18 03:53:10.207 TRACE [lightning::ln::peer_handler:1051] Received message OpenChannel(OpenChannel { chain_hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, temporary_channel_id: [163, 209, 130, 20, 25, 132, 18, 77, 193, 174, 219, 170, 211, 28, 87, 30, 43, 245, 103, 15, 41, 251, 201, 19, 62, 253, 43, 207, 131, 186, 81, 183], funding_satoshis: 591000, push_msat: 0, dust_limit_satoshis: 546, max_htlc_value_in_flight_msat: 18446744073709551615, channel_reserve_satoshis: 5910, htlc_minimum_msat: 0, feerate_per_kw: 253, to_self_delay: 144, max_accepted_htlcs: 30, funding_pubkey: PublicKey(4c19a18c570d0ecb9474a4cc465fd35b37ee95f62b9dab022e65d07565b0cbd9edd8eaa8b5f141a57e74cb29d6f68b608a36ba81fff7f9f924550ce69ffb48c0), revocation_basepoint: PublicKey(ed1c2a37472e7517d788a1eb5c774b46a8c04b8e5cd11481a3f70b093a042e2f735108c59595ec7a43aa3047785d979a41d882fe62eb6e0d93aee27baac62b8e), payment_point: PublicKey(f267c941a73172b5eb96e0c69ed3ddba4e8b8e7027b6da9b2fadc6a42dc659f040bbc7d653f00dd90fbaa40c9c719a8cd5bfc98832279549a59b25bf203bf6ba), delayed_payment_basepoint: PublicKey(52bbe1af0465a677aed2b8eaf4192f380e9199f5971d3e097463ffaf34e585ae7a74b6def2599e9bead5bb93eafc33e595969625bd1ebcd7b0d353fef3373e0a), htlc_basepoint: PublicKey(8007459cb4739c452d55f0ea41fbd17ea363573359e73b37966c9cc39d273b53d82d9d141b395e2b5c0665a20e52df02972b459fca2380ad9b6fbc5f20b00d23), first_per_commitment_point: PublicKey(24ec754221e019dc067dea23d38b10406adfd856a34a7d81b104071782f0786c77b8a2a6ddfe8d3b7a91ab10102760c6eda2cb477e5c58deb16393ddf2db3b22), channel_flags: 1, shutdown_scriptpubkey: Present(Script()) }) from 03a219ba0d2614168aa1876a73c2f4e3af582b5feac98496af3183a13b3974c46e
2021-10-18 03:53:10.261 TRACE [lightning_background_processor:225] Persisting ChannelManager...
2021-10-18 03:53:10.261 DEBUG [lightning::ln::peer_handler:1343] Handling SendAcceptChannel event in peer_handler for node 03a219ba0d2614168aa1876a73c2f4e3af582b5feac98496af3183a13b3974c46e for channel a3d182141984124dc1aedbaad31c571e2bf5670f29fbc9133efd2bcf83ba51b7
2021-10-18 03:53:10.261 TRACE [lightning::ln::peer_handler:809] Enqueueing message AcceptChannel { temporary_channel_id: [163, 209, 130, 20, 25, 132, 18, 77, 193, 174, 219, 170, 211, 28, 87, 30, 43, 245, 103, 15, 41, 251, 201, 19, 62, 253, 43, 207, 131, 186, 81, 183], dust_limit_satoshis: 354, max_htlc_value_in_flight_msat: 59100000, channel_reserve_satoshis: 5910, htlc_minimum_msat: 1, minimum_depth: 6, to_self_delay: 144, max_accepted_htlcs: 50, funding_pubkey: PublicKey(24627e24adedd44feb934c6df3362400dfc8b82c665190f22c0788b345a160b38fab2ec675272763fa71931e2c82897d2f67048d9f656a7eba5b755ecfeba5ed), revocation_basepoint: PublicKey(a87fa311c088ee5e17059ed69a60a72bb3b48e48bf86e6c8efa308647989ede5bda3aab4c2fbac227e1909458a4db51a19ce200510bb2ed1c493ac52c1f1a23b), payment_point: PublicKey(9f000c94206bd697a7f60be290a56decb00504336de8e698177de9755b0c81a8d848f5f60f1b7f883e2f9aedd882f0b2bc22fad7e986b523503e545bca39607c), delayed_payment_basepoint: PublicKey(14921637086191906d0f4598f38cdd769b60fa5758f00b28579fe8ab7f8b3f57fd228bf9d2706c9e1897faf4b5389662ae243991706d029de528b00dc904b85a), htlc_basepoint: PublicKey(ea942706e814b5786cf31f6926dc77fcc82535e9b40a2e7c3590d50a384a9b3d9d7e6c6f842b1a962636e53b08480400005b5a91e618383c8e598e324ffd6a8d), first_per_commitment_point: PublicKey(617587f5b07a07a52d75d4f602438df4544b3af94da537156d8a99119aee9ee0309fd8a256aaad9527c110c5f07734a370641b7f81471d38f1735bc4c32bb7a8), shutdown_scriptpubkey: Present(Script(OP_0 OP_PUSHBYTES_20 a20f92037eb14943f092631165c3d5f2deea152a)) } to 03a219ba0d2614168aa1876a73c2f4e3af582b5feac98496af3183a13b3974c46e
2021-10-18 03:53:10.465 TRACE [lightning::ln::peer_handler:1051] Received message Error(ErrorMessage { channel_id: [163, 209, 130, 20, 25, 132, 18, 77, 193, 174, 219, 170, 211, 28, 87, 30, 43, 245, 103, 15, 41, 251, 201, 19, 62, 253, 43, 207, 131, 186, 81, 183], data: "You gave bad parameters: channel capacity with funding 591000sat, reserves 5910sat/5910sat, max_htlc_value_in_flight_msat is 59100000msat, channel capacity is 59100sat, which is below 2000000000msat" }) from 03a219ba0d2614168aa1876a73c2f4e3af582b5feac98496af3183a13b3974c46e
tnull commented 2 years ago

So, if I'm not mistaken this can be done by subtracting the two reserve values in get_holder_max_htlc_value_in_flight_msat (see https://github.com/rust-bitcoin/rust-lightning/blob/main/lightning/src/ln/channel.rs#L608).

However, while our reserve value can be retrieved by calling get_holder_selected_channel_reserve_satoshis, I believe the counterparty's reserve value is only known after we received a corresponding AcceptChannel message? This might be an issue since get_holder_max_htlc_value_in_flight_msat is called before that, e.g., when a OpenChannel message is constructed. So, might subtracting only our reserve value (or twice) be an option?

TheBlueMatt commented 2 years ago

So, if I'm not mistaken this can be done by subtracting the two reserve values in get_holder_max_htlc_value_in_flight_msat (see https://github.com/rust-bitcoin/rust-lightning/blob/main/lightning/src/ln/channel.rs#L608).

Yep, basically.

However, while our reserve value can be retrieved by calling get_holder_selected_channel_reserve_satoshis, I believe the counterparty's reserve value is only known after we received a corresponding AcceptChannel message? This might be an issue since get_holder_max_htlc_value_in_flight_msat is called before that, e.g., when a OpenChannel message is constructed. So, might subtracting only our reserve value (or twice) be an option?

Ah, good point, maybe I misinterpreted their error?

Looking at it again, I wonder if they're just confusing themselves - the end of the message "channel capacity is 59100sat, which is below 2000000000msat" seems to imply that they have configured a minimum channel value of 2 million sats. This would simply imply that they're simply opening a channel that they don't want to accept.

Google seems to think the error message format comes from c-lightning, so I've asked over there https://github.com/ElementsProject/lightning/issues/4873.

Maybe not worth doing anything here until we get a response.

tnull commented 3 weeks ago

Seems users are still hitting this: https://github.com/fedimint/fedimint/issues/5880

TheBlueMatt commented 1 week ago

Right, this seems like just a CLN issue that we can't do anything about. Closing as they need to fix it.