Skip to content

Commit 61e7aa6

Browse files
authored
Rename StakingEnabled to SybilProtectionEnabled (#1441)
1 parent 85c1d24 commit 61e7aa6

File tree

15 files changed

+73
-79
lines changed

15 files changed

+73
-79
lines changed

app/app.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ func (a *app) Start() error {
135135
}
136136

137137
// Track if sybil control is enforced
138-
if !a.config.EnableStaking {
139-
log.Warn("sybil control is not enforced",
140-
zap.String("reason", "staking is disabled"),
141-
)
138+
if !a.config.SybilProtectionEnabled {
139+
log.Warn("sybil control is not enforced")
142140
}
143141

144142
// TODO move this to config

chains/manager.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ type ChainConfig struct {
166166
}
167167

168168
type ManagerConfig struct {
169-
StakingEnabled bool // True iff the network has staking enabled
170-
StakingCert tls.Certificate // needed to sign snowman++ blocks
171-
StakingBLSKey *bls.SecretKey
172-
TracingEnabled bool
169+
SybilProtectionEnabled bool
170+
StakingCert tls.Certificate // needed to sign snowman++ blocks
171+
StakingBLSKey *bls.SecretKey
172+
TracingEnabled bool
173173
// Must not be used unless [TracingEnabled] is true as this may be nil.
174174
Tracer trace.Tracer
175175
Log logging.Logger
@@ -522,9 +522,9 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
522522

523523
var vdrs validators.Set // Validators validating this blockchain
524524
var ok bool
525-
if m.StakingEnabled {
525+
if m.SybilProtectionEnabled {
526526
vdrs, ok = m.Validators.Get(chainParams.SubnetID)
527-
} else { // Staking is disabled. Every peer validates every subnet.
527+
} else { // Sybil protection is disabled. Every peer validates every subnet.
528528
vdrs, ok = m.Validators.Get(constants.PrimaryNetworkID)
529529
}
530530
if !ok {
@@ -1065,7 +1065,7 @@ func (m *manager) createSnowmanChain(
10651065
m.validatorState = validators.Trace(m.validatorState, "lockedState", m.Tracer)
10661066
}
10671067

1068-
if !m.ManagerConfig.StakingEnabled {
1068+
if !m.ManagerConfig.SybilProtectionEnabled {
10691069
m.validatorState = validators.NewNoValidatorsState(m.validatorState)
10701070
ctx.ValidatorState = validators.NewNoValidatorsState(ctx.ValidatorState)
10711071
}

config/config.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func getGossipConfig(v *viper.Viper) subnets.GossipConfig {
314314

315315
func getNetworkConfig(
316316
v *viper.Viper,
317-
stakingEnabled bool,
317+
sybilProtectionEnabled bool,
318318
halflife time.Duration,
319319
) (network.Config, error) {
320320
// Set the max number of recent inbound connections upgraded to be
@@ -380,7 +380,7 @@ func getNetworkConfig(
380380
},
381381

382382
HealthConfig: network.HealthConfig{
383-
Enabled: stakingEnabled,
383+
Enabled: sybilProtectionEnabled,
384384
MaxTimeSinceMsgSent: v.GetDuration(NetworkHealthMaxTimeSinceMsgSentKey),
385385
MaxTimeSinceMsgReceived: v.GetDuration(NetworkHealthMaxTimeSinceMsgReceivedKey),
386386
MaxPortionSendQueueBytesFull: v.GetFloat64(NetworkHealthMaxPortionSendQueueFillKey),
@@ -793,20 +793,17 @@ func getStakingSigner(v *viper.Viper) (*bls.SecretKey, error) {
793793

794794
func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, error) {
795795
config := node.StakingConfig{
796-
// We use SybilProtectionEnabledKey for CLI flags that is shown to the user
797-
// and EnableStaking in the rest of the codebase. This is to avoid confusion
798-
// with the name "staking" like in "AVAX staking".
799-
EnableStaking: v.GetBool(getRenamedKey(v, StakingEnabledKey, SybilProtectionEnabledKey)),
800-
DisabledStakingWeight: v.GetUint64(getRenamedKey(v, StakingDisabledWeightKey, SybilProtectionDisabledWeightKey)),
801-
StakingKeyPath: GetExpandedArg(v, StakingTLSKeyPathKey),
802-
StakingCertPath: GetExpandedArg(v, StakingCertPathKey),
803-
StakingSignerPath: GetExpandedArg(v, StakingSignerKeyPathKey),
804-
}
805-
if !config.EnableStaking && config.DisabledStakingWeight == 0 {
796+
SybilProtectionEnabled: v.GetBool(getRenamedKey(v, StakingEnabledKey, SybilProtectionEnabledKey)),
797+
SybilProtectionDisabledWeight: v.GetUint64(getRenamedKey(v, StakingDisabledWeightKey, SybilProtectionDisabledWeightKey)),
798+
StakingKeyPath: GetExpandedArg(v, StakingTLSKeyPathKey),
799+
StakingCertPath: GetExpandedArg(v, StakingCertPathKey),
800+
StakingSignerPath: GetExpandedArg(v, StakingSignerKeyPathKey),
801+
}
802+
if !config.SybilProtectionEnabled && config.SybilProtectionDisabledWeight == 0 {
806803
return node.StakingConfig{}, errSybilProtectionDisabledStakerWeights
807804
}
808805

809-
if !config.EnableStaking && (networkID == constants.MainnetID || networkID == constants.FujiID) {
806+
if !config.SybilProtectionEnabled && (networkID == constants.MainnetID || networkID == constants.FujiID) {
810807
return node.StakingConfig{}, errSybilProtectionDisabledOnPublicNetwork
811808
}
812809

@@ -1395,7 +1392,7 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
13951392
}
13961393

13971394
// Network Config
1398-
nodeConfig.NetworkConfig, err = getNetworkConfig(v, nodeConfig.EnableStaking, healthCheckAveragerHalflife)
1395+
nodeConfig.NetworkConfig, err = getNetworkConfig(v, nodeConfig.SybilProtectionEnabled, healthCheckAveragerHalflife)
13991396
if err != nil {
14001397
return node.Config{}, err
14011398
}

config/flags.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ func addNodeFlags(fs *pflag.FlagSet) {
267267
fs.Bool(StakingEphemeralSignerEnabledKey, false, "If true, the node uses an ephemeral staking signer key")
268268
fs.String(StakingSignerKeyPathKey, defaultStakingSignerKeyPath, fmt.Sprintf("Path to the signer private key for staking. Ignored if %s is specified", StakingSignerKeyContentKey))
269269
fs.String(StakingSignerKeyContentKey, "", "Specifies base64 encoded signer private key for staking")
270-
271270
// TODO: Remove this flag in the future
272271
fs.Uint64(StakingDisabledWeightKey, 100, "Weight to provide to each peer when staking is disabled")
273272
fs.Bool(SybilProtectionEnabledKey, true, "Enables sybil protection. If enabled, Network TLS is required")

node/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ type IPConfig struct {
8484

8585
type StakingConfig struct {
8686
genesis.StakingConfig
87-
EnableStaking bool `json:"enableStaking"`
88-
StakingTLSCert tls.Certificate `json:"-"`
89-
StakingSigningKey *bls.SecretKey `json:"-"`
90-
DisabledStakingWeight uint64 `json:"disabledStakingWeight"`
91-
StakingKeyPath string `json:"stakingKeyPath"`
92-
StakingCertPath string `json:"stakingCertPath"`
93-
StakingSignerPath string `json:"stakingSignerPath"`
87+
SybilProtectionEnabled bool `json:"sybilProtectionEnabled"`
88+
StakingTLSCert tls.Certificate `json:"-"`
89+
StakingSigningKey *bls.SecretKey `json:"-"`
90+
SybilProtectionDisabledWeight uint64 `json:"sybilProtectionDisabledWeight"`
91+
StakingKeyPath string `json:"stakingKeyPath"`
92+
StakingCertPath string `json:"stakingCertPath"`
93+
StakingSignerPath string `json:"stakingSignerPath"`
9494
}
9595

9696
type StateSyncConfig struct {

node/insecure_validator_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ type insecureValidatorManager struct {
1919

2020
func (i *insecureValidatorManager) Connected(vdrID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID) {
2121
if constants.PrimaryNetworkID == subnetID {
22-
// Staking is disabled so we don't have a txID that added the peer as a
23-
// validator. Because each validator needs a txID associated with it, we
24-
// hack one together by padding the nodeID with zeroes.
22+
// Sybil protection is disabled so we don't have a txID that added the
23+
// peer as a validator. Because each validator needs a txID associated
24+
// with it, we hack one together by padding the nodeID with zeroes.
2525
dummyTxID := ids.Empty
2626
copy(dummyTxID[:], vdrID[:])
2727

node/node.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,24 @@ func (n *Node) initNetworking(primaryNetVdrs validators.Set) error {
254254
// Configure benchlist
255255
n.Config.BenchlistConfig.Validators = n.vdrs
256256
n.Config.BenchlistConfig.Benchable = n.Config.ConsensusRouter
257-
n.Config.BenchlistConfig.StakingEnabled = n.Config.EnableStaking
257+
n.Config.BenchlistConfig.SybilProtectionEnabled = n.Config.SybilProtectionEnabled
258258
n.benchlistManager = benchlist.NewManager(&n.Config.BenchlistConfig)
259259

260260
n.uptimeCalculator = uptime.NewLockedCalculator()
261261

262262
consensusRouter := n.Config.ConsensusRouter
263-
if !n.Config.EnableStaking {
264-
// Staking is disabled so we don't have a txID that added us as a
265-
// validator. Because each validator needs a txID associated with it, we
266-
// hack one together by just padding our nodeID with zeroes.
263+
if !n.Config.SybilProtectionEnabled {
264+
// Sybil protection is disabled so we don't have a txID that added us as
265+
// a validator. Because each validator needs a txID associated with it,
266+
// we hack one together by just padding our nodeID with zeroes.
267267
dummyTxID := ids.Empty
268268
copy(dummyTxID[:], n.ID[:])
269269

270270
err := primaryNetVdrs.Add(
271271
n.ID,
272272
bls.PublicFromSecretKey(n.Config.StakingSigningKey),
273273
dummyTxID,
274-
n.Config.DisabledStakingWeight,
274+
n.Config.SybilProtectionDisabledWeight,
275275
)
276276
if err != nil {
277277
return err
@@ -280,7 +280,7 @@ func (n *Node) initNetworking(primaryNetVdrs validators.Set) error {
280280
consensusRouter = &insecureValidatorManager{
281281
Router: consensusRouter,
282282
vdrs: primaryNetVdrs,
283-
weight: n.Config.DisabledStakingWeight,
283+
weight: n.Config.SybilProtectionDisabledWeight,
284284
}
285285
}
286286

@@ -695,7 +695,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
695695
timeoutManager,
696696
n.Config.ConsensusShutdownTimeout,
697697
criticalChains,
698-
n.Config.EnableStaking,
698+
n.Config.SybilProtectionEnabled,
699699
n.Config.TrackedSubnets,
700700
n.Shutdown,
701701
n.Config.RouterHealthConfig,
@@ -707,7 +707,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
707707
}
708708

709709
n.chainManager = chains.New(&chains.ManagerConfig{
710-
StakingEnabled: n.Config.EnableStaking,
710+
SybilProtectionEnabled: n.Config.SybilProtectionEnabled,
711711
StakingCert: n.Config.StakingTLSCert,
712712
StakingBLSKey: n.Config.StakingSigningKey,
713713
Log: n.Log,
@@ -764,10 +764,10 @@ func (n *Node) initVMs() error {
764764

765765
vdrs := n.vdrs
766766

767-
// If staking is disabled, ignore updates to Subnets' validator sets
768-
// Instead of updating node's validator manager, platform chain makes changes
769-
// to its own local validator manager (which isn't used for sampling)
770-
if !n.Config.EnableStaking {
767+
// If sybil protection is disabled, we provide the P-chain its own local
768+
// validator manager that will not be used by the rest of the node. This
769+
// allows the node's validator sets to be determined by network connections.
770+
if !n.Config.SybilProtectionEnabled {
771771
vdrs = validators.NewManager()
772772
primaryVdrs := validators.NewSet()
773773
_ = vdrs.Add(constants.PrimaryNetworkID, primaryVdrs)
@@ -788,7 +788,7 @@ func (n *Node) initVMs() error {
788788
Chains: n.chainManager,
789789
Validators: vdrs,
790790
UptimeLockedCalculator: n.uptimeCalculator,
791-
StakingEnabled: n.Config.EnableStaking,
791+
SybilProtectionEnabled: n.Config.SybilProtectionEnabled,
792792
TrackedSubnets: n.Config.TrackedSubnets,
793793
TxFee: n.Config.TxFee,
794794
CreateAssetTxFee: n.Config.CreateAssetTxFee,

snow/networking/benchlist/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Manager interface {
4747
type Config struct {
4848
Benchable Benchable `json:"-"`
4949
Validators validators.Manager `json:"-"`
50-
StakingEnabled bool `json:"-"`
50+
SybilProtectionEnabled bool `json:"-"`
5151
Threshold int `json:"threshold"`
5252
MinimumFailingDuration time.Duration `json:"minimumFailingDuration"`
5353
Duration time.Duration `json:"duration"`
@@ -119,10 +119,10 @@ func (m *manager) RegisterChain(ctx *snow.ConsensusContext) error {
119119
vdrs validators.Set
120120
ok bool
121121
)
122-
if m.config.StakingEnabled {
122+
if m.config.SybilProtectionEnabled {
123123
vdrs, ok = m.config.Validators.Get(ctx.SubnetID)
124124
} else {
125-
// If staking is disabled, everyone validates every chain
125+
// If sybil protection is disabled, everyone validates every chain
126126
vdrs, ok = m.config.Validators.Get(constants.PrimaryNetworkID)
127127
}
128128
if !ok {

snow/networking/router/chain_router.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ type ChainRouter struct {
7676
peers map[ids.NodeID]*peer
7777
// node ID --> chains that node is benched on
7878
// invariant: if a node is benched on any chain, it is treated as disconnected on all chains
79-
benched map[ids.NodeID]set.Set[ids.ID]
80-
criticalChains set.Set[ids.ID]
81-
stakingEnabled bool
82-
onFatal func(exitCode int)
83-
metrics *routerMetrics
79+
benched map[ids.NodeID]set.Set[ids.ID]
80+
criticalChains set.Set[ids.ID]
81+
sybilProtectionEnabled bool
82+
onFatal func(exitCode int)
83+
metrics *routerMetrics
8484
// Parameters for doing health checks
8585
healthConfig HealthConfig
8686
// aggregator of requests based on their time
@@ -98,7 +98,7 @@ func (cr *ChainRouter) Initialize(
9898
timeoutManager timeout.Manager,
9999
closeTimeout time.Duration,
100100
criticalChains set.Set[ids.ID],
101-
stakingEnabled bool,
101+
sybilProtectionEnabled bool,
102102
trackedSubnets set.Set[ids.ID],
103103
onFatal func(exitCode int),
104104
healthConfig HealthConfig,
@@ -111,7 +111,7 @@ func (cr *ChainRouter) Initialize(
111111
cr.closeTimeout = closeTimeout
112112
cr.benched = make(map[ids.NodeID]set.Set[ids.ID])
113113
cr.criticalChains = criticalChains
114-
cr.stakingEnabled = stakingEnabled
114+
cr.sybilProtectionEnabled = sybilProtectionEnabled
115115
cr.onFatal = onFatal
116116
cr.timedRequests = linkedhashmap.New[ids.RequestID, requestEntry]()
117117
cr.peers = make(map[ids.NodeID]*peer)
@@ -408,7 +408,7 @@ func (cr *ChainRouter) AddChain(ctx context.Context, chain handler.Handler) {
408408

409409
// If this peer isn't running this chain, then we shouldn't mark them as
410410
// connected
411-
if !peer.trackedSubnets.Contains(subnetID) && cr.stakingEnabled {
411+
if !peer.trackedSubnets.Contains(subnetID) && cr.sybilProtectionEnabled {
412412
continue
413413
}
414414

@@ -466,14 +466,14 @@ func (cr *ChainRouter) Connected(nodeID ids.NodeID, nodeVersion *version.Applica
466466
// set, disconnect. we cannot put a subnet-only validator check here since
467467
// Disconnected would not be handled properly.
468468
//
469-
// When staking is disabled, we only want this clause to happen once.
470-
// Therefore, we only update the chains during the connection of the primary
471-
// network, which is guaranteed to happen for every peer.
472-
if cr.stakingEnabled || subnetID == constants.PrimaryNetworkID {
469+
// When sybil protection is disabled, we only want this clause to happen
470+
// once. Therefore, we only update the chains during the connection of the
471+
// primary network, which is guaranteed to happen for every peer.
472+
if cr.sybilProtectionEnabled || subnetID == constants.PrimaryNetworkID {
473473
for _, chain := range cr.chainHandlers {
474-
// If staking is disabled, send a Connected message to every chain
475-
// when connecting to the primary network
476-
if subnetID == chain.Context().SubnetID || !cr.stakingEnabled {
474+
// If sybil protection is disabled, send a Connected message to
475+
// every chain when connecting to the primary network.
476+
if subnetID == chain.Context().SubnetID || !cr.sybilProtectionEnabled {
477477
chain.Push(
478478
context.TODO(),
479479
handler.Message{
@@ -506,7 +506,7 @@ func (cr *ChainRouter) Disconnected(nodeID ids.NodeID) {
506506
// if a validator connects then it leaves validator-set, it would not be
507507
// disconnected properly.
508508
for _, chain := range cr.chainHandlers {
509-
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.stakingEnabled {
509+
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.sybilProtectionEnabled {
510510
chain.Push(
511511
context.TODO(),
512512
handler.Message{
@@ -536,7 +536,7 @@ func (cr *ChainRouter) Benched(chainID ids.ID, nodeID ids.NodeID) {
536536
msg := message.InternalDisconnected(nodeID)
537537

538538
for _, chain := range cr.chainHandlers {
539-
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.stakingEnabled {
539+
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.sybilProtectionEnabled {
540540
chain.Push(
541541
context.TODO(),
542542
handler.Message{
@@ -571,7 +571,7 @@ func (cr *ChainRouter) Unbenched(chainID ids.ID, nodeID ids.NodeID) {
571571
msg := message.InternalConnected(nodeID, peer.version)
572572

573573
for _, chain := range cr.chainHandlers {
574-
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.stakingEnabled {
574+
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.sybilProtectionEnabled {
575575
chain.Push(
576576
context.TODO(),
577577
handler.Message{

snow/networking/router/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Router interface {
3232
timeouts timeout.Manager,
3333
shutdownTimeout time.Duration,
3434
criticalChains set.Set[ids.ID],
35-
stakingEnabled bool,
35+
sybilProtectionEnabled bool,
3636
trackedSubnets set.Set[ids.ID],
3737
onFatal func(exitCode int),
3838
healthConfig HealthConfig,

0 commit comments

Comments
 (0)