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

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 hits per line

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

72.73
/contractcourt/htlc_lease_resolver.go
1
package contractcourt
2

3
import (
4
        "github.com/btcsuite/btcd/wire"
5
        "github.com/lightningnetwork/lnd/chainntnfs"
6
        "github.com/lightningnetwork/lnd/channeldb"
7
        "github.com/lightningnetwork/lnd/fn/v2"
8
        "github.com/lightningnetwork/lnd/input"
9
        "github.com/lightningnetwork/lnd/tlv"
10
)
11

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

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

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

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

4✔
41
        waitHeight := uint32(commitSpend.SpendingHeight) + csvDelay - 1
4✔
42
        if h.hasCLTV() {
4✔
43
                waitHeight = max(waitHeight, h.leaseExpiry)
×
44
        }
×
45

46
        return waitHeight
4✔
47
}
48

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

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

4✔
59
        if h.hasCLTV() {
4✔
60
                return input.NewCsvInputWithCltv(
×
61
                        op, cltvWtype, signDesc, broadcastHeight, csvDelay,
×
62
                        h.leaseExpiry, input.WithResolutionBlob(resBlob),
×
63
                )
×
64
        }
×
65

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

4✔
69
        return input.NewCsvInput(
4✔
70
                op, wType, signDesc, broadcastHeight, csvDelay,
4✔
71
                input.WithResolutionBlob(resBlob),
4✔
72
        )
4✔
73
}
74

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