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

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

24750.23 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.
UNCOV
57
func (c *Cluster) Validate() error {
×
UNCOV
58
        if !c.EnableLeaderElection {
×
UNCOV
59
                return nil
×
UNCOV
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