Open dangeross opened 2 years ago
a service that receives an out-of-band channel request and, when a user hops an invoice through our node it holds the intercepted HTLC, creates a zero-conf channel, then resumes the HTLC to the user
A compelling flow! Hope this design is developed.
I don't know if there is a log / event you could look for, but a way to check if the channel is ready could be to retry a probe payment with the routerrpc.SendPayment
api e.g.
&routerrpc.SendPaymentRequest{
PaymentHash = // some random payment hash
TimoutSeconds = // some sane time to wait for
Amt = // whatever amount you need
Dest = // pubkey of peer
OutgoingChanIds = // chanid of new channel
}
If this succeeds, resuming the htlc might work.
I don't think anything needs to change here, the database state of the channel has went from "pending open" to "open". Your peer hasn't sent you a FundingLocked message, meaning you haven't added the ChannelUpdate to your graph. It may just take longer for your peer to send this message on mainnet rather than regtest.
If I subscribe to SubscribeChannelGraph
could I receive an update when the FundingLocked message is received and channel update added to the graph?
Quick update, I've updated to listen for the first GraphTopologyUpdate related to the opened channel, then trigger resuming the HTLCs after a delay. But I'm still getting the same error: UNKNOWN_NEXT_PEER
LSP: 2022/09/06 19:40:36 HTLC Intercept
LSP: 2022/09/06 19:40:36 IncomingAmountMsat: 25000000
LSP: 2022/09/06 19:40:36 IncomingCircuitKey.ChanId: 822325845953937409
LSP: 2022/09/06 19:40:36 IncomingCircuitKey.HtlcId: 2560
LSP: 2022/09/06 19:40:36 IncomingExpiry: 752970
LSP: 2022/09/06 19:40:36 OnionBlob: 00027ba1b7f8f9f20b513b16aeef0c546d7079b4c474af3a5c9c4a205e9dbc81a50dd7d2181816ec357f792a07368fd41f9ecd060ff41df35fb0e8a22b508478b07d8ecead16676a1e9b394df0cc1f61>
LSP: 2022/09/06 19:40:36 OutgoingAmountMsat: 25000000
LSP: 2022/09/06 19:40:36 OutgoingExpiry: 752970
LSP: 2022/09/06 19:40:36 OutgoingRequestedChanId: 15766966598639671997
LSP: 2022/09/06 19:40:36 PaymentHash: f9f6bfc71eec2a6d27ca48b1900a954769a6831728a30329c3c21d2a9c8178a1
LSP: 2022/09/06 19:40:36 PSBT thread locked
LSP: 2022/09/06 19:40:36 Psbt Fund open channel request
LND: 2022-09-06 19:40:36.150 [DBG] RPCS: [openchannel] request to NodeKey(03ec54855663fec338e007e05734821189850f375c720a093bfce7cc611e03a220) allocation(us=31250, them=0)
LND: 2022-09-06 19:40:36.156 [DBG] RPCS: [openchannel]: using fee of 2428 sat/kw for funding tx
LND: 2022-09-06 19:40:36.157 [INF] FNDG: Initiating fundingRequest(local_amt=0.0003125 BTC (subtract_fees=false), push_amt=0 mSAT, chain_hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1>
LND: 2022-09-06 19:40:36.184 [DBG] HSWC: ChannelLink(f4782bd639767a9768f2d16d127ebea915010bef5482fc32991244be35f4a2cc:1): removing Add packet (Chan ID=745570:750:1, HTLC ID=12908) from mailbox
LND: 2022-09-06 19:40:48.267 [DBG] HSWC: Sent 50000 satoshis and received 100 satoshis in the last 10 seconds (0.400000 tx/sec)
LND: 2022-09-06 19:40:48.807 [INF] FNDG: Target commit tx sat/kw for pendingID(78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd): 3424
LND: 2022-09-06 19:40:48.807 [INF] FNDG: Dust limit for pendingID(78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd): 0.00000354 BTC
LND: 2022-09-06 19:40:48.808 [INF] FNDG: Starting funding workflow with 24.134.172.181:52092 for pending_id(78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd), committype=anchors-ze>
LND: 2022-09-06 19:40:49.569 [DBG] HSWC: Sent 0 satoshis and received 0 satoshis in the last 10 seconds (0.100000 tx/sec)
LND: 2022-09-06 19:40:49.855 [INF] FNDG: Recv'd fundingResponse for pending_id(78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd)
LND: 2022-09-06 19:40:49.856 [INF] FNDG: pendingChan(78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd): remote party proposes num_confs=0, csv_delay=144
LSP: 2022/09/06 19:40:49 PSBT thread unlocked
LSP: 2022/09/06 19:40:49 PSBT Fund timeout (2022-09-06 19:40:49.871895439 +0000 UTC m=+575.155568414) set for 2022-09-06 19:41:19.857106 +0000 UTC: 29.985210985s
LSP: 2022/09/06 19:40:49 Payment timeout set for 30 seconds: f9f6bfc71eec2a6d27ca48b1900a954769a6831728a30329c3c21d2a9c8178a1
LSP: 2022/09/06 19:40:49 Payment timeout ended (OPENING_CHANNEL): f9f6bfc71eec2a6d27ca48b1900a954769a6831728a30329c3c21d2a9c8178a1
LSP: 2022/09/06 19:41:19 PSBT thread locked
LND: 2022-09-06 19:41:20.873 [DBG] RPCS: Verifying PSBT for pending_id=78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd
LND: 2022-09-06 19:41:21.122 [DBG] RPCS: Finalizing PSBT for pending_id=78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd
LND: 2022-09-06 19:41:21.125 [INF] FNDG: Generated ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0) for pending_id(78d4553b510740736189efc27479f87f2801ca06bf601793d>
LND: 2022-09-06 19:41:21.228 [INF] LNWL: Inserting unconfirmed transaction 5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0
LND: 2022-09-06 19:41:21.512 [INF] CNCT: Creating new ChannelArbitrator for ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0)
LND: 2022-09-06 19:41:21.518 [DBG] CNCT: New ChainEventSubscription(id=0) for ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0)
LND: 2022-09-06 19:41:21.832 [INF] CNCT: ChannelArbitrator(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): starting state=StateDefault, trigger=chainTrigger, triggerHeight=752>
LND: 2022-09-06 19:41:21.832 [DBG] CNCT: ChannelArbitrator(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): attempting state step with trigger=chainTrigger from state=StateDefa>
LND: 2022-09-06 19:41:21.832 [DBG] CNCT: ChannelArbitrator(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): new block (height=752927) examining active HTLC's
LND: 2022-09-06 19:41:21.832 [DBG] CNCT: ChannelArbitrator(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): checking commit chain actions at height=752927, in_htlc_count=0, out>
LND: 2022-09-06 19:41:21.832 [DBG] CNCT: ChannelArbitrator(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): no actions for chain trigger, terminating
LND: 2022-09-06 19:41:21.832 [DBG] CNCT: ChannelArbitrator(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): terminating at state=StateDefault
LND: 2022-09-06 19:41:21.832 [DBG] CNCT: Starting chain watcher for ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0)
LND: 2022-09-06 19:41:21.843 [INF] NTFN: New spend subscription: spend_id=22, outpoint=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0, script=0 22e359a770a8044504cf8870974c91e4>
LND: 2022-09-06 19:41:21.843 [INF] NTFN: Dispatching historical spend rescan for outpoint=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0, script=0 22e359a770a8044504cf8870974c9>
LND: 2022-09-06 19:41:21.852 [INF] FNDG: Finalizing pending_id(78d4553b510740736189efc27479f87f2801ca06bf601793dacf8495a15ddabd) over ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308>
LND: 2022-09-06 19:41:21.852 [INF] CNCT: Close observer for ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0) active
LSP: 2022/09/06 19:41:21 Channel Event: PENDING_OPEN_CHANNEL
LND: 2022-09-06 19:41:21.854 [INF] NTFN: Historical spend dispatch finished for request outpoint=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0, script=0 22e359a770a8044504cf88>
LSP: 2022/09/06 19:41:22 Transaction: 5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0
LSP: 2022/09/06 19:41:22 BlockHash:
LSP: 2022/09/06 19:41:22 BlockHeight: 0
LSP: 2022/09/06 19:41:22 Confirmations: 0
LSP: 2022/09/06 19:41:22 Amount: -31556
LSP: 2022/09/06 19:41:22 TotalFees: 306
LSP: 2022/09/06 19:41:22 PublishTransaction:
LSP: 2022/09/06 19:41:22 PSBT thread unlocked
LND: 2022-09-06 19:41:22.441 [DBG] NTFN: Updated spend hint to height=752927 for unconfirmed spend request outpoint=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0, script=0 22e>
LND: 2022-09-06 19:41:22.509 [INF] CHBU: Updating on-disk multi SCB backup: num_old_chans=12, num_new_chans=13
LSP: 2022/09/06 19:41:23 Channel Event: OPEN_CHANNEL
LSP: 2022/09/06 19:41:23 Txid: 5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0
LSP: 2022/09/06 19:41:23 OutputIndex: 0
LND: 2022-09-06 19:41:23.803 [INF] FNDG: Peer(03ec54855663fec338e007e05734821189850f375c720a093bfce7cc611e03a220) is online, sending FundingLocked for ChannelID(a0852306bdca6789301e0f38691ba7c93fd>
LND: 2022-09-06 19:41:24.452 [WRN] DISC: ignoring remote ChannelAnnouncement for own channel
LND: 2022-09-06 19:41:24.799 [INF] PEER: Peer(03ec54855663fec338e007e05734821189850f375c720a093bfce7cc611e03a220): New channel active ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308>
LND: 2022-09-06 19:41:24.799 [DBG] CNCT: New ChainEventSubscription(id=1) for ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0)
LND: 2022-09-06 19:41:24.799 [INF] HSWC: ChannelLink(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): starting
LND: 2022-09-06 19:41:24.822 [INF] HSWC: Trimming open circuits for chan_id=16000000:0:1, start_htlc_id=0
LND: 2022-09-06 19:41:24.822 [INF] HSWC: Adding live link chan_id=a0852306bdca6789301e0f38691ba7c93fdfa7bdae78d0138a9e98cb4feb665d, short_chan_id=16000000:0:1
LND: 2022-09-06 19:41:24.823 [INF] CNCT: Attempting to update ContractSignals for ChannelPoint(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0)
LND: 2022-09-06 19:41:24.823 [INF] HSWC: ChannelLink(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): HTLC manager started, bandwidth=25799000 mSAT
LSP: 2022/09/06 19:41:24 Channel Event: ACTIVE_CHANNEL
LND: 2022-09-06 19:41:24.840 [DBG] HSWC: ChannelLink(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): loaded 0 fwd pks
LSP: 2022/09/06 19:42:59 Graph Update
LSP: 2022/09/06 19:42:59 ChanID: 16000000:0:1
LSP: 2022/09/06 19:42:59 Txid: 5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0
LSP: 2022/09/06 19:42:59 OutputIndex: 0
LSP: 2022/09/06 19:42:59 AdvertisingNode: 03ec54855663fec338e007e05734821189850f375c720a093bfce7cc611e03a220
LSP: 2022/09/06 19:42:59 ConnectingNode: 029e6289970aa5e57fe92bb8ae0cefa7ff388bb21a0f8277bc3a45fc5c10e98c4b
LSP: 2022/09/06 19:42:59 Disabled: false
LSP: 2022/09/06 19:42:59 Wait 5 seconds before resuming HTLCs: 4
LND: 2022-09-06 19:43:04.859 [DBG] HSWC: unable to find link with destination 14339972:9806173:55997
LND: 2022-09-06 19:43:04.859 [ERR] HSWC: UnknownNextPeer
LND: 2022-09-06 19:43:04.859 [ERR] HSWC: Unhandled error while reforwarding htlc settle/fail over htlcswitch: UnknownNextPeer
LND: 2022-09-06 19:43:04.859 [DBG] HSWC: ChannelLink(859c4b59cd9390f51c2387e43534b0a3eddb1898c7b2201267680348dd733b58:1): queueing removal of FAIL closed circuit: (Chan ID=747901:437:1, HTLC ID=25>
LSP: 2022/09/06 19:43:04 HTLC Event: FORWARD
LSP: 2022/09/06 19:43:04 Link Fail HTLC Event
LSP: 2022/09/06 19:43:04 WireFailure: UNKNOWN_NEXT_PEER
LSP: 2022/09/06 19:43:04 FailureDetail: NO_DETAIL
LSP: 2022/09/06 19:43:04 FailureString: UnknownNextPeer
LND: 2022-09-06 19:43:33.192 [INF] NTFN: New confirmation subscription: conf_id=4, txid=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0, num_confs=6 height_hint=752927
LND: 2022-09-06 19:43:33.193 [DBG] NTFN: Dispatching historical confirmation rescan for txid=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0
LND: 2022-09-06 19:43:33.193 [INF] FNDG: Waiting for funding tx (5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0) to reach 6 confirmations
LND: 2022-09-06 19:43:33.197 [DBG] NTFN: Confirmation details for txid=5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0 not found during historical dispatch, waiting to dispatch at>
Restart
LND: 2022-09-06 20:25:29.601 [INF] DISC: Creating new GossipSyncer for peer=03ec54855663fec338e007e05734821189850f375c720a093bfce7cc611e03a220
LND: 2022-09-06 20:25:29.601 [INF] HSWC: ChannelLink(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): resending FundingLocked message to peer
LND: 2022-09-06 20:25:29.602 [INF] DISC: GossipSyncer(03ec54855663fec338e007e05734821189850f375c720a093bfce7cc611e03a220): filtering chan range: start_height=0, num_blocks=752927
LND: 2022-09-06 20:25:29.602 [INF] HSWC: ChannelLink(5d66eb4fcb989e8a13d078aebda7df3fc9a71b69380f1e308967cabd062385a0:0): received re-establishment message from remote side```
How are you creating the alias SCID (short channel id) as Alice? Currently LND doesn't let you set the alias, so your forwards on mainnet shouldn't work - the one that you use in the invoice MUST be the LSP's alias. ACTIVE_CHANNEL is the correct event to be listening for. I'm curious how you are able to get this to work on regtest given that the same constraints with the alias apply.
I'm curious why regtest works also.
The LSP generates a random 32 byte chan_id and returns it as part of the out-of-band channel request. Then Alice adds the chan_id and LSP pubkey to the route hints of the invoice.
I assumed the route hints are not absolute and LND could pick an alternative channel if necessary because of non-strict forwarding. As written in the HtlcInterceptor ForwardHtlcInterceptorRequest RPC response:
outgoing_requested_chan_id - The requested outgoing channel id for this forwarded htlc. Because of non-strict forwarding, this isn't necessarily the channel over which the packet will be forwarded eventually. A different channel to the same peer may be selected as well.
Can you think of an alternative way to achieve this if I'm implementing it incorrectly?
32-byte channel ids don't go in the invoice, the 8-byte short channel id goes there. Non-strict forwarding only works if the short channel id in the invoice maps to an actual channel - it can't be randomly generated in the way you've done, there's no way for the LSP LND node to know what to do with this random channel. I can't think of a way your flow works since:
Ok, thanks for your feedback. If you think there is no way to open a channel this way during a HTLC interception, then the issue can be closed.
It may be possible in a future API, but not now. So it's not really an issue but more of a feature request
Background
I am building a service that receives an out-of-band channel request and, when a user hops an invoice through our node it holds the intercepted HTLC, creates a zero-conf channel, then resumes the HTLC to the user. But I’m having issues determining when is the best point to resume the HTLC for it to go through successfully. Locally testing it seems waiting 10 seconds after the ACTIVE_CHANNEL event works, but on mainnet the period is too short and errors with link fail: UNKNOWN_NEXT_PEER.
Is there a specific event after the PENDING_OPEN/OPEN/ACTIVE events where I know for sure the HTLC will go through? I am assuming once the channel is ACTIVE then it should in theory be ready for business.
Your environment
Steps to reproduce
Alice: Receiver of a new channel Bob: Payer of invoice
Logs are included below. LND and LSP notate the LND node and LSP application.
Expected behaviour
Once the newly opened channel is active, signalled with the ACTIVE_CHANNEL event then the channel should be ready to resume HTLCs.
Actual behaviour
After the opened channel is active, even after waiting up to 10 seconds, the HTLC results in a link error UNKNOWN_NEXT_PEER once the HTLC is resumed.