ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.81k stars 887 forks source link

Broadcast failure on 0 conf channel still considers the channel okay. #6291

Open TonyGiorgio opened 1 year ago

TonyGiorgio commented 1 year ago

Issue and Steps to Reproduce

  1. fundchannel and get this weird broadcast error for no logical reason
  2. Proceed to make payments down the channel despite the funding transaction not existing

This will result in loss of funds for the other peer once it closes. There's no attempt to rebroadcast the transaction or mark the channel as invalid despite the failure to the fundchannel rpc.

After awhile when I noticed this, I broadcasted the transaction hex manually. I don't see any reason why it was getting the obscure broadcast error. But regardless, it should not consider the channel valid if the RPC fails.

Error funding channel: Error code -1: Error broadcasting transaction: error code: -26\nerror message:\ninsufficient fee, 
rejecting replacement 43e2bce5eb841c5e1f0015e9f384ab3a00973e7497489ac8f5019224aea1061b; 
new feerate 0.00001006 BTC/kvB <= old feerate 0.00001006 BTC/kvB. Unsent tx discarded 
02000000000101b4d49e3549ce6315b26b54aee70e343fd319cd35b1014aa5a3b8b9819074b7ae0100000000fdffffff022aa80100000000002200202dabae629c4d22a855ac0ec141186822f0614526634107b3491454aaffc55d171ab1a90200000000160014df33f307bbd72856e6223a92abb309c61a9dbb470247304402207cfa2be8cb24d847af395abf68c2fd9d4844f72113001f413efedb24860daab502207d457a003695a9be950cadf9fe3e488bd9345d8bc4220312078d2aa586c2503f012102514dd76c814f90b38ce44865b2e137d364ad12b7fba45db19e4fb47c2119283732b60100    

getinfo output

{
   "id": "0366abc8eb4da61e31a8d2c4520d31cabdf58cc5250f855657397f3dd62493938a",
   "alias": "GREENFELONY",
   "color": "0366ab",
   "num_peers": 227,
   "num_pending_channels": 2,
   "num_active_channels": 385,
   "num_inactive_channels": 0,
   "address": [
      {
         "type": "ipv4",
         "address": "45.33.17.66",
         "port": 39735
      }
   ],
   "binding": [
      {
         "type": "ipv4",
         "address": "45.33.17.66",
         "port": 39735
      }
   ],
   "version": "96974a6",
   "blockheight": 112317,
   "network": "signet",
   "fees_collected_msat": 135099,
   "lightning-dir": "/home/lsp/.lightning/signet",
   "our_features": {
      "init": "08a000080a69a2",
      "node": "88a000080a69a2",
      "channel": "",
      "invoice": "02000000024100"
   }
}
lsp@localhost:~$ lightning-cli --network signet listpeers | grep 03e51181b543dd8247a2ce41f748eb52b9306352b160ad5709f8bec5f8ad1b2b00 -A 100                                                                                                                                                                                                   [59/1769]
         "id": "03e51181b543dd8247a2ce41f748eb52b9306352b160ad5709f8bec5f8ad1b2b00",                                                                                                                                                                                                                                                                  
         "connected": true,                                                                                                                                                                                                                                                                                                                           
         "netaddr": [                                                                                                                                                                                                                                                                                                                                 
            "173.255.194.162:36550"                                                                                                                                                                                                                                                                                                                   
         ],                                                                                                                                                                                                                                                                                                                                           
         "remote_addr": "45.33.17.66:39735",                                                                                                                                                                                                                                                                                                          
         "features": "08a000080a5122",                                                                                                                                                                                                                                                                                                                
         "channels": [                                                                                                                                                                                                                                                                                                                                
            {                                                                                                                                                                                                                                                                                                                                         
               "state": "CHANNELD_NORMAL",                                                                                                                                                                                                                                                                                                            
               "scratch_txid": "a1d12354539bf18879c386738485898df88ea70f536495b1069f14ae9cf4ef7d",                                                                                                                                                                                                                                                    
               "last_tx_fee_msat": 183000,                                                                                                                                                                                                                                                                                                            
               "feerate": {                                                                                                                                                                                                                                                                                                                           
                  "perkw": 253,                                                                                                                                                                                                                                                                                                                       
                  "perkb": 1012                                                                                                                                                                                                                                                                                                                       
               },                                                                                                                                                                                                                                                                                                                                     
               "owner": "channeld",                                                                                                                                                                                                                                                                                                                   
               "direction": 0,                                                                                                                                                                                                                                                                                                                        
               "channel_id": "1b06a1ae249201f5c89a4897743e97003aab84f3e915001f5e1c84ebe5bce243",                                                                                                                                                                                                                                                      
               "funding_txid": "43e2bce5eb841c5e1f0015e9f384ab3a00973e7497489ac8f5019224aea1061b",                                                                                                                                                                                                                                                    
               "funding_outnum": 0,                                                                                                                                                                                                                                                                                                                   
               "close_to_addr": "tb1q2q0uypucuntgzy4jcg0cmvlulv7f2pg7f4affm",                                                                                                                                                                                                                                                                         
               "close_to": "0014501fc20798e4d68112b2c21f8db3fcfb3c95051e",                                                                                                                                                                                                                                                                            
               "private": true,                                                                                                                                                                                                                                                                                                                       
               "opener": "local",                                                                                                                                                                                                                                                                                                                     
               "alias": {                                                                                                                                                                                                                                                                                                                             
                  "local": "11922873x5380645x44435",                                                                                                                                                                                                                                                                                                  
                  "remote": "107248x888x7"                                                                                                                                                                                                                                                                                                            
               },                                                                                                                                                                                                                                                                                                                                     
               "features": [                                                                                                                                                                                                                                                                                                                          
                  "option_static_remotekey"                                                                                                                                                                                                                                                                                                           
               ],                                                                                                                                                                                                                                                                                                                                     
               "funding": {                                                                                                                                                                                                                                                                                                                           
                  "local_funds_msat": "108586000msat",                                                                                                                                                                                                                                                                                                
                  "remote_funds_msat": "0msat",                                                                                                                                                                                                                                                                                                       
                  "pushed_msat": 0                                                                                                                                                                                                                                                                                                                    
               },                                                                                                                                                                                                                                                                                                                                     
               "to_us_msat": 101086000,                                                                                                                                                                                                                                                                                                               
               "min_to_us_msat": 101086000,                                                                                                                                                                                                                                                                                                           
               "max_to_us_msat": 108586000,                                                                                                                                                                                                                                                                                                           
               "total_msat": 108586000,                                                                                                                                                                                                                                                                                                               
               "fee_base_msat": 1,                                                                                                                                                                                                                                                                                                                    
               "fee_proportional_millionths": 10,                                                                                                                                                                                                                                                                                                     
               "dust_limit_msat": 546000,                                                                                                                                                                                                                                                                                                             
               "max_total_htlc_in_msat": 18446744073709551615,                                                                                                                                                                                                                                                                                        
               "their_reserve_msat": 1085000,                                                                                                                                                                                                                                                                                                         
               "our_reserve_msat": 1085000,                                                                                                                                                                                                                                                                                                           
               "spendable_msat": 99461000,                                                                                                                                                                                                                                                                                                            
               "receivable_msat": 6415000,                                                                                                                                                                                                                                                                                                            
               "minimum_htlc_in_msat": 0,                                                                                                                                                                                                                                                                                                             
               "minimum_htlc_out_msat": 1,                                                                                                                                                                                                                                                                                                            
               "maximum_htlc_out_msat": 107501000,                                                                                                                                                                                                                                                                                                    
               "their_to_self_delay": 6,                                                                                                                                                                                                                                                                                                              
               "our_to_self_delay": 144,                                                                                                                                                                                                                                                                                                              
               "max_accepted_htlcs": 483,                          
               "state_changes": [                                                    
                  {                                                                  
                     "timestamp": "2023-05-29T21:56:00.453Z",
                     "old_state": "CHANNELD_AWAITING_LOCKIN",
                     "new_state": "CHANNELD_NORMAL",
                     "cause": "user",                                                
                     "message": "Lockin complete"
                  }                                                                  
               ],                                                                    
               "status": [                                                           
                  "CHANNELD_NORMAL:Reconnected, and reestablished.",
                  "CHANNELD_NORMAL:Channel ready for use."
               ],                                                                    
               "in_payments_offered": 0,                                             
               "in_offered_msat": 0,                                                 
               "in_payments_fulfilled": 0,
               "in_fulfilled_msat": 0,                                               
               "out_payments_offered": 1,                                            
               "out_offered_msat": 7500000,
               "out_payments_fulfilled": 1,
               "out_fulfilled_msat": 7500000,
               "htlcs": []                                                           
            } 

https://mutinynet.com/tx/43e2bce5eb841c5e1f0015e9f384ab3a00973e7497489ac8f5019224aea1061b

vincenzopalazzo commented 1 year ago

Mh this stage, so in this issue there is two sub-issue:

vincenzopalazzo commented 1 year ago

Mh! ok looks like our multi-funding channel RPC is a chain of callback, so the error is through by Bitcoin core not core lightning,

Core lightning cannot backtrack during the error and update remove the channel from the listfunds. The channel should never be open because the funding transaction died before,

So no funding lost. But I should spend more time debugging it this week.

TonyGiorgio commented 1 year ago

So no funding lost

Funds were lost, because the funding transaction was never broadcasted on the 0 conf channel.

vincenzopalazzo commented 1 year ago

Ah right we are in a 0-conf, my bad :)

frnandu commented 2 months ago

Was minconf=0 used when opening the 0 conf channel? We're having similar problem at Alby with 0 conf channels when using minconf=0