Merge branch 'develop' into felipe/log-level

This commit is contained in:
mergify[bot] 2023-05-04 23:55:14 +00:00 committed by GitHub
commit f5a8f900d6
5 changed files with 34 additions and 18 deletions

@ -132,6 +132,8 @@ type Backend struct {
stripTrailingXFF bool stripTrailingXFF bool
proxydIP string proxydIP string
skipPeerCountCheck bool
maxDegradedLatencyThreshold time.Duration maxDegradedLatencyThreshold time.Duration
maxLatencyThreshold time.Duration maxLatencyThreshold time.Duration
maxErrorRateThreshold float64 maxErrorRateThreshold float64
@ -207,6 +209,12 @@ func WithProxydIP(ip string) BackendOpt {
} }
} }
func WithSkipPeerCountCheck(skipPeerCountCheck bool) BackendOpt {
return func(b *Backend) {
b.skipPeerCountCheck = skipPeerCountCheck
}
}
func WithMaxDegradedLatencyThreshold(maxDegradedLatencyThreshold time.Duration) BackendOpt { func WithMaxDegradedLatencyThreshold(maxDegradedLatencyThreshold time.Duration) BackendOpt {
return func(b *Backend) { return func(b *Backend) {
b.maxDegradedLatencyThreshold = maxDegradedLatencyThreshold b.maxDegradedLatencyThreshold = maxDegradedLatencyThreshold

@ -92,6 +92,7 @@ type BackendConfig struct {
ClientCertFile string `toml:"client_cert_file"` ClientCertFile string `toml:"client_cert_file"`
ClientKeyFile string `toml:"client_key_file"` ClientKeyFile string `toml:"client_key_file"`
StripTrailingXFF bool `toml:"strip_trailing_xff"` StripTrailingXFF bool `toml:"strip_trailing_xff"`
SkipPeerCountCheck bool `toml:"consensus_skip_peer_count"`
} }
type BackendsConfig map[string]*BackendConfig type BackendsConfig map[string]*BackendConfig

@ -227,11 +227,14 @@ func (cp *ConsensusPoller) UpdateBackend(ctx context.Context, be *Backend) {
return return
} }
peerCount, err := cp.getPeerCount(ctx, be) var peerCount uint64
if !be.skipPeerCountCheck {
peerCount, err = cp.getPeerCount(ctx, be)
if err != nil { if err != nil {
log.Warn("error updating backend", "name", be.Name, "err", err) log.Warn("error updating backend", "name", be.Name, "err", err)
return return
} }
}
latestBlockNumber, latestBlockHash, err := cp.fetchBlock(ctx, be, "latest") latestBlockNumber, latestBlockHash, err := cp.fetchBlock(ctx, be, "latest")
if err != nil { if err != nil {
@ -257,7 +260,7 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
for _, be := range cp.backendGroup.Backends { for _, be := range cp.backendGroup.Backends {
peerCount, backendLatestBlockNumber, backendLatestBlockHash, lastUpdate := cp.getBackendState(be) peerCount, backendLatestBlockNumber, backendLatestBlockHash, lastUpdate := cp.getBackendState(be)
if peerCount < cp.minPeerCount { if !be.skipPeerCountCheck && peerCount < cp.minPeerCount {
continue continue
} }
if lastUpdate.Add(cp.maxUpdateThreshold).Before(time.Now()) { if lastUpdate.Add(cp.maxUpdateThreshold).Before(time.Now()) {
@ -306,7 +309,7 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
bs := cp.backendState[be] bs := cp.backendState[be]
notUpdated := bs.lastUpdate.Add(cp.maxUpdateThreshold).Before(time.Now()) notUpdated := bs.lastUpdate.Add(cp.maxUpdateThreshold).Before(time.Now())
isBanned := time.Now().Before(bs.bannedUntil) isBanned := time.Now().Before(bs.bannedUntil)
notEnoughPeers := bs.peerCount < cp.minPeerCount notEnoughPeers := !be.skipPeerCountCheck && bs.peerCount < cp.minPeerCount
if !be.IsHealthy() || be.IsRateLimited() || !be.Online() || notUpdated || isBanned || notEnoughPeers { if !be.IsHealthy() || be.IsRateLimited() || !be.Online() || notUpdated || isBanned || notEnoughPeers {
filteredBackendsNames = append(filteredBackendsNames, be.Name) filteredBackendsNames = append(filteredBackendsNames, be.Name)
continue continue
@ -384,7 +387,7 @@ func (cp *ConsensusPoller) fetchBlock(ctx context.Context, be *Backend, block st
return return
} }
// isSyncing Convenient wrapper to check if the backend is syncing from the network // getPeerCount Convenient wrapper to retrieve the current peer count from the backend
func (cp *ConsensusPoller) getPeerCount(ctx context.Context, be *Backend) (count uint64, err error) { func (cp *ConsensusPoller) getPeerCount(ctx context.Context, be *Backend) (count uint64, err error) {
var rpcRes RPCRes var rpcRes RPCRes
err = be.ForwardRPC(ctx, &rpcRes, "67", "net_peerCount") err = be.ForwardRPC(ctx, &rpcRes, "67", "net_peerCount")

@ -72,6 +72,9 @@ ca_file = ""
client_cert_file = "" client_cert_file = ""
# Path to a custom client key file. # Path to a custom client key file.
client_key_file = "" client_key_file = ""
# Allows backends to skip peer count checking, default false
# consensus_skip_peer_count = true
[backends.alchemy] [backends.alchemy]
rpc_url = "" rpc_url = ""

@ -157,6 +157,7 @@ func Start(config *Config) (*Server, func(), error) {
opts = append(opts, WithStrippedTrailingXFF()) opts = append(opts, WithStrippedTrailingXFF())
} }
opts = append(opts, WithProxydIP(os.Getenv("PROXYD_IP"))) opts = append(opts, WithProxydIP(os.Getenv("PROXYD_IP")))
opts = append(opts, WithSkipPeerCountCheck(cfg.SkipPeerCountCheck))
back := NewBackend(name, rpcURL, wsURL, lim, rpcRequestSemaphore, opts...) back := NewBackend(name, rpcURL, wsURL, lim, rpcRequestSemaphore, opts...)
backendNames = append(backendNames, name) backendNames = append(backendNames, name)