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

lightningnetwork / lnd / 13236757158

10 Feb 2025 08:39AM UTC coverage: 57.649% (-1.2%) from 58.815%
13236757158

Pull #9493

github

ziggie1984
lncli: for some cmds we don't replace the data of the response.

For some cmds it is not very practical to replace the json output
because we might pipe it into other commands. For example when
creating the route we want to pipe it into sendtoRoute.
Pull Request #9493: For some lncli cmds we should not replace the content with other data

0 of 9 new or added lines in 2 files covered. (0.0%)

19535 existing lines in 252 files now uncovered.

103517 of 179563 relevant lines covered (57.65%)

24878.49 hits per line

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

64.86
/contractcourt/htlc_lease_resolver.go
1
package contractcourt
2

3
import (
4
        "math"
5

6
        "github.com/btcsuite/btcd/wire"
7
        "github.com/lightningnetwork/lnd/chainntnfs"
8
        "github.com/lightningnetwork/lnd/channeldb"
9
        "github.com/lightningnetwork/lnd/fn/v2"
10
        "github.com/lightningnetwork/lnd/input"
11
        "github.com/lightningnetwork/lnd/tlv"
12
)
13

14
// htlcLeaseResolver is a struct that houses the lease specific HTLC resolution
15
// logic. This includes deriving the _true_ waiting height, as well as the
16
// input to offer to the sweeper.
17
type htlcLeaseResolver struct {
18
        // channelInitiator denotes whether the party responsible for resolving
19
        // the contract initiated the channel.
20
        channelInitiator bool
21

22
        // leaseExpiry denotes the additional waiting period the contract must
23
        // hold until it can be resolved. This waiting period is known as the
24
        // expiration of a script-enforced leased channel and only applies to
25
        // the channel initiator.
26
        //
27
        // NOTE: This value should only be set when the contract belongs to a
28
        // leased channel.
29
        leaseExpiry uint32
30
}
31

32
// hasCLTV denotes whether the resolver must wait for an additional CLTV to
33
// expire before resolving the contract.
34
func (h *htlcLeaseResolver) hasCLTV() bool {
12✔
35
        return h.channelInitiator && h.leaseExpiry > 0
12✔
36
}
12✔
37

38
// deriveWaitHeight computes the height the resolver needs to wait until it can
39
// sweep the input.
40
func (h *htlcLeaseResolver) deriveWaitHeight(csvDelay uint32,
41
        commitSpend *chainntnfs.SpendDetail) uint32 {
4✔
42

4✔
43
        waitHeight := uint32(commitSpend.SpendingHeight) + csvDelay - 1
4✔
44
        if h.hasCLTV() {
4✔
UNCOV
45
                waitHeight = uint32(math.Max(
×
UNCOV
46
                        float64(waitHeight), float64(h.leaseExpiry),
×
UNCOV
47
                ))
×
UNCOV
48
        }
×
49

50
        return waitHeight
4✔
51
}
52

53
// makeSweepInput constructs the type of input (either just csv or csv+ctlv) to
54
// send to the sweeper so the output can ultimately be swept.
55
func (h *htlcLeaseResolver) makeSweepInput(op *wire.OutPoint,
56
        wType, cltvWtype input.StandardWitnessType,
57
        signDesc *input.SignDescriptor, csvDelay, broadcastHeight uint32,
58
        payHash [32]byte, resBlob fn.Option[tlv.Blob]) *input.BaseInput {
4✔
59

4✔
60
        log.Infof("%T(%x): offering second-layer output to sweeper: %v", h,
4✔
61
                payHash, op)
4✔
62

4✔
63
        if h.hasCLTV() {
4✔
UNCOV
64
                return input.NewCsvInputWithCltv(
×
UNCOV
65
                        op, cltvWtype, signDesc,
×
UNCOV
66
                        broadcastHeight, csvDelay,
×
UNCOV
67
                        h.leaseExpiry,
×
UNCOV
68
                        input.WithResolutionBlob(resBlob),
×
UNCOV
69
                )
×
UNCOV
70
        }
×
71

72
        log.Infof("%T(%x): CSV lock expired, offering second-layer output to "+
4✔
73
                "sweeper: %v", h, payHash, op)
4✔
74

4✔
75
        return input.NewCsvInput(
4✔
76
                op, wType, signDesc, broadcastHeight, csvDelay,
4✔
77
                input.WithResolutionBlob(resBlob),
4✔
78
        )
4✔
79
}
80

81
// SupplementState allows the user of a ContractResolver to supplement it with
82
// state required for the proper resolution of a contract.
83
//
84
// NOTE: Part of the ContractResolver interface.
85
func (h *htlcLeaseResolver) SupplementState(state *channeldb.OpenChannel) {
2✔
86
        if state.ChanType.HasLeaseExpiration() {
2✔
UNCOV
87
                h.leaseExpiry = state.ThawHeight
×
UNCOV
88
        }
×
89
        h.channelInitiator = state.IsInitiator
2✔
90
}
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