• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 16177692143

09 Jul 2025 06:49PM UTC coverage: 55.317% (-2.3%) from 57.611%
16177692143

Pull #10060

github

web-flow
Merge 4aec413e3 into 0e830da9d
Pull Request #10060: sweep: fix expected spending events being missed

9 of 25 new or added lines in 1 file covered. (36.0%)

23713 existing lines in 281 files now uncovered.

108499 of 196142 relevant lines covered (55.32%)

22331.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lnrpc/invoicesrpc/htlc_modifier.go
1
package invoicesrpc
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/chaincfg"
7
        "github.com/lightningnetwork/lnd/invoices"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
)
10

11
// htlcModifier is a helper struct that handles the lifecycle of an RPC invoice
12
// HTLC modifier server instance.
13
//
14
// This struct handles passing send and receive RPC messages between the client
15
// and the invoice service.
16
type htlcModifier struct {
17
        // chainParams is required to properly marshall an invoice for RPC.
18
        chainParams *chaincfg.Params
19

20
        // serverStream is a bidirectional RPC server stream to send invoices to
21
        // a client and receive accept responses from the client.
22
        serverStream Invoices_HtlcModifierServer
23
}
24

25
// newHtlcModifier creates a new RPC invoice HTLC modifier handler.
26
func newHtlcModifier(params *chaincfg.Params,
UNCOV
27
        serverStream Invoices_HtlcModifierServer) *htlcModifier {
×
UNCOV
28

×
UNCOV
29
        return &htlcModifier{
×
UNCOV
30
                chainParams:  params,
×
UNCOV
31
                serverStream: serverStream,
×
UNCOV
32
        }
×
UNCOV
33
}
×
34

35
// onIntercept is called when an invoice HTLC is intercepted by the invoice HTLC
36
// modifier. This method sends the invoice and the current HTLC to the client.
37
func (r *htlcModifier) onIntercept(
UNCOV
38
        req invoices.HtlcModifyRequest) (*invoices.HtlcModifyResponse, error) {
×
UNCOV
39

×
UNCOV
40
        // Convert the circuit key to an RPC circuit key.
×
UNCOV
41
        rpcCircuitKey := &CircuitKey{
×
UNCOV
42
                ChanId: req.ExitHtlcCircuitKey.ChanID.ToUint64(),
×
UNCOV
43
                HtlcId: req.ExitHtlcCircuitKey.HtlcID,
×
UNCOV
44
        }
×
UNCOV
45

×
UNCOV
46
        // Convert the invoice to an RPC invoice.
×
UNCOV
47
        rpcInvoice, err := CreateRPCInvoice(&req.Invoice, r.chainParams)
×
UNCOV
48
        if err != nil {
×
49
                return nil, err
×
50
        }
×
51

52
        // Send the modification request to the client.
UNCOV
53
        err = r.serverStream.Send(&HtlcModifyRequest{
×
UNCOV
54
                Invoice:                   rpcInvoice,
×
UNCOV
55
                ExitHtlcCircuitKey:        rpcCircuitKey,
×
UNCOV
56
                ExitHtlcAmt:               uint64(req.ExitHtlcAmt),
×
UNCOV
57
                ExitHtlcExpiry:            req.ExitHtlcExpiry,
×
UNCOV
58
                CurrentHeight:             req.CurrentHeight,
×
UNCOV
59
                ExitHtlcWireCustomRecords: req.WireCustomRecords,
×
UNCOV
60
        })
×
UNCOV
61
        if err != nil {
×
62
                return nil, err
×
63
        }
×
64

65
        // Then wait for the client to respond.
UNCOV
66
        resp, err := r.serverStream.Recv()
×
UNCOV
67
        if err != nil {
×
68
                return nil, err
×
69
        }
×
70

UNCOV
71
        if resp.CircuitKey == nil {
×
72
                return nil, fmt.Errorf("missing circuit key")
×
73
        }
×
74

UNCOV
75
        log.Tracef("Resolving invoice HTLC modifier response %v", resp)
×
UNCOV
76

×
UNCOV
77
        // Pass the resolution to the modifier.
×
UNCOV
78
        var amtPaid lnwire.MilliSatoshi
×
UNCOV
79
        if resp.AmtPaid != nil {
×
UNCOV
80
                amtPaid = lnwire.MilliSatoshi(*resp.AmtPaid)
×
UNCOV
81
        }
×
82

UNCOV
83
        return &invoices.HtlcModifyResponse{
×
UNCOV
84
                AmountPaid: amtPaid,
×
UNCOV
85
                CancelSet:  resp.CancelSet,
×
UNCOV
86
        }, nil
×
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc