mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package network
|
|
|
|
import (
|
|
"errors"
|
|
|
|
validators "github.com/luxfi/validators"
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
// ErrNoIngressConnections denotes that no node is connected to this validator.
|
|
var ErrNoIngressConnections = errors.New("primary network validator has no inbound connections")
|
|
|
|
type ingressConnectionCounter interface {
|
|
IngressConnCount() int
|
|
}
|
|
|
|
type validatorRetriever interface {
|
|
GetValidator(netID ids.ID, nodeID ids.NodeID) (*validators.GetValidatorOutput, bool)
|
|
}
|
|
|
|
func checkNoIngressConnections(selfID ids.NodeID, ingressConnections ingressConnectionCounter, validators validatorRetriever) (interface{}, error) {
|
|
connCount := ingressConnections.IngressConnCount()
|
|
_, areWeValidator := validators.GetValidator(constants.PrimaryNetworkID, selfID)
|
|
|
|
result := map[string]interface{}{
|
|
"ingressConnectionCount": connCount,
|
|
"primaryNetworkValidator": areWeValidator,
|
|
}
|
|
|
|
if connCount > 0 || !areWeValidator {
|
|
return result, nil
|
|
}
|
|
|
|
return result, ErrNoIngressConnections
|
|
}
|