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

lightningnetwork / lnd / 13045835407

30 Jan 2025 04:48AM UTC coverage: 58.782% (+0.005%) from 58.777%
13045835407

push

github

web-flow
Merge pull request #9454 from ziggie1984/add_custom_error_msg

Add Custom Error msg and Prioritise replayed HTLCs

113 of 133 new or added lines in 6 files covered. (84.96%)

76 existing lines in 21 files now uncovered.

136069 of 231481 relevant lines covered (58.78%)

19289.04 hits per line

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

83.67
/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,
27
        serverStream Invoices_HtlcModifierServer) *htlcModifier {
3✔
28

3✔
29
        return &htlcModifier{
3✔
30
                chainParams:  params,
3✔
31
                serverStream: serverStream,
3✔
32
        }
3✔
33
}
3✔
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(
38
        req invoices.HtlcModifyRequest) (*invoices.HtlcModifyResponse, error) {
3✔
39

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

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

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

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

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

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

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

83
        return &invoices.HtlcModifyResponse{
3✔
84
                AmountPaid: amtPaid,
3✔
85
                CancelSet:  resp.CancelSet,
3✔
86
        }, nil
3✔
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