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

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 hits per line

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

29.03
/lncfg/cluster.go
1
package lncfg
2

3
import (
4
        "context"
5
        "fmt"
6
        "os"
7

8
        "github.com/lightningnetwork/lnd/cluster"
9
)
10

11
const (
12
        // DefaultEtcdElectionPrefix is used as election prefix if none is provided
13
        // through the config.
14
        DefaultEtcdElectionPrefix = "/leader/"
15
)
16

17
// Cluster holds configuration for clustered LND.
18
type Cluster struct {
19
        EnableLeaderElection bool `long:"enable-leader-election" description:"Enables leader election if set."`
20

21
        LeaderElector string `long:"leader-elector" choice:"etcd" description:"Leader elector to use. Valid values: \"etcd\"."`
22

23
        EtcdElectionPrefix string `long:"etcd-election-prefix" description:"Election key prefix when using etcd leader elector."`
24

25
        ID string `long:"id" description:"Identifier for this node inside the cluster (used in leader election). Defaults to the hostname."`
26

27
        LeaderSessionTTL int `long:"leader-session-ttl" description:"The TTL in seconds to use for the leader election session."`
28
}
29

30
// DefaultCluster creates and returns a new default DB config.
31
func DefaultCluster() *Cluster {
1✔
32
        hostname, _ := os.Hostname()
1✔
33
        return &Cluster{
1✔
34
                LeaderElector:      cluster.EtcdLeaderElector,
1✔
35
                EtcdElectionPrefix: DefaultEtcdElectionPrefix,
1✔
36
                LeaderSessionTTL:   90,
1✔
37
                ID:                 hostname,
1✔
38
        }
1✔
39
}
1✔
40

41
// MakeLeaderElector is a helper method to construct the concrete leader elector
42
// based on the current configuration.
43
func (c *Cluster) MakeLeaderElector(electionCtx context.Context, db *DB) (
44
        cluster.LeaderElector, error) {
×
45

×
46
        if c.LeaderElector == cluster.EtcdLeaderElector {
×
47
                return cluster.MakeLeaderElector(
×
48
                        electionCtx, c.LeaderElector, c.ID,
×
49
                        c.EtcdElectionPrefix, c.LeaderSessionTTL, db.Etcd,
×
50
                )
×
51
        }
×
52

53
        return nil, fmt.Errorf("unsupported leader elector")
×
54
}
55

56
// Validate validates the Cluster config.
57
func (c *Cluster) Validate() error {
×
58
        if !c.EnableLeaderElection {
×
59
                return nil
×
60
        }
×
61

62
        switch c.LeaderElector {
×
63
        case cluster.EtcdLeaderElector:
×
64
                if c.EtcdElectionPrefix == "" {
×
65
                        return fmt.Errorf("etcd-election-prefix must be set")
×
66
                }
×
67
                return nil
×
68

69
        default:
×
70
                return fmt.Errorf("unknown leader elector, valid values are: "+
×
71
                        "\"%v\"", cluster.EtcdLeaderElector)
×
72
        }
73
}
74

75
// Compile-time constraint to ensure Workers implements the Validator interface.
76
var _ Validator = (*Cluster)(nil)
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