mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
Merge pull request #8576 from mohamedawnallah/check-outbound-peers-chain-backend
healthcheck: make sure chain backend has enough outbound peers
This commit is contained in:
commit
971281deae
2 changed files with 68 additions and 2 deletions
|
@ -122,6 +122,11 @@ const (
|
||||||
// DefaultBitcoinStaticMinRelayFeeRate is the min relay fee used for
|
// DefaultBitcoinStaticMinRelayFeeRate is the min relay fee used for
|
||||||
// static estimators.
|
// static estimators.
|
||||||
DefaultBitcoinStaticMinRelayFeeRate = chainfee.FeePerKwFloor
|
DefaultBitcoinStaticMinRelayFeeRate = chainfee.FeePerKwFloor
|
||||||
|
|
||||||
|
// DefaultMinOutboundPeers is the min number of connected
|
||||||
|
// outbound peers the chain backend should have to maintain a
|
||||||
|
// healthy connection to the network.
|
||||||
|
DefaultMinOutboundPeers = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
// PartialChainControl contains all the primary interfaces of the chain control
|
// PartialChainControl contains all the primary interfaces of the chain control
|
||||||
|
@ -504,7 +509,21 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||||
|
|
||||||
cc.HealthCheck = func() error {
|
cc.HealthCheck = func() error {
|
||||||
_, err := chainConn.RawRequest(cmd, nil)
|
_, err := chainConn.RawRequest(cmd, nil)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// On local test networks we usually don't have multiple
|
||||||
|
// chain backend peers, so we can skip
|
||||||
|
// the checkOutboundPeers test.
|
||||||
|
if cfg.Bitcoin.SimNet || cfg.Bitcoin.RegTest {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the bitcoind chain backend maintains a
|
||||||
|
// healthy connection to the network by checking the
|
||||||
|
// number of outbound peers.
|
||||||
|
return checkOutboundPeers(chainConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "btcd":
|
case "btcd":
|
||||||
|
@ -613,7 +632,21 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
|
||||||
// Use a query for our best block as a health check.
|
// Use a query for our best block as a health check.
|
||||||
cc.HealthCheck = func() error {
|
cc.HealthCheck = func() error {
|
||||||
_, _, err := cc.ChainSource.GetBestBlock()
|
_, _, err := cc.ChainSource.GetBestBlock()
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// On local test networks we usually don't have multiple
|
||||||
|
// chain backend peers, so we can skip
|
||||||
|
// the checkOutboundPeers test.
|
||||||
|
if cfg.Bitcoin.SimNet || cfg.Bitcoin.RegTest {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the btcd chain backend maintains a
|
||||||
|
// healthy connection to the network by checking the
|
||||||
|
// number of outbound peers.
|
||||||
|
return checkOutboundPeers(chainRPC.Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not in simnet or regtest mode, then we'll attempt
|
// If we're not in simnet or regtest mode, then we'll attempt
|
||||||
|
@ -840,3 +873,31 @@ 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 < DefaultMinOutboundPeers {
|
||||||
|
log.Warnf("The chain backend has an insufficient number "+
|
||||||
|
"of connected outbound peers (%d connected, expected "+
|
||||||
|
"minimum is %d) which can be a security issue. "+
|
||||||
|
"Connect to more trusted nodes manually if necessary.",
|
||||||
|
outboundPeers, DefaultMinOutboundPeers)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -265,6 +265,11 @@ bitcoin peers' feefilter values into account](https://github.com/lightningnetwor
|
||||||
types](https://github.com/lightningnetwork/lnd/pull/8554) defined in
|
types](https://github.com/lightningnetwork/lnd/pull/8554) defined in
|
||||||
`btcd/rpcclient`.
|
`btcd/rpcclient`.
|
||||||
|
|
||||||
|
* [checkOutboundPeers](https://github.com/lightningnetwork/lnd/pull/8576) is
|
||||||
|
added to `chainHealthCheck` to make sure chain backend `bitcoind` and `btcd`
|
||||||
|
maintain a healthy connection to the network by checking the number of
|
||||||
|
outbound peers if they are below 6.
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
* [Add the htlc amount](https://github.com/lightningnetwork/lnd/pull/8156) to
|
* [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
|
contract court logs in case of timed-out HTLCs in order to easily spot dust
|
||||||
|
|
Loading…
Add table
Reference in a new issue