Skip to content

Commit

Permalink
Add --track-subnets to replace --whitelisted-subnets (ava-labs#2439)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jan 10, 2023
1 parent db5704f commit 10f4405
Show file tree
Hide file tree
Showing 26 changed files with 98 additions and 95 deletions.
4 changes: 2 additions & 2 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Manager interface {
// Queues a chain to be created in the future after chain creator is unblocked.
// This is only called from the P-chain thread to create other chains
// Queued chains are created only after P-chain is bootstrapped.
// This assumes only chains in whitelisted subnets are queued.
// This assumes only chains in tracked subnets are queued.
QueueChainCreation(ChainParameters)

// Add a registrant [r]. Every time a chain is
Expand Down Expand Up @@ -262,7 +262,7 @@ func (m *manager) Router() router.Router {
}

// QueueChainCreation queues a chain creation request
// Invariant: Whitelisted Subnet must be checked before calling this function
// Invariant: Tracked Subnet must be checked before calling this function
func (m *manager) QueueChainCreation(chainParams ChainParameters) {
m.subnetsLock.Lock()
sb, exists := m.subnets[chainParams.SubnetID]
Expand Down
31 changes: 20 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const (
)

var (
deprecatedKeys = map[string]string{}
deprecatedKeys = map[string]string{
WhitelistedSubnetsKey: fmt.Sprintf("Use --%s instead", TrackSubnetsKey),
}

errInvalidStakerWeights = errors.New("staking weights must be positive")
errStakingDisableOnPublicNetwork = errors.New("staking disabled on public network")
Expand All @@ -73,7 +75,7 @@ var (
errStakeMaxConsumptionTooLarge = fmt.Errorf("max stake consumption must be less than or equal to %d", reward.PercentDenominator)
errStakeMaxConsumptionBelowMin = errors.New("stake max consumption can't be less than min stake consumption")
errStakeMintingPeriodBelowMin = errors.New("stake minting period can't be less than max stake duration")
errCannotWhitelistPrimaryNetwork = errors.New("cannot whitelist primary network")
errCannotTrackPrimaryNetwork = errors.New("cannot track primary network")
errStakingKeyContentUnset = fmt.Errorf("%s key not set but %s set", StakingTLSKeyContentKey, StakingCertContentKey)
errStakingCertContentUnset = fmt.Errorf("%s key set but %s not set", StakingTLSKeyContentKey, StakingCertContentKey)
errMissingStakingSigningKeyFile = errors.New("missing staking signing key file")
Expand Down Expand Up @@ -835,9 +837,16 @@ func getGenesisData(v *viper.Viper, networkID uint32) ([]byte, ids.ID, error) {
return genesis.FromConfig(config)
}

func getWhitelistedSubnets(v *viper.Viper) (set.Set[ids.ID], error) {
whitelistedSubnetIDs := set.Set[ids.ID]{}
for _, subnet := range strings.Split(v.GetString(WhitelistedSubnetsKey), ",") {
func getTrackedSubnets(v *viper.Viper) (set.Set[ids.ID], error) {
var trackSubnets string
if v.IsSet(TrackSubnetsKey) {
trackSubnets = v.GetString(TrackSubnetsKey)
} else {
trackSubnets = v.GetString(WhitelistedSubnetsKey)
}

trackedSubnetIDs := set.Set[ids.ID]{}
for _, subnet := range strings.Split(trackSubnets, ",") {
if subnet == "" {
continue
}
Expand All @@ -846,11 +855,11 @@ func getWhitelistedSubnets(v *viper.Viper) (set.Set[ids.ID], error) {
return nil, fmt.Errorf("couldn't parse subnetID %q: %w", subnet, err)
}
if subnetID == constants.PrimaryNetworkID {
return nil, errCannotWhitelistPrimaryNetwork
return nil, errCannotTrackPrimaryNetwork
}
whitelistedSubnetIDs.Add(subnetID)
trackedSubnetIDs.Add(subnetID)
}
return whitelistedSubnetIDs, nil
return trackedSubnetIDs, nil
}

func getDatabaseConfig(v *viper.Viper, networkID uint32) (node.DatabaseConfig, error) {
Expand Down Expand Up @@ -1292,8 +1301,8 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
return node.Config{}, err
}

// Whitelisted Subnets
nodeConfig.WhitelistedSubnets, err = getWhitelistedSubnets(v)
// Tracked Subnets
nodeConfig.TrackedSubnets, err = getTrackedSubnets(v)
if err != nil {
return node.Config{}, err
}
Expand Down Expand Up @@ -1370,7 +1379,7 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
}

// Subnet Configs
subnetConfigs, err := getSubnetConfigs(v, nodeConfig.WhitelistedSubnets.List())
subnetConfigs, err := getSubnetConfigs(v, nodeConfig.TrackedSubnets.List())
if err != nil {
return node.Config{}, fmt.Errorf("couldn't read subnet configs: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestGetSubnetConfigsFromFile(t *testing.T) {
},
errMessage: "invalid character",
},
"subnet is not whitelisted": {
"subnet is not tracked": {
fileName: "Gmt4fuNsGJAd2PX86LBvycGaBpgCYKbuULdCLZs3SEs1Jx1LU.json",
givenJSON: `{"validatorOnly": true}`,
testF: func(require *require.Assertions, given map[ids.ID]chains.SubnetConfig) {
Expand Down Expand Up @@ -508,7 +508,7 @@ func TestGetSubnetConfigsFromFlags(t *testing.T) {
require.Equal(20, config.ConsensusParameters.K)
},
},
"subnet is not whitelisted": {
"subnet is not tracked": {
givenJSON: `{"Gmt4fuNsGJAd2PX86LBvycGaBpgCYKbuULdCLZs3SEs1Jx1LU":{"validatorOnly":true}}`,
testF: func(require *require.Assertions, given map[ids.ID]chains.SubnetConfig) {
require.Empty(given)
Expand Down
3 changes: 2 additions & 1 deletion config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ func addNodeFlags(fs *flag.FlagSet) {
fs.Duration(StakeMintingPeriodKey, genesis.LocalParams.RewardConfig.MintingPeriod, "Consumption period of the staking function")
fs.Uint64(StakeSupplyCapKey, genesis.LocalParams.RewardConfig.SupplyCap, "Supply cap of the staking function")
// Subnets
fs.String(WhitelistedSubnetsKey, "", "Whitelist of subnets to validate")
fs.String(WhitelistedSubnetsKey, "", fmt.Sprintf("[DEPRECATED] Use --%s", TrackSubnetsKey))
fs.String(TrackSubnetsKey, "", "List of subnets for the node to track. A node tracking a subnet will track the uptimes of the subnet validators and attempt to sync all the chains in the subnet. Before validating a subnet, a node should be tracking the subnet to avoid impacting their subnet validation uptime")

// State syncing
fs.String(StateSyncIPsKey, "", "Comma separated list of state sync peer ips to connect to. Example: 127.0.0.1:9630,127.0.0.1:9631")
Expand Down
1 change: 1 addition & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const (
SnowMixedQueryNumPushVdrKey = "snow-mixed-query-num-push-vdr"
SnowMixedQueryNumPushNonVdrKey = "snow-mixed-query-num-push-non-vdr"
WhitelistedSubnetsKey = "whitelisted-subnets"
TrackSubnetsKey = "track-subnets"
AdminAPIEnabledKey = "api-admin-enabled"
InfoAPIEnabledKey = "api-info-enabled"
KeystoreAPIEnabledKey = "api-keystore-enabled"
Expand Down
6 changes: 3 additions & 3 deletions network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ type Config struct {
// TLSKey is this node's TLS key that is used to sign IPs.
TLSKey crypto.Signer `json:"-"`

// WhitelistedSubnets of the node.
WhitelistedSubnets set.Set[ids.ID] `json:"-"`
Beacons validators.Set `json:"-"`
// TrackedSubnets of the node.
TrackedSubnets set.Set[ids.ID] `json:"-"`
Beacons validators.Set `json:"-"`

// Validators are the current validators in the Avalanche network
Validators validators.Manager `json:"-"`
Expand Down
2 changes: 1 addition & 1 deletion network/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func newMetrics(namespace string, registerer prometheus.Registerer, initialSubne
registerer.Register(m.peerConnectedLifetimeAverage),
)

// init subnet tracker metrics with whitelisted subnets
// init subnet tracker metrics with tracked subnets
for subnetID := range initialSubnetIDs {
// no need to track primary network ID
if subnetID == constants.PrimaryNetworkID {
Expand Down
12 changes: 6 additions & 6 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (

errMissingPrimaryValidators = errors.New("missing primary validator set")
errNotValidator = errors.New("node is not a validator")
errNotWhiteListed = errors.New("subnet is not whitelisted")
errNotTracked = errors.New("subnet is not tracked")
errSubnetNotExist = errors.New("subnet does not exist")
)

Expand Down Expand Up @@ -219,7 +219,7 @@ func NewNetwork(
return nil, fmt.Errorf("initializing peer metrics failed with: %w", err)
}

metrics, err := newMetrics(config.Namespace, metricsRegisterer, config.WhitelistedSubnets)
metrics, err := newMetrics(config.Namespace, metricsRegisterer, config.TrackedSubnets)
if err != nil {
return nil, fmt.Errorf("initializing network metrics failed with: %w", err)
}
Expand All @@ -235,7 +235,7 @@ func NewNetwork(
Network: nil, // This is set below.
Router: router,
VersionCompatibility: version.GetCompatibility(config.NetworkID),
MySubnets: config.WhitelistedSubnets,
MySubnets: config.TrackedSubnets,
Beacons: config.Beacons,
NetworkID: config.NetworkID,
PingFrequency: config.PingFrequency,
Expand Down Expand Up @@ -1242,8 +1242,8 @@ func (n *network) StartClose() {
}

func (n *network) NodeUptime(subnetID ids.ID) (UptimeResult, error) {
if subnetID != constants.PrimaryNetworkID && !n.config.WhitelistedSubnets.Contains(subnetID) {
return UptimeResult{}, errNotWhiteListed
if subnetID != constants.PrimaryNetworkID && !n.config.TrackedSubnets.Contains(subnetID) {
return UptimeResult{}, errNotTracked
}

validators, ok := n.config.Validators.Get(subnetID)
Expand Down Expand Up @@ -1320,7 +1320,7 @@ func (n *network) runTimers() {
n.metrics.nodeUptimeWeightedAverage.Set(primaryUptime.WeightedAveragePercentage)
n.metrics.nodeUptimeRewardingStake.Set(primaryUptime.RewardingStakePercentage)

for subnetID := range n.config.WhitelistedSubnets {
for subnetID := range n.config.TrackedSubnets {
result, err := n.NodeUptime(subnetID)
if err != nil {
n.peerConfig.Log.Debug("failed to get subnet uptime",
Expand Down
10 changes: 1 addition & 9 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,12 @@ type Config struct {

AdaptiveTimeoutConfig timer.AdaptiveTimeoutConfig `json:"adaptiveTimeoutConfig"`

// Benchlist Configuration
BenchlistConfig benchlist.Config `json:"benchlistConfig"`

// Profiling configurations
ProfilerConfig profiler.Config `json:"profilerConfig"`

// Logging configuration
LoggingConfig logging.Config `json:"loggingConfig"`

// Plugin directory
PluginDir string `json:"pluginDir"`

// File Descriptor Limit
Expand All @@ -189,17 +185,13 @@ type Config struct {
// Gossip a container in the accepted frontier every [ConsensusGossipFrequency]
ConsensusGossipFrequency time.Duration `json:"consensusGossipFreq"`

// Subnet Whitelist
WhitelistedSubnets set.Set[ids.ID] `json:"whitelistedSubnets"`
TrackedSubnets set.Set[ids.ID] `json:"trackedSubnets"`

// SubnetConfigs
SubnetConfigs map[ids.ID]chains.SubnetConfig `json:"subnetConfigs"`

// ChainConfigs
ChainConfigs map[string]chains.ChainConfig `json:"-"`
ChainAliases map[ids.ID][]string `json:"chainAliases"`

// VM management
VMManager vms.Manager `json:"-"`

// Halflife to use for the processing requests tracker.
Expand Down
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (n *Node) initNetworking(primaryNetVdrs validators.Set) error {
n.Config.NetworkConfig.Beacons = n.beacons
n.Config.NetworkConfig.TLSConfig = tlsConfig
n.Config.NetworkConfig.TLSKey = tlsKey
n.Config.NetworkConfig.WhitelistedSubnets = n.Config.WhitelistedSubnets
n.Config.NetworkConfig.TrackedSubnets = n.Config.TrackedSubnets
n.Config.NetworkConfig.UptimeCalculator = n.uptimeCalculator
n.Config.NetworkConfig.UptimeRequirement = n.Config.UptimeRequirement
n.Config.NetworkConfig.ResourceTracker = n.resourceTracker
Expand Down Expand Up @@ -663,7 +663,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
n.Config.ConsensusShutdownTimeout,
criticalChains,
n.Config.EnableStaking,
n.Config.WhitelistedSubnets,
n.Config.TrackedSubnets,
n.Shutdown,
n.Config.RouterHealthConfig,
"requests",
Expand Down Expand Up @@ -755,7 +755,7 @@ func (n *Node) initVMs() error {
Validators: vdrs,
UptimeLockedCalculator: n.uptimeCalculator,
StakingEnabled: n.Config.EnableStaking,
WhitelistedSubnets: n.Config.WhitelistedSubnets,
TrackedSubnets: n.Config.TrackedSubnets,
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
CreateSubnetTxFee: n.Config.CreateSubnetTxFee,
Expand Down
8 changes: 4 additions & 4 deletions snow/networking/router/chain_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type requestEntry struct {

type peer struct {
version *version.Application
// The subnets that this peer is currently tracking (i.e whitelisted)
// The subnets that this peer is currently tracking
trackedSubnets set.Set[ids.ID]
// The subnets that this peer actually has a connection to.
// This is a subset of trackedSubnets.
Expand Down Expand Up @@ -95,7 +95,7 @@ func (cr *ChainRouter) Initialize(
closeTimeout time.Duration,
criticalChains set.Set[ids.ID],
stakingEnabled bool,
whitelistedSubnets set.Set[ids.ID],
trackedSubnets set.Set[ids.ID],
onFatal func(exitCode int),
healthConfig HealthConfig,
metricsNamespace string,
Expand All @@ -118,7 +118,7 @@ func (cr *ChainRouter) Initialize(
myself := &peer{
version: version.CurrentApp,
}
myself.trackedSubnets.Union(whitelistedSubnets)
myself.trackedSubnets.Union(trackedSubnets)
myself.trackedSubnets.Add(constants.PrimaryNetworkID)
cr.peers[nodeID] = myself

Expand Down Expand Up @@ -378,7 +378,7 @@ func (cr *ChainRouter) AddChain(ctx context.Context, chain handler.Handler) {
}

// When we register the P-chain, we mark ourselves as connected on all of
// the subnets that we have whitelisted.
// the subnets that we have tracked.
if chainID != constants.PlatformChainID {
return
}
Expand Down
6 changes: 3 additions & 3 deletions snow/networking/router/chain_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,8 @@ func TestConnectedSubnet(t *testing.T) {
peerNodeID := ids.GenerateTestNodeID()
subnetID0 := ids.GenerateTestID()
subnetID1 := ids.GenerateTestID()
whitelistedSubnets := set.Set[ids.ID]{}
whitelistedSubnets.Add(subnetID0, subnetID1)
trackedSubnets := set.Set[ids.ID]{}
trackedSubnets.Add(subnetID0, subnetID1)
chainRouter := ChainRouter{}
err = chainRouter.Initialize(
myNodeID,
Expand All @@ -1216,7 +1216,7 @@ func TestConnectedSubnet(t *testing.T) {
time.Millisecond,
set.Set[ids.ID]{},
true,
whitelistedSubnets,
trackedSubnets,
nil,
HealthConfig{},
"",
Expand Down
2 changes: 1 addition & 1 deletion snow/networking/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Router interface {
shutdownTimeout time.Duration,
criticalChains set.Set[ids.ID],
stakingEnabled bool,
whiteListedSubnets set.Set[ids.ID],
trackedSubnets set.Set[ids.ID],
onFatal func(exitCode int),
healthConfig HealthConfig,
metricsNamespace string,
Expand Down
4 changes: 2 additions & 2 deletions snow/networking/router/traced_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *tracedRouter) Initialize(
closeTimeout time.Duration,
criticalChains set.Set[ids.ID],
stakingEnabled bool,
whitelistedSubnets set.Set[ids.ID],
trackedSubnets set.Set[ids.ID],
onFatal func(exitCode int),
healthConfig HealthConfig,
metricsNamespace string,
Expand All @@ -57,7 +57,7 @@ func (r *tracedRouter) Initialize(
closeTimeout,
criticalChains,
stakingEnabled,
whitelistedSubnets,
trackedSubnets,
onFatal,
healthConfig,
metricsNamespace,
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/blocks/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func newEnvironment(t *testing.T) *environment {
)
res.sender = &common.SenderTest{T: t}

metrics, err := metrics.New("", registerer, res.config.WhitelistedSubnets)
metrics, err := metrics.New("", registerer, res.config.TrackedSubnets)
if err != nil {
panic(fmt.Errorf("failed to create metrics: %w", err))
}
Expand Down
Loading

0 comments on commit 10f4405

Please sign in to comment.