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

lightningnetwork / lnd / 12343072627

15 Dec 2024 11:09PM UTC coverage: 57.504% (-1.1%) from 58.636%
12343072627

Pull #9315

github

yyforyongyu
contractcourt: offer outgoing htlc one block earlier before its expiry

We need to offer the outgoing htlc one block earlier to make sure when
the expiry height hits, the sweeper will not miss sweeping it in the
same block. This also means the outgoing contest resolver now only does
one thing - watch for preimage spend till height expiry-1, which can
easily be moved into the timeout resolver instead in the future.
Pull Request #9315: Implement `blockbeat`

1445 of 2007 new or added lines in 26 files covered. (72.0%)

19246 existing lines in 249 files now uncovered.

102342 of 177975 relevant lines covered (57.5%)

24772.24 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