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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 hits per line

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

54.55
/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/input"
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✔
UNCOV
43
                waitHeight = uint32(math.Max(
×
UNCOV
44
                        float64(waitHeight), float64(h.leaseExpiry),
×
UNCOV
45
                ))
×
UNCOV
46
        }
×
47

48
        return waitHeight
4✔
49
}
50

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

4✔
58
        if h.hasCLTV() {
4✔
UNCOV
59
                log.Infof("%T(%x): CSV and CLTV locks expired, offering "+
×
UNCOV
60
                        "second-layer output to sweeper: %v", h, payHash, op)
×
UNCOV
61

×
UNCOV
62
                return input.NewCsvInputWithCltv(
×
UNCOV
63
                        op, cltvWtype, signDesc,
×
UNCOV
64
                        broadcastHeight, csvDelay,
×
UNCOV
65
                        h.leaseExpiry,
×
UNCOV
66
                )
×
UNCOV
67
        }
×
68

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

4✔
72
        return input.NewCsvInput(op, wType, signDesc, broadcastHeight, csvDelay)
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✔
UNCOV
81
                h.leaseExpiry = state.ThawHeight
×
UNCOV
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