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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 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