Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

healthcheck: make sure chain backend has enough outbound peers #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions chainreg/chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,19 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {

cc.HealthCheck = func() error {
_, err := chainConn.RawRequest(cmd, nil)
return err
if err != nil {
return err
}

// Make sure the bitcoind chain backend maintains a
// healthy connection to the network by checking the
// number of outbound peers.
err = checkOutboundPeers(chainConn)
if err != nil {
return err
}

return nil
}

case "btcd":
Expand Down Expand Up @@ -613,7 +625,19 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
// Use a query for our best block as a health check.
cc.HealthCheck = func() error {
_, _, err := cc.ChainSource.GetBestBlock()
return err
if err != nil {
return err
}

// Make sure the btcd chain backend maintains a
// healthy connection to the network by checking the
// number of outbound peers.
err = checkOutboundPeers(chainRPC.Client)
if err != nil {
return err
}

return nil
}

// If we're not in simnet or regtest mode, then we'll attempt
Expand Down Expand Up @@ -840,3 +864,28 @@ var (
},
}
)

// checkOutboundPeers checks the number of outbound peers connected to the
// provided RPC client. If the number of outbound peers is below 6, a warning
// is logged. This function is intended to ensure that the chain backend
// maintains a healthy connection to the network.
func checkOutboundPeers(client *rpcclient.Client) error {
peers, err := client.GetPeerInfo()
if err != nil {
return err
}

var outboundPeers int
for _, peer := range peers {
if !peer.Inbound {
outboundPeers++
}
}

if outboundPeers < 6 {
log.Warnf("The number of outbound peers (%d) is "+
"below the expected minimum of 6.", outboundPeers)
}

return nil
}
5 changes: 5 additions & 0 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ bitcoin peers' feefilter values into account](https://github.com/lightningnetwor
types](https://github.com/lightningnetwork/lnd/pull/8554) defined in
`btcd/rpcclient`.

`[checkOutboundPeers](https://github.com/lightningnetwork/lnd/pull/8576) is
added to `chainHealthCheck` to make sure chain backend `bitcoind` and `btcd`
maintains a healthy connection to the network by checking the number of
outbound peers if they are below 6.

### Logging
* [Add the htlc amount](https://github.com/lightningnetwork/lnd/pull/8156) to
contract court logs in case of timed-out HTLCs in order to easily spot dust
Expand Down
Loading