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

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

24750.23 hits per line

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

68.57
/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✔
UNCOV
43
                waitHeight = max(waitHeight, h.leaseExpiry)
×
UNCOV
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✔
UNCOV
60
                return input.NewCsvInputWithCltv(
×
UNCOV
61
                        op, cltvWtype, signDesc,
×
UNCOV
62
                        broadcastHeight, csvDelay,
×
UNCOV
63
                        h.leaseExpiry,
×
UNCOV
64
                        input.WithResolutionBlob(resBlob),
×
UNCOV
65
                )
×
UNCOV
66
        }
×
67

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

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

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