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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

0.0
/lnwallet/chainfee/minfeemanager.go
1
package chainfee
2

3
import (
4
        "sync"
5
        "time"
6
)
7

8
const defaultUpdateInterval = 10 * time.Minute
9

10
// minFeeManager is used to store and update the minimum fee that is required
11
// by a transaction to be accepted to the mempool. The minFeeManager ensures
12
// that the backend used to fetch the fee is not queried too regularly.
13
type minFeeManager struct {
14
        mu                sync.Mutex
15
        minFeePerKW       SatPerKWeight
16
        lastUpdatedTime   time.Time
17
        minUpdateInterval time.Duration
18
        fetchFeeFunc      fetchFee
19
}
20

21
// fetchFee represents a function that can be used to fetch a fee.
22
type fetchFee func() (SatPerKWeight, error)
23

24
// newMinFeeManager creates a new minFeeManager and uses the
25
// given fetchMinFee function to set the minFeePerKW of the minFeeManager.
26
// This function requires the fetchMinFee function to succeed.
27
func newMinFeeManager(minUpdateInterval time.Duration,
UNCOV
28
        fetchMinFee fetchFee) (*minFeeManager, error) {
×
UNCOV
29

×
UNCOV
30
        minFee, err := fetchMinFee()
×
UNCOV
31
        if err != nil {
×
32
                return nil, err
×
33
        }
×
34

35
        // Ensure that the minimum fee we use is always clamped by our fee
36
        // floor.
UNCOV
37
        if minFee < FeePerKwFloor {
×
UNCOV
38
                minFee = FeePerKwFloor
×
UNCOV
39
        }
×
40

UNCOV
41
        return &minFeeManager{
×
UNCOV
42
                minFeePerKW:       minFee,
×
UNCOV
43
                lastUpdatedTime:   time.Now(),
×
UNCOV
44
                minUpdateInterval: minUpdateInterval,
×
UNCOV
45
                fetchFeeFunc:      fetchMinFee,
×
UNCOV
46
        }, nil
×
47
}
48

49
// fetchMinFee returns the stored minFeePerKW if it has been updated recently
50
// or if the call to the chain backend fails. Otherwise, it sets the stored
51
// minFeePerKW to the fee returned from the backend and floors it based on
52
// our fee floor.
UNCOV
53
func (m *minFeeManager) fetchMinFee() SatPerKWeight {
×
UNCOV
54
        m.mu.Lock()
×
UNCOV
55
        defer m.mu.Unlock()
×
UNCOV
56

×
UNCOV
57
        if time.Since(m.lastUpdatedTime) < m.minUpdateInterval {
×
UNCOV
58
                return m.minFeePerKW
×
UNCOV
59
        }
×
60

UNCOV
61
        newMinFee, err := m.fetchFeeFunc()
×
UNCOV
62
        if err != nil {
×
63
                log.Errorf("Unable to fetch updated min fee from chain "+
×
64
                        "backend. Using last known min fee instead: %v", err)
×
65

×
66
                return m.minFeePerKW
×
67
        }
×
68

69
        // By default, we'll use the backend node's minimum fee as the
70
        // minimum fee rate we'll propose for transactions. However, if this
71
        // happens to be lower than our fee floor, we'll enforce that instead.
UNCOV
72
        m.minFeePerKW = newMinFee
×
UNCOV
73
        if m.minFeePerKW < FeePerKwFloor {
×
74
                m.minFeePerKW = FeePerKwFloor
×
75
        }
×
UNCOV
76
        m.lastUpdatedTime = time.Now()
×
UNCOV
77

×
UNCOV
78
        log.Debugf("Using minimum fee rate of %v sat/kw",
×
UNCOV
79
                int64(m.minFeePerKW))
×
UNCOV
80

×
UNCOV
81
        return m.minFeePerKW
×
82
}
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