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

lightningnetwork / lnd / 15269120149

27 May 2025 07:23AM UTC coverage: 58.6% (+0.02%) from 58.583%
15269120149

Pull #9356

github

web-flow
Merge 587e4ef4c into 93a6ab875
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

37 of 40 new or added lines in 2 files covered. (92.5%)

211 existing lines in 13 files now uncovered.

97532 of 166436 relevant lines covered (58.6%)

1.82 hits per line

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

0.0
/graph/db/sql_store.go
1
package graphdb
2

3
import (
4
        "fmt"
5
        "sync"
6

7
        "github.com/lightningnetwork/lnd/batch"
8
        "github.com/lightningnetwork/lnd/sqldb"
9
)
10

11
// SQLQueries is a subset of the sqlc.Querier interface that can be used to
12
// execute queries against the SQL graph tables.
13
type SQLQueries interface {
14
}
15

16
// BatchedSQLQueries is a version of SQLQueries that's capable of batched
17
// database operations.
18
type BatchedSQLQueries interface {
19
        SQLQueries
20
        sqldb.BatchedTx[SQLQueries]
21
}
22

23
// SQLStore is an implementation of the V1Store interface that uses a SQL
24
// database as the backend.
25
//
26
// NOTE: currently, this temporarily embeds the KVStore struct so that we can
27
// implement the V1Store interface incrementally. For any method not
28
// implemented,  things will fall back to the KVStore. This is ONLY the case
29
// for the time being while this struct is purely used in unit tests only.
30
type SQLStore struct {
31
        db BatchedSQLQueries
32

33
        // cacheMu guards all caches (rejectCache and chanCache). If
34
        // this mutex will be acquired at the same time as the DB mutex then
35
        // the cacheMu MUST be acquired first to prevent deadlock.
36
        cacheMu     sync.RWMutex
37
        rejectCache *rejectCache
38
        chanCache   *channelCache
39

40
        chanScheduler batch.Scheduler[SQLQueries]
41
        nodeScheduler batch.Scheduler[SQLQueries]
42

43
        // Temporary fall-back to the KVStore so that we can implement the
44
        // interface incrementally.
45
        *KVStore
46
}
47

48
// A compile-time assertion to ensure that SQLStore implements the V1Store
49
// interface.
50
var _ V1Store = (*SQLStore)(nil)
51

52
// NewSQLStore creates a new SQLStore instance given an open BatchedSQLQueries
53
// storage backend.
54
func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore,
UNCOV
55
        options ...StoreOptionModifier) (*SQLStore, error) {
×
UNCOV
56

×
UNCOV
57
        opts := DefaultOptions()
×
UNCOV
58
        for _, o := range options {
×
UNCOV
59
                o(opts)
×
UNCOV
60
        }
×
61

UNCOV
62
        if opts.NoMigration {
×
UNCOV
63
                return nil, fmt.Errorf("the NoMigration option is not yet " +
×
UNCOV
64
                        "supported for SQL stores")
×
UNCOV
65
        }
×
66

UNCOV
67
        s := &SQLStore{
×
UNCOV
68
                db:          db,
×
UNCOV
69
                KVStore:     kvStore,
×
UNCOV
70
                rejectCache: newRejectCache(opts.RejectCacheSize),
×
UNCOV
71
                chanCache:   newChannelCache(opts.ChannelCacheSize),
×
UNCOV
72
        }
×
UNCOV
73

×
UNCOV
74
        s.chanScheduler = batch.NewTimeScheduler(
×
UNCOV
75
                db, &s.cacheMu, opts.BatchCommitInterval,
×
UNCOV
76
        )
×
UNCOV
77
        s.nodeScheduler = batch.NewTimeScheduler(
×
UNCOV
78
                db, nil, opts.BatchCommitInterval,
×
UNCOV
79
        )
×
UNCOV
80

×
UNCOV
81
        return s, nil
×
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