Git Product home page Git Product logo

Comments (2)

bitromortac avatar bitromortac commented on May 26, 2024 1

This seems to be a normal case of an HTLC that can't be settled because the peer isn't reachable. That's covered in this test:

// testMultiHopReceiverChainClaim tests that in the multi-hop setting, if the
// receiver of an HTLC knows the preimage, but wasn't able to settle the HTLC
// off-chain, then it goes on chain to claim the HTLC uing the HTLC success
// transaction. In this scenario, the node that sent the outgoing HTLC should
// extract the preimage from the sweep transaction, and finish settling the
// HTLC backwards into the route.
func testMultiHopReceiverChainClaim(ht *lntest.HarnessTest) {
runMultiHopHtlcClaimTest(ht, runMultiHopReceiverChainClaim)
}
func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
alice, bob *node.HarnessNode, c lnrpc.CommitmentType, zeroConf bool) {
// First, we'll create a three hop network: Alice -> Bob -> Carol, with
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
ht, alice, bob, false, c, zeroConf,
)
// If this is a taproot channel, then we'll need to make some manual
// route hints so Alice can actually find a route.
var routeHints []*lnrpc.RouteHint
if c == lnrpc.CommitmentType_SIMPLE_TAPROOT {
routeHints = makeRouteHints(bob, carol, zeroConf)
}
// With the network active, we'll now add a new hodl invoice at Carol's
// end. Make sure the cltv expiry delta is large enough, otherwise Bob
// won't send out the outgoing htlc.
const invoiceAmt = 100000
var preimage lntypes.Preimage
copy(preimage[:], ht.Random32Bytes())
payHash := preimage.Hash()
invoiceReq := &invoicesrpc.AddHoldInvoiceRequest{
Value: invoiceAmt,
CltvExpiry: finalCltvDelta,
Hash: payHash[:],
RouteHints: routeHints,
}
carolInvoice := carol.RPC.AddHoldInvoice(invoiceReq)
// Subscribe the invoice.
stream := carol.RPC.SubscribeSingleInvoice(payHash[:])
// Now that we've created the invoice, we'll send a single payment from
// Alice to Carol. We won't wait for the response however, as Carol
// will not immediately settle the payment.
req := &routerrpc.SendPaymentRequest{
PaymentRequest: carolInvoice.PaymentRequest,
TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat,
}
alice.RPC.SendPayment(req)
// At this point, all 3 nodes should now have an active channel with
// the created HTLC pending on all of them.
ht.AssertActiveHtlcs(alice, payHash[:])
ht.AssertActiveHtlcs(bob, payHash[:])
ht.AssertActiveHtlcs(carol, payHash[:])
// Wait for carol to mark invoice as accepted. There is a small gap to
// bridge between adding the htlc to the channel and executing the exit
// hop logic.
ht.AssertInvoiceState(stream, lnrpc.Invoice_ACCEPTED)
restartBob := ht.SuspendNode(bob)
// Settle invoice. This will just mark the invoice as settled, as there
// is no link anymore to remove the htlc from the commitment tx. For
// this test, it is important to actually settle and not leave the
// invoice in the accepted state, because without a known preimage, the
// channel arbitrator won't go to chain.
carol.RPC.SettleInvoice(preimage[:])
// Increase the fee estimate so that the following force close tx will
// be cpfp'ed.
ht.SetFeeEstimate(30000)
// We now advance the block height to the point where Carol will force
// close her channel with Bob, broadcast the closing tx but keep it
// unconfirmed.
numBlocks := padCLTV(uint32(
invoiceReq.CltvExpiry - lncfg.DefaultIncomingBroadcastDelta,
))
// Now we'll mine enough blocks to prompt carol to actually go to the
// chain in order to sweep her HTLC since the value is high enough.
ht.MineBlocks(numBlocks)
// At this point, Carol should broadcast her active commitment
// transaction in order to go to the chain and sweep her HTLC. If there
// are anchors, Carol also sweeps hers.
expectedTxes := 1
hasAnchors := lntest.CommitTypeHasAnchors(c)
if hasAnchors {
expectedTxes = 2
}
ht.Miner.AssertNumTxsInMempool(expectedTxes)
closingTx := ht.Miner.AssertOutpointInMempool(
ht.OutPointFromChannelPoint(bobChanPoint),
)
closingTxid := closingTx.TxHash()
// Confirm the commitment.
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Restart bob again.
require.NoError(ht, restartBob())
// After the force close transaction is mined, a series of transactions
// should be broadcast by Bob and Carol. When Bob notices Carol's second
// level transaction in the mempool, he will extract the preimage and
// settle the HTLC back off-chain.
switch c {
// Carol should broadcast her second level HTLC transaction and Bob
// should broadcast a sweep tx to sweep his output in the channel with
// Carol.
case lnrpc.CommitmentType_LEGACY:
expectedTxes = 2
// Carol should broadcast her second level HTLC transaction and Bob
// should broadcast a sweep tx to sweep his output in the channel with
// Carol, and another sweep tx to sweep his anchor output.
case lnrpc.CommitmentType_ANCHORS, lnrpc.CommitmentType_SIMPLE_TAPROOT:
expectedTxes = 3
// Carol should broadcast her second level HTLC transaction and Bob
// should broadcast a sweep tx to sweep his anchor output. Bob's commit
// output can't be swept yet as he's incurring an additional CLTV from
// being the channel initiator of a script-enforced leased channel.
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
expectedTxes = 2
default:
ht.Fatalf("unhandled commitment type %v", c)
}
// All transactions should be spending from the commitment transaction.
txes := ht.Miner.GetNumTxsFromMempool(expectedTxes)
ht.AssertAllTxesSpendFrom(txes, closingTxid)
// We'll now mine an additional block which should confirm both the
// second layer transactions.
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
// Carol's pending channel report should now show two outputs under
// limbo: her commitment output, as well as the second-layer claim
// output, and the pending HTLC should also now be in stage 2.
ht.AssertNumHTLCsAndStage(carol, bobChanPoint, 1, 2)
// Once the second-level transaction confirmed, Bob should have
// extracted the preimage from the chain, and sent it back to Alice,
// clearing the HTLC off-chain.
ht.AssertNumActiveHtlcs(alice, 0)
// If we mine 4 additional blocks, then Carol can sweep the second
// level HTLC output once the CSV expires.
ht.MineEmptyBlocks(defaultCSV)
// We should have a new transaction in the mempool.
ht.Miner.AssertNumTxsInMempool(1)
// Finally, if we mine an additional block to confirm Carol's second
// level success transaction. Carol should not show a pending channel
// in her report afterwards.
ht.MineBlocks(1)
ht.AssertNumPendingForceClose(carol, 0)
// The invoice should show as settled for Carol, indicating that it was
// swept on-chain.
ht.AssertInvoiceSettled(carol, carolInvoice.PaymentAddr)
// Finally, check that the Alice's payment is correctly marked
// succeeded.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
// Bob still has his commit output to sweep to since he incurred
// an additional CLTV from being the channel initiator of a
// script-enforced leased channel, regardless of whether he
// forced closed the channel or not.
pendingChanResp := bob.RPC.PendingChannels()
require.Len(ht, pendingChanResp.PendingForceClosingChannels, 1)
forceCloseChan := pendingChanResp.PendingForceClosingChannels[0]
require.Positive(ht, forceCloseChan.LimboBalance)
require.Positive(ht, forceCloseChan.BlocksTilMaturity)
// TODO: Bob still shows a pending HTLC at this point when he
// shouldn't, as he already extracted the preimage from Carol's
// claim.
// require.Len(t.t, forceCloseChan.PendingHtlcs, 0)
// Mine enough blocks for Bob's commit output's CLTV to expire
// and sweep it.
numBlocks := uint32(forceCloseChan.BlocksTilMaturity)
ht.MineBlocks(numBlocks)
commitOutpoint := wire.OutPoint{Hash: closingTxid, Index: 3}
ht.Miner.AssertOutpointInMempool(commitOutpoint)
ht.MineBlocks(1)
}
ht.AssertNumPendingForceClose(bob, 0)
// We'll close out the channel between Alice and Bob, then shutdown
// carol to conclude the test.
ht.CloseChannel(alice, aliceChanPoint)
}

so I think your node should go to chain to claim the HTLC 10 blocks before timeout, see

lnd/lncfg/config.go

Lines 20 to 27 in 72764b1

// DefaultIncomingBroadcastDelta defines the number of blocks before the
// expiry of an incoming htlc at which we force close the channel. We
// only go to chain if we also have the preimage to actually pull in the
// htlc. BOLT #2 suggests 7 blocks. We use a few more for extra safety.
// Within this window we need to get our sweep or 2nd level success tx
// confirmed, because after that the remote party is also able to claim
// the htlc using the timeout path.
DefaultIncomingBroadcastDelta = 10

from lnd.

SunnySarahNode avatar SunnySarahNode commented on May 26, 2024

bitromortac Thank you for your answer, it's really helpful!

One more short question: can I FC this channel manually earlier with the same result?

from lnd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.