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

lightningnetwork / lnd / 15574102646

11 Jun 2025 01:44AM UTC coverage: 68.554% (+9.9%) from 58.637%
15574102646

Pull #9652

github

web-flow
Merge eb863e46a into 92a5d35cf
Pull Request #9652: lnwallet/chancloser: fix flake in TestRbfCloseClosingNegotiationLocal

11 of 12 new or added lines in 1 file covered. (91.67%)

7276 existing lines in 84 files now uncovered.

134508 of 196208 relevant lines covered (68.55%)

44569.29 hits per line

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

73.33
/lnrpc/walletrpc/psbt.go
1
//go:build walletrpc
2
// +build walletrpc
3

4
package walletrpc
5

6
import (
7
        "fmt"
8
        "math"
9
        "time"
10

11
        "github.com/btcsuite/btcd/wire"
12
        base "github.com/btcsuite/btcwallet/wallet"
13
        "github.com/btcsuite/btcwallet/wtxmgr"
14
        "github.com/lightningnetwork/lnd/lnwallet"
15
        "github.com/lightningnetwork/lnd/lnwallet/chanfunding"
16
)
17

18
const (
19
        defaultMaxConf = math.MaxInt32
20
)
21

22
// verifyInputsUnspent checks that all inputs are contained in the list of
23
// known, non-locked UTXOs given.
24
func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
6✔
25
        // TODO(guggero): Pass in UTXOs as a map to make lookup more efficient.
6✔
26
        for idx, txIn := range inputs {
12✔
27
                found := false
6✔
28
                for _, u := range utxos {
12✔
29
                        if u.OutPoint == txIn.PreviousOutPoint {
12✔
30
                                found = true
6✔
31
                                break
6✔
32
                        }
33
                }
34

35
                if !found {
12✔
36
                        return fmt.Errorf("input %d not found in list of non-"+
6✔
37
                                "locked UTXO", idx)
6✔
38
                }
6✔
39
        }
40

41
        return nil
6✔
42
}
43

44
// lockInputs requests lock leases for all inputs specified in a PSBT packet
45
// (the passed outpoints), using either the optional custom lock ID and duration
46
// or the wallet's internal static lock ID with the default 10-minute duration.
47
func lockInputs(w lnwallet.WalletController, outpoints []wire.OutPoint,
48
        customLockID *wtxmgr.LockID, customLockDuration time.Duration) (
49
        []*base.ListLeasedOutputResult, error) {
6✔
50

6✔
51
        locks := make(
6✔
52
                []*base.ListLeasedOutputResult, len(outpoints),
6✔
53
        )
6✔
54
        for idx := range outpoints {
12✔
55
                lock := &base.ListLeasedOutputResult{
6✔
56
                        LockedOutput: &wtxmgr.LockedOutput{
6✔
57
                                Outpoint: outpoints[idx],
6✔
58
                        },
6✔
59
                }
6✔
60

6✔
61
                lock.LockID = chanfunding.LndInternalLockID
6✔
62
                if customLockID != nil {
12✔
63
                        lock.LockID = *customLockID
6✔
64
                }
6✔
65

66
                lockDuration := chanfunding.DefaultLockDuration
6✔
67
                if customLockDuration != 0 {
12✔
68
                        lockDuration = customLockDuration
6✔
69
                }
6✔
70

71
                // Get the details about this outpoint.
72
                utxo, err := w.FetchOutpointInfo(&lock.Outpoint)
6✔
73
                if err != nil {
6✔
74
                        return nil, fmt.Errorf("fetch outpoint info: %w", err)
×
75
                }
×
76

77
                expiration, err := w.LeaseOutput(
6✔
78
                        lock.LockID, lock.Outpoint, lockDuration,
6✔
79
                )
6✔
80
                if err != nil {
6✔
81
                        // If we run into a problem with locking one output, we
×
UNCOV
82
                        // should try to unlock those that we successfully
×
UNCOV
83
                        // locked so far. If that fails as well, there's not
×
84
                        // much we can do.
×
85
                        for i := 0; i < idx; i++ {
×
UNCOV
86
                                op := locks[i].Outpoint
×
UNCOV
87
                                if err := w.ReleaseOutput(
×
UNCOV
88
                                        chanfunding.LndInternalLockID, op,
×
UNCOV
89
                                ); err != nil {
×
UNCOV
90
                                        log.Errorf("could not release the "+
×
UNCOV
91
                                                "lock on %v: %v", op, err)
×
UNCOV
92
                                }
×
93
                        }
94

UNCOV
95
                        return nil, fmt.Errorf("could not lease a lock on "+
×
UNCOV
96
                                "UTXO: %v", err)
×
97
                }
98

99
                lock.Expiration = expiration
6✔
100
                lock.PkScript = utxo.PkScript
6✔
101
                lock.Value = int64(utxo.Value)
6✔
102
                locks[idx] = lock
6✔
103
        }
104

105
        return locks, nil
6✔
106
}
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